public void TestUnloadWithImports() { writeFile(tmpdir, "t.stg", "import \"g1.stg\"\n\nmain() ::= <<\nv1-<f()>\n>>"); writeFile(tmpdir, "g1.stg", "f() ::= \"g1\""); writeFile(tmpdir, "g2.stg", "f() ::= \"g2\"\nf2() ::= \"f2\"\n"); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); Template st = group.GetInstanceOf("main"); Assert.AreEqual("v1-g1", st.Render()); // Change the text of group t, including the imports. writeFile(tmpdir, "t.stg", "import \"g2.stg\"\n\nmain() ::= <<\nv2-<f()>;<f2()>\n>>"); group.Unload(); st = group.GetInstanceOf("main"); Assert.AreEqual("v2-g2;f2", st.Render()); }
public void TestUnloadImportedTemplatedSpecifiedInGroupFile() { writeFile(tmpdir, "t.stg", "import \"g1.stg\"\n\nmain() ::= <<\nv1-<f()>\n>>"); writeFile(tmpdir, "g1.stg", "f() ::= \"g1\""); writeFile(tmpdir, "g2.stg", "f() ::= \"g2\"\nf2() ::= \"f2\"\n"); TemplateGroup group = new TemplateGroupFile(tmpdir + "/t.stg"); Template st = group.GetInstanceOf("main"); Assert.AreEqual("v1-g1", st.Render()); // Change the imports of group t. writeFile(tmpdir, "t.stg", "import \"g2.stg\"\n\nmain() ::= <<\nv2-<f()>;<f2()>\n>>"); group.Unload(); // will also unload already imported groups st = group.GetInstanceOf("main"); Assert.AreEqual("v2-g2;f2", st.Render()); }
public void TestUnloadingGroupFile() { string dir = tmpdir; string a = "a(x) ::= <<foo>>\n" + "b() ::= <<bar>>\n"; writeFile(dir, "a.stg", a); TemplateGroup group = new TemplateGroupFile(dir + "/a.stg"); group.Load(); // force load Template st = group.GetInstanceOf("a"); int originalHashCode = RuntimeHelpers.GetHashCode(st); group.Unload(); // blast cache st = group.GetInstanceOf("a"); int newHashCode = RuntimeHelpers.GetHashCode(st); Assert.AreEqual(originalHashCode == newHashCode, false); // diff objects string expected = "foo"; string result = st.Render(); Assert.AreEqual(expected, result); st = group.GetInstanceOf("b"); expected = "bar"; result = st.Render(); Assert.AreEqual(expected, result); }