public void TestMissingSuperTemplate() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; String templates = "t() ::= \"<super.t()>\"" + newline; WriteFile(tmpdir, "t.stg", templates); STGroup group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); String templates2 = "u() ::= \"blech\"" + newline; WriteFile(tmpdir, "t2.stg", templates2); STGroup group2 = new STGroupFile(Path.Combine(tmpdir, "t2.stg")); group.ImportTemplates(group2); ST st = group.GetInstanceOf("t"); st.Render(); String expected = "context [t] 1:1 no such template: super.t" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestDefineRegionInSubgroup2() { string dir = GetRandomDir(); string g1 = "a() ::= <<[<@r()>]>>\n"; WriteFile(dir, "g1.stg", g1); string g2 = "@a.r() ::= <<foo>>>\n"; WriteFile(dir, "g2.stg", g2); TemplateGroup group1 = new TemplateGroupFile(dir + "/g1.stg"); TemplateGroup group2 = new TemplateGroupFile(dir + "/g2.stg"); group1.ImportTemplates(group2); // opposite of previous; g1 imports g2 Template st = group1.GetInstanceOf("a"); string expected = "[]"; // @a.r implicitly defined in g1; can't see g2's string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestImportTemplateInGroupFileFromGroupFile() { string dir = GetRandomDir(); string groupFile = "a() ::= \"g1 a\"\n" + "b() ::= \"<c()>\"\n"; WriteFile(dir, "x/group.stg", groupFile); groupFile = "b() ::= \"g2 b\"\n" + "c() ::= \"g2 c\"\n"; WriteFile(dir, "y/group.stg", groupFile); TemplateGroup group1 = new TemplateGroupFile(dir + "/x/group.stg"); TemplateGroup group2 = new TemplateGroupFile(dir + "/y/group.stg"); group1.ImportTemplates(group2); Template st = group1.GetInstanceOf("/b"); string expected = "g2 c"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestDefineRegionInSubgroup() { string dir = GetRandomDir(); string g1 = "a() ::= <<[<@r()>]>>\n"; WriteFile(dir, "g1.stg", g1); string g2 = "@a.r() ::= <<foo>>\n"; WriteFile(dir, "g2.stg", g2); TemplateGroup group1 = new TemplateGroupFile(dir + "/g1.stg"); TemplateGroup group2 = new TemplateGroupFile(dir + "/g2.stg"); group2.ImportTemplates(group1); // define r in g2 Template st = group2.GetInstanceOf("a"); string expected = "[foo]"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestImportTemplateInDirFromGroupFile() { string dir = GetRandomDir(); string a = "a() ::= <<dir1 a>>\n"; WriteFile(dir, "group/a.st", a); string groupFile = "b() ::= \"<a()>\"\n"; WriteFile(dir, "group.stg", groupFile); TemplateGroup group1 = new TemplateGroupDirectory(dir); TemplateGroup group2 = new TemplateGroupFile(dir + "/group.stg"); group2.ImportTemplates(group1); Template st = group2.GetInstanceOf("/group/b"); string expected = "dir1 a"; string result = st.Render(); Assert.AreEqual(expected, result); }