public void TestDefineRegionInSubgroup() { string dir = tmpdir; string g1 = "a() ::= <<[<@r()>]>>\n"; writeFile(dir, "g1.stg", g1); string g2 = "@a.r() ::= <%\n" + " foo\n\n\n" + "%>\n"; writeFile(dir, "g2.stg", g2); TemplateGroup group1 = new TemplateGroupFile(Path.Combine(dir, "g1.stg")); TemplateGroup group2 = new TemplateGroupFile(Path.Combine(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 TestImportTemplateInGroupFileFromGroupFile() { string dir = tmpdir; string groupFile = "a() ::= \"g1 a\"\n" + "b() ::= \"<c()>\"\n"; writeFile(dir, Path.Combine("x", "group.stg"), groupFile); groupFile = "b() ::= \"g2 b\"\n" + "c() ::= \"g2 c\"\n"; writeFile(dir, Path.Combine("y", "group.stg"), groupFile); TemplateGroup group1 = new TemplateGroupFile(Path.Combine(dir, "x", "group.stg")); TemplateGroup group2 = new TemplateGroupFile(Path.Combine(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 TestMissingSuperTemplate() { ErrorBuffer errors = new ErrorBuffer(); string templates = "t() ::= \"<super.t()>\"" + Environment.NewLine; writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; string templates2 = "u() ::= \"blech\"" + Environment.NewLine; writeFile(tmpdir, "t2.stg", templates2); TemplateGroup group2 = new TemplateGroupFile(Path.Combine(tmpdir, "t2.stg")); group.ImportTemplates(group2); Template 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 TestSuperRegionRefMissingOk() { string dir = tmpdir; string g = "a() ::= \"X<@r()>Y\"" + "@a.r() ::= \"foo\"" + newline; writeFile(dir, "g.stg", g); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg")); string sub = "@a.r() ::= \"A<@super.q()>B\"" + newline; // allow this; trap at runtime ITemplateErrorListener errors = new ErrorBuffer(); group.Listener = errors; writeFile(dir, "sub.stg", sub); TemplateGroupFile subGroup = new TemplateGroupFile(dir + "/sub.stg"); subGroup.ImportTemplates(group); Template st = subGroup.GetInstanceOf("a"); string result = st.Render(); string expecting = "XABY"; Assert.AreEqual(expecting, result); }
public void TestRegionOverrideStripsNewlines() { string dir = tmpdir; string g = "a() ::= \"X<@r()>Y\"" + "@a.r() ::= <<\n" + "foo\n" + ">>\n"; writeFile(dir, "g.stg", g); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg")); string sub = "@a.r() ::= \"A<@super.r()>B\"" + newline; writeFile(dir, "sub.stg", sub); TemplateGroupFile subGroup = new TemplateGroupFile(Path.Combine(dir, "sub.stg")); subGroup.ImportTemplates(group); Template st = subGroup.GetInstanceOf("a"); string result = st.Render(); string expecting = "XAfooBY"; Assert.AreEqual(expecting, result); }
public void TestRegionOverrideRefSuperRegion3Levels() { string dir = tmpdir; string g = "a() ::= \"X<@r()>Y\"" + "@a.r() ::= \"foo\"" + newline; writeFile(dir, "g.stg", g); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg")); string sub = "@a.r() ::= \"<@super.r()>2\"" + newline; writeFile(dir, "sub.stg", sub); TemplateGroupFile subGroup = new TemplateGroupFile(dir + "/sub.stg"); subGroup.ImportTemplates(group); string subsub = "@a.r() ::= \"<@super.r()>3\"" + newline; writeFile(dir, "subsub.stg", subsub); TemplateGroupFile subSubGroup = new TemplateGroupFile(dir + "/subsub.stg"); subSubGroup.ImportTemplates(subGroup); Template st = subSubGroup.GetInstanceOf("a"); string result = st.Render(); string expecting = "Xfoo23Y"; Assert.AreEqual(expecting, result); }
public void TestRegionOverrideRefSuperImplicitRegion() { string dir = tmpdir; string g = "a() ::= \"X<@r>foo<@end>Y\"" + newline; writeFile(dir, "g.stg", g); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg")); string sub = "@a.r() ::= \"A<@super.r()>\"" + newline; writeFile(dir, "sub.stg", sub); TemplateGroupFile subGroup = new TemplateGroupFile(dir + "/sub.stg"); subGroup.ImportTemplates(group); Template st = subGroup.GetInstanceOf("a"); string result = st.Render(); string expecting = "XAfooY"; Assert.AreEqual(expecting, result); }
public void TestDefineRegionInSubgroup2() { string dir = tmpdir; 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(Path.Combine(dir, "g1.stg")); TemplateGroup group2 = new TemplateGroupFile(Path.Combine(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); }