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 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 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 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 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 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 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 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 TestEOFInExpr() { String templates = "foo() ::= \"hi <name:{[<aaa.bb>]}\"\n"; WriteFile(tmpdir, "t.stg", templates); TemplateGroup group = null; var errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "1:32: premature EOF" + newline; String result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestValidButOutOfPlaceCharOnDifferentLine() { String templates = "foo() ::= \"hi <\n" + ".> mom\"\n"; WriteFile(tmpdir, "t.stg", templates); ITemplateErrorListener errors = new ErrorBuffer(); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "t.stg 1:15: \\n in string, 1:14: doesn't look like an expression" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }
public void TestMissingRPAREN() { String templates = "foo() ::= \"hi <foo(>\"\n"; WriteFile(tmpdir, "t.stg", templates); TemplateGroup group = null; var errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "1:19: mismatched input '>' expecting RPAREN" + 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); TemplateGroup group = null; ITemplateErrorListener errors = new ErrorBuffer(); group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); ErrorManager.ErrorListener = errors; group.Load(); // force load String expected = "1:29: '!' came as a complete surprise to me" + newline; string result = errors.ToString(); Assert.AreEqual(expected, result); }