public void TestImportTemplate() { string dir1 = GetRandomDir(); string a = "a() ::= <<dir1 a>>\n"; string b = "b() ::= <<dir1 b>>\n"; WriteFile(dir1, "a.st", a); WriteFile(dir1, "b.st", b); string dir2 = GetRandomDir(); a = "a() ::= << <b()> >>\n"; WriteFile(dir2, "a.st", a); TemplateGroup group1 = new TemplateGroupDirectory(dir1); TemplateGroup group2 = new TemplateGroupDirectory(dir2); group2.ImportTemplates(group1); Template st = group2.GetInstanceOf("b"); string expected = "dir1 b"; string result = st.Render(); Assert.AreEqual(expected, result); // do it again, but make a template ref imported template st = group2.GetInstanceOf("a"); expected = " dir1 b "; result = st.Render(); Assert.AreEqual(expected, result); }
public void TestImportTemplateFromGroupFile() { // /randomdir/x/subdir/a and /randomdir/y/subdir.stg which has a and b string dir = GetRandomDir(); string a = "a() ::= << <b()> >>\n"; // get b imported from subdir.stg WriteFile(dir, "x/subdir/a.st", a); string groupFile = "a() ::= \"group file a\"\n" + "b() ::= \"group file b\"\n"; WriteFile(dir, "y/subdir.stg", groupFile); TemplateGroup group1 = new TemplateGroupDirectory(dir + "/x"); TemplateGroup group2 = new TemplateGroupDirectory(dir + "/y"); group1.ImportTemplates(group2); Template st = group1.GetInstanceOf("/subdir/a"); string expected = " group file b "; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestImportTemplateFromSubdir() { // /randomdir/x/subdir/a and /randomdir/y/subdir/b string dir = GetRandomDir(); string a = "a() ::= << <b()> >>\n"; string b = "b() ::= <<x/subdir/b>>\n"; WriteFile(dir, "x/subdir/a.st", a); WriteFile(dir, "y/subdir/b.st", b); TemplateGroup group1 = new TemplateGroupDirectory(dir + "/x"); TemplateGroup group2 = new TemplateGroupDirectory(dir + "/y"); group1.ImportTemplates(group2); Template st = group1.GetInstanceOf("/subdir/a"); string expected = " x/subdir/b "; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestSuper() { string dir1 = GetRandomDir(); string a = "a() ::= <<dir1 a>>\n"; string b = "b() ::= <<dir1 b>>\n"; WriteFile(dir1, "a.st", a); WriteFile(dir1, "b.st", b); string dir2 = GetRandomDir(); a = "a() ::= << [<super.a()>] >>\n"; WriteFile(dir2, "a.st", a); TemplateGroup group1 = new TemplateGroupDirectory(dir1); TemplateGroup group2 = new TemplateGroupDirectory(dir2); group2.ImportTemplates(group1); Template st = group2.GetInstanceOf("a"); string expected = " [dir1 a] "; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestPolymorphicTemplateReference() { string dir1 = GetRandomDir(); string b = "b() ::= <<dir1 b>>\n"; WriteFile(dir1, "b.st", b); string dir2 = GetRandomDir(); string a = "a() ::= << <b()> >>\n"; b = "b() ::= <<dir2 b>>\n"; WriteFile(dir2, "a.st", a); WriteFile(dir2, "b.st", b); TemplateGroup group1 = new TemplateGroupDirectory(dir1); TemplateGroup group2 = new TemplateGroupDirectory(dir2); group1.ImportTemplates(group2); // normal lookup; a created from dir2 calls dir2.b Template st = group2.GetInstanceOf("a"); string expected = " dir2 b "; string result = st.Render(); Assert.AreEqual(expected, result); // polymorphic lookup; a created from dir1 calls dir2.a which calls dir1.b st = group1.GetInstanceOf("a"); expected = " dir1 b "; result = st.Render(); Assert.AreEqual(expected, result); }
public void TestImportTemplateInGroupFileFromDir() { string dir = GetRandomDir(); string a = "a() ::= << <b()> >>\n"; WriteFile(dir, "x/a.st", a); string groupFile = "b() ::= \"group file b\"\n" + "c() ::= \"group file c\"\n"; WriteFile(dir, "y/group.stg", groupFile); TemplateGroup group1 = new TemplateGroupDirectory(dir + "/x"); TemplateGroup group2 = new TemplateGroupFile(dir + "/y/group.stg"); group1.ImportTemplates(group2); Template st = group1.GetInstanceOf("/a"); st.code.Dump(); string expected = " group file b "; string result = st.Render(); Assert.AreEqual(expected, result); }