public void TestSeesEnclosingAttr() { string templates = "t(x,y) ::= \"<u()>\"\n" + "u() ::= \"<x><y>\""; ErrorBuffer errors = new ErrorBuffer(); writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; Template st = group.GetInstanceOf("t"); st.Add("x", "x"); st.Add("y", "y"); string result = st.Render(); string expectedError = ""; Assert.AreEqual(expectedError, errors.ToString()); string expected = "xy"; Assert.AreEqual(expected, result); }
public void TestParallelAttributeIterationWithMissingArgs() { ErrorBuffer errors = new ErrorBuffer(); TemplateGroup group = new TemplateGroup(); group.Listener = errors; Template e = new Template(group, "<names,phones,salaries:{n,p | <n>@<p>}; separator=\", \">" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("phones", "1"); e.Add("phones", "2"); e.Add("salaries", "big"); e.Render(); string errorExpecting = "1:23: anonymous template has 2 arg(s) but mapped across 3 value(s)" + newline + "context [anonymous] 1:23 passed 3 arg(s) to template /_sub1 with 2 declared arg(s)" + newline + "context [anonymous] 1:1 iterating through 3 values in zip map but template has 2 declared arguments" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); string expecting = "Ter@1, Tom@2"; Assert.AreEqual(expecting, e.Render()); }
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 TestIndexAttrVisibleLocallyOnly() { string templates = "t(names) ::= \"<names:{n | <u(n)>}>\"\n" + "u(x) ::= \"<i>:<x>\""; ErrorBuffer errors = new ErrorBuffer(); writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; Template st = group.GetInstanceOf("t"); st.Add("names", "Ter"); string result = st.Render(); group.GetInstanceOf("u").impl.Dump(); string expectedError = "t.stg 2:11: implicitly-defined attribute i not visible" + newline; Assert.AreEqual(expectedError, errors.ToString()); string expected = ":Ter"; Assert.AreEqual(expected, result); group.Listener = ErrorManager.DefaultErrorListener; }
public void TestArgWithSameNameAsEnclosing() { string templates = "t(x,y) ::= \"<u(x)>\"\n" + "u(y) ::= \"<x><y>\""; ErrorBuffer errors = new ErrorBuffer(); writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; Template st = group.GetInstanceOf("t"); st.Add("x", "x"); st.Add("y", "y"); string result = st.Render(); string expectedError = ""; Assert.AreEqual(expectedError, errors.ToString()); string expected = "xx"; Assert.AreEqual(expected, result); group.Listener = ErrorManager.DEFAULT_ERROR_LISTENER; }
public void TestAnonIncludeArgMismatch3() { ITemplateErrorListener errors = new ErrorBuffer(); string template = "<a:{x|foo},{bar}>"; CompiledTemplate code = new TemplateCompiler(new TemplateGroup() { ErrorManager = new ErrorManager(errors) }).Compile(template); string expected = "1:11: anonymous template has 0 arg(s) but mapped across 1 value(s)" + newline; Assert.AreEqual(expected, errors.ToString()); }
public void TestStringTypeMismatch2() { ErrorBuffer errors = new ErrorBuffer(); TemplateGroup group = new TemplateGroup(); group.Listener = errors; Template e = new Template(group, "<strlen(s)>"); e.Add("s", 34); e.Render(); // generate the error string errorExpecting = "context [anonymous] 1:1 function strlen expects a string not System.Int32" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); }
public void TestIllegalOption() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; STGroup group = new STGroup(); group.DefineTemplate(new TemplateName("test"), "<name; bad=\"ugly\">"); ST st = group.GetInstanceOf("test"); st.Add("name", "Ter"); String expected = "Ter"; String result = st.Render(); Assert.AreEqual(expected, result); expected = "1:7: no such option: bad" + newline; Assert.AreEqual(expected, errors.ToString()); }
public void TestArg() { String templates = "foo(a,) ::= << >>\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = null; var errors = new ErrorBuffer(); group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 1:6: missing ID at ')'" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestCantDefineEmbeddedRegionAgain() { string dir = GetRandomDir(); string g = "a() ::= <<[<@r>foo<@end>]>>\n" + "@a.r() ::= <<bar>>\n"; // error; dup WriteFile(dir, "g.stg", g); TemplateGroup group = new TemplateGroupFile(Path.Combine(dir, "g.stg")); ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; group.Load(); string expected = "2:3: region a.r is embedded and thus already implicitly defined" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestHiddenFieldNotError() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; String templates = "t(u) ::= \"<u.name>\"" + newline; WriteFile(tmpdir, "t.stg", templates); STGroup group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ST st = group.GetInstanceOf("t"); st.Add("u", new UserHiddenNameField("parrt")); st.Render(); String expected = ""; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingRegionName() { string dir = tmpdir; string g = "@t.() ::= \"\"\n"; writeFile(dir, "g.stg", g); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg")); ErrorBuffer errors = new ErrorBuffer(); group.Listener = errors; group.Load(); string expected = "g.stg 1:3: missing ID at '('" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestValidButOutOfPlaceChar() { string templates = "foo() ::= <<hi <.> mom>>\n"; writeFile(tmpdir, "t.stg", templates); ITemplateErrorListener errors = new ErrorBuffer(); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:15: doesn't look like an expression" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestUnknownAttr() { string templates = "t() ::= \"<x>\"\n"; ErrorBuffer errors = new ErrorBuffer(); writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; Template st = group.GetInstanceOf("t"); string result = st.Render(); string expectedError = "context [/t] 1:1 attribute x isn't defined" + newline; Assert.AreEqual(expectedError, errors.ToString()); }
public void TestDupDef() { string dir = tmpdir; string groupFile = "b() ::= \"bar\"\n" + "b() ::= \"duh\"\n"; writeFile(dir, "group.stg", groupFile); ITemplateErrorListener errors = new ErrorBuffer(); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "group.stg")); group.Listener = errors; group.Load(); string expected = "group.stg 2:0: redefinition of template b" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingArg() { string templates = "t() ::= \"<u()>\"\n" + "u(z) ::= \"\""; ErrorBuffer errors = new ErrorBuffer(); writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; Template st = group.GetInstanceOf("t"); string result = st.Render(); string expectedError = "context [/t] 1:1 passed 0 arg(s) to template /u with 1 declared arg(s)" + newline; Assert.AreEqual(expectedError, errors.ToString()); }
public void TestMissingTemplate() { string templates = "foo() ::= \n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 2:0: missing template at '<EOF>'" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestImportNotString() { string templates = "import Super.stg\n" + "foo() ::= <<>>\n"; writeFile(tmpdir, "t.stg", templates); ITemplateErrorListener errors = new ErrorBuffer(); TemplateGroup group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:7: mismatched input 'Super' expecting STRING" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestErrorInNestedTemplate() { string templates = "foo() ::= \"hi <name:{[<aaa.bb!>]}> mom\"\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:29: mismatched input '!' expecting RDELIM" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestCantDefineEmbeddedRegionAgain() { string dir = tmpdir; string g = "a() ::= <<[<@r>foo<@end>]>>\n" + "@a.r() ::= <<bar>>\n"; // error; dup writeFile(dir, "g.stg", g); TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg")); ErrorBuffer errors = new ErrorBuffer(); group.Listener = errors; group.Load(); string expected = "g.stg 2:3: region a.r is embedded and thus already implicitly defined" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestEOFInExpr2() { string templates = "foo() ::= \"hi <name:{x|[<aaa.bb>]}\"\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:34: premature EOF" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingRPAREN() { string templates = "foo() ::= \"hi <foo(>\"\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:19: '>' came as a complete surprise to me" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestNonterminatedComment() { string templates = "foo() ::= << <!foo> >>"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:20: Nonterminated comment starting at 1:1: '!>' missing" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestRotPar() { string templates = "foo() ::= \"<a,b:t(),u()>\"\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:19: mismatched input ',' expecting RDELIM" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestParen() { string templates = "foo( ::= << >>\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:5: no viable alternative at input '::='" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestNewlineInString() { string templates = "foo() ::= \"\nfoo\"\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:11: \\n in string" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestArg() { string templates = "foo(a,) ::= << >>\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:6: mismatched input ')' expecting ID" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestHandleBuggyDefaultArgument() { string templates = "main(a={(<\"\")>}) ::= \"\""; writeFile(tmpdir, "t.stg", templates); ErrorBuffer errors = new ErrorBuffer(); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; Template st = group.GetInstanceOf("main"); string s = st.Render(); // Check the errors. This contained an "NullPointerException" before Assert.AreEqual( "t.stg 1:12: mismatched input ')' expecting RDELIM" + newline, errors.ToString()); }
public void TestParen2() { string templates = "foo) ::= << >>\n" + "bar() ::= <<bar>>\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:0: garbled template definition starting at 'foo'" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingImportString() { string templates = "import\n" + "foo() ::= <<>>\n"; writeFile(tmpdir, "t.stg", templates); ITemplateErrorListener errors = new ErrorBuffer(); TemplateGroup group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 2:0: mismatched input 'foo' expecting STRING" + newline + "t.stg 2:3: required (...)+ loop did not match anything at input '('" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestEmptyExpr2() { string template = "hi <> "; TemplateGroup group = new TemplateGroup(); ErrorBuffer errors = new ErrorBuffer(); group.Listener = errors; try { group.DefineTemplate("test", template); } catch (TemplateException) { } string result = errors.ToString(); string expected = "test 1:3: doesn't look like an expression" + newline; Assert.AreEqual(expected, result); }
public void TestUnclosedTemplate() { string templates = "foo() ::= {"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(tmpdir + "/" + "t.stg"); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:11: missing final '}' in {...} anonymous template" + newline + "t.stg 1:10: no viable alternative at input '{'" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingEmbeddedTemplate() { ErrorBuffer errors = new ErrorBuffer(); string templates = "t() ::= \"<foo()>\"" + Environment.NewLine; writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; Template st = group.GetInstanceOf("t"); st.Render(); string expected = "context [/t] 1:1 no such template: /foo" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestEOFInString() { string templates = "foo() ::= << <f(\"foo>>\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroupFile group; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.Listener = errors; group.Load(); // force load string expected = "t.stg 1:20: EOF in string" + newline + "t.stg 1:20: premature EOF" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestSoleArgUsingApplySyntax() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; String templates = "t() ::= \"<{9}:u()>\"\n" + "u(x,y) ::= \"<x>\"\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ST st = group.GetInstanceOf("t"); String expected = "9"; String result = st.Render(); Assert.AreEqual(expected, result); expected = "context [t] 1:1 expecting single arg in template reference u() (not 2 args)" + newline; result = errors.ToString(); Assert.AreEqual(expected, result); }
public virtual void testParallelAttributeIterationWithMissingArgs() { IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplate e = new StringTemplate("$names,phones,salaries:{$n$@$p$}; separator=\", \"$"); e.ErrorListener = errors; e = e.GetInstanceOf(); e.SetAttribute("names", "Tom"); e.SetAttribute("phones", "2"); e.SetAttribute("salaries", "big"); e.ToString(); // generate the error string errorExpecting = "missing arguments in anonymous template in context [anonymous]"; Assert.AreEqual(errorExpecting, errors.ToString()); }
public void TestParallelAttributeIterationWithMissingArgs() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; Template e = new Template( "<names,phones,salaries:{<n>@<p>}; separator=\", \">" ); e.Add("names", "Tom"); e.Add("phones", "2"); e.Add("salaries", "big"); e.Render(); // generate the error string errorExpecting = "context [anonymous] 1:1 missing argument definitions" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); }
public void TestMap2() { String templates = "d ::= [\"k\":]\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = null; ErrorBuffer errors = new ErrorBuffer(); group = new STGroupFile(tmpdir + "/" + "t.stg"); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 1:11: missing value for key at ']'" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestParallelAttributeIterationWithMismatchArgListSizes() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; Template e = new Template( "<names,phones,salaries:{n,p | <n>@<p>}; separator=\", \">" ); e.Add("names", "Ter"); e.Add("names", "Tom"); e.Add("phones", "1"); e.Add("phones", "2"); e.Add("salaries", "big"); e.Render(); string errorExpecting = "context [anonymous] 1:1 iterating through 3 arguments but parallel map has 2 formal arguments" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); string expecting = "Ter@1, Tom@2"; Assert.AreEqual(expecting, e.Render()); }
public virtual void testComputedPropertyName() { StringTemplateGroup group = new StringTemplateGroup("test"); IStringTemplateErrorListener errors = new ErrorBuffer(); group.ErrorListener = errors; StringTemplate t = new StringTemplate(group, "variable property $propName$=$v.(propName)$"); t.SetAttribute("v", new Decl("i", "int")); t.SetAttribute("propName", "type"); string expecting = "variable property type=int"; string result = t.ToString(); Assert.AreEqual(errors.ToString(), ""); Assert.AreEqual(expecting, result); }
public virtual void testSingleExprTemplateArgumentError() { string templates = "" + "group test;" + NL + "test(name) ::= \"<bold(name)>\"" + NL + "bold(item,ick) ::= \"*<item>*\"" + NL; IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(AngleBracketTemplateLexer), errors); StringTemplate e = group.GetInstanceOf("test"); e.SetAttribute("name", "Ter"); string result = e.ToString(); string expecting = "template bold must have exactly one formal arg in template context [test <invoke bold arg context>]"; Assert.AreEqual(expecting, errors.ToString()); }
public virtual void testGroupSatisfiesSingleInterface() { // this also tests the group loader IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplateGroup.RegisterGroupLoader(new CommonGroupLoader(errors, TEMPDIR)); string groupIStr = "" + "interface testI;" + NL + "t();" + NL + "bold(item);" + NL + "optional duh(a,b,c);" + NL; WriteFile(TEMPDIR, "testI.sti", groupIStr); string templates = "" + "group testG implements testI;" + NL + "t() ::= <<foo>>" + NL + "bold(item) ::= <<foo>>" + NL + "duh(a,b,c) ::= <<foo>>" + NL; WriteFile(TEMPDIR, "testG.stg", templates); file1 = new StreamReader(Path.Combine(TEMPDIR, "testG.stg")); StringTemplateGroup group = new StringTemplateGroup(file1, errors); string expecting = ""; // should be no errors Assert.AreEqual(expecting, errors.ToString()); }
public void testEmbeddedRegionRedefError() { // cannot define an embedded template within group string templates = "" + "group test;" + NL + "a() ::= \"X<@r>dork<@end>Y\"" + "@a.r() ::= \"foo\"" + NL; IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), errors); StringTemplate st = group.GetInstanceOf("a"); st.ToString(); string result = errors.ToString(); string expecting = "group test line 2: redefinition of template region: @a.r"; Assert.AreEqual(expecting, result); }
public virtual void testCannotFindInterfaceFile() { // this also tests the group loader IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplateGroup.RegisterGroupLoader(new CommonGroupLoader(errors, TEMPDIR)); string templates = "" + "group testG implements blort;" + NL + "t() ::= <<foo>>" + NL + "bold(item) ::= <<foo>>" + NL + "duh(a,b,c) ::= <<foo>>" + NL; WriteFile(TEMPDIR, "testG.stg", templates); file1 = new StreamReader(Path.Combine(TEMPDIR, "testG.stg")); StringTemplateGroup group = new StringTemplateGroup(file1, errors); string expecting = "no such interface file 'blort.sti'"; Assert.AreEqual(expecting, errors.ToString()); }
public void testNoDotsInTemplateNames() { IStringTemplateErrorListener errors = new ErrorBuffer(); string templates = "" + "group test;" + NL + "a.b() ::= <<foo>>" + NL ; //string error = null; StringTemplateGroup group = new StringTemplateGroup( new StringReader(templates), typeof(DefaultTemplateLexer), errors); string expecting = "template group parse error: line 2:1: unexpected token:"; Console.Error.WriteLine("errors.ToString() = '{0}'", errors.ToString()); Console.Error.WriteLine("expecting = '{0}'", expecting); Assert.IsTrue(errors.ToString().StartsWith(expecting)); }
public void TestNewlineInString() { String templates = "foo() ::= \"\nfoo\"\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = null; var errors = new ErrorBuffer(); group = new STGroupFile(tmpdir + "/" + "t.stg"); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 1:11: \\n in string" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingTemplate() { String templates = "foo() ::= \n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 2:0: missing template at '<EOF>'" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingEmbeddedTemplate() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; String templates = "t() ::= \"<foo()>\"" + newline; WriteFile(tmpdir, "t.stg", templates); STGroup group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ST st = group.GetInstanceOf("t"); st.Render(); String expected = "context [t] 1:0 no such template: foo" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMap3() { String templates = "d ::= [\"k\":{dfkj}}]\n"; // extra } WriteFile(tmpdir, "t.stg", templates); STGroup group = null; ErrorBuffer errors = new ErrorBuffer(); group = new STGroupFile(tmpdir + "/" + "t.stg"); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 1:17: invalid character '}'" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestUndefinedArgNoProblemInCompatibilityMode() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; ErrorManager.CompatibilityMode = true; try { string templates = "t() ::= \"<u()>\"\n" + "u() ::= \"<x>\"\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = new STGroupFile(tmpdir + "/" + "t.stg"); ST st = group.GetInstanceOf("t"); st.Render(); String expected = ""; String result = errors.ToString(); Assert.AreEqual(expected, result); } finally { ErrorManager.CompatibilityMode = false; } }
public void TestErrorWithinTemplate() { String templates = "foo(a) ::= \"<a b>\"\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = null; ErrorBuffer errors = new ErrorBuffer(); group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "1:15: 'b' came as a complete surprise to me" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestUndefinedArg() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; string templates = "t() ::= \"<u()>\"\n" + "u() ::= \"<x>\"\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); group.Debug = true; ST st = group.GetInstanceOf("t"); st.Render(); String expected = "context [t, u] 1:1 attribute x isn't defined" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestPassUnknownAttr() { String templates = "t() ::= \"<u(x={Ter})>\"\n" + "u(y) ::= <<hi <x>!>>\n"; ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; WriteFile(tmpdir, "t.stg", templates); STGroup group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ST st = group.GetInstanceOf("t"); String expected = "hi Ter!"; String result = st.Render(); Assert.AreEqual(expected, result); // check error now expected = "context [t u] can't set attribute x; template u has no such attribute" + newline; result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestStringTypeMismatch2() { ErrorBuffer errors = new ErrorBuffer(); ErrorManager.ErrorListener = errors; ST e = new ST("<strlen(s)>"); e.Add("s", 34); e.Render(); // generate the error String errorExpecting = "context [anonymous] 1:1 function strlen expects a string not System.Int32" + newline; Assert.AreEqual(errorExpecting, errors.ToString()); }
public void testImplicitOverriddenRegionRedefError() { string templates1 = "" + "group super;" + NL + "a() ::= \"X<@r()>Y\"" + "@a.r() ::= \"foo\"" + NL; StringTemplateGroup group = new StringTemplateGroup( new StringReader(templates1)); string templates2 = "" + "group sub;" + NL + "@a.r() ::= \"foo\"" + NL + "@a.r() ::= \"bar\"" + NL; IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplateGroup subGroup = new StringTemplateGroup( new StringReader(templates2), errors, group); StringTemplate st = subGroup.GetInstanceOf("a"); string result = errors.ToString(); string expecting = "group sub line 3: redefinition of template region: @a.r"; Assert.AreEqual(expecting, result); }
public void TestUnterminatedString() { String templates = "f() ::= \""; // extra } WriteFile(tmpdir, "t.stg", templates); STGroup group = null; ErrorBuffer errors = new ErrorBuffer(); group = new STGroupFile(tmpdir + "/" + "t.stg"); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 1:9: unterminated string" + newline + "t.stg 1:9: missing template at '<EOF>'" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void testImplicitRegionRedefError() { // cannot define an implicitly-defined template more than once string templates = "" + "group test;" + NL + "a() ::= \"X<@r()>Y\"" + NL + "@a.r() ::= \"foo\"" + NL + "@a.r() ::= \"bar\"" + NL; IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), errors); StringTemplate st = group.GetInstanceOf("a"); st.ToString(); string result = errors.ToString(); string expecting = "group test line 4: redefinition of template region: @a.r"; Assert.AreEqual(expecting, result); }
public void TestParen2() { String templates = "foo) ::= << >>\n" + "bar() ::= <<bar>>\n"; WriteFile(tmpdir, "t.stg", templates); STGroup group = null; var errors = new ErrorBuffer(); group = new STGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 1:0: garbled template definition starting at 'foo'" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public virtual void testParallelAttributeIterationWithMismatchArgListSizes() { IStringTemplateErrorListener errors = new ErrorBuffer(); StringTemplate e = new StringTemplate("$names,phones,salaries:{n,p | $n$@$p$}; separator=\", \"$"); e.ErrorListener = errors; e = e.GetInstanceOf(); e.SetAttribute("names", "Ter"); e.SetAttribute("names", "Tom"); e.SetAttribute("phones", "1"); e.SetAttribute("phones", "2"); e.SetAttribute("salaries", "big"); string expecting = "Ter@1, Tom@2"; Assert.AreEqual(expecting, e.ToString()); string errorExpecting = "number of arguments [n, p] mismatch between attribute list and anonymous template in context [anonymous]"; Assert.AreEqual(errorExpecting, errors.ToString()); }
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); }