コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: TestRegions.cs プロジェクト: bszafko/antlrcs
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: TestSyntaxErrors.cs プロジェクト: bszafko/antlrcs
        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);
        }
コード例 #11
0
ファイル: TestSyntaxErrors.cs プロジェクト: bszafko/antlrcs
        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);
        }
コード例 #12
0
ファイル: TestSyntaxErrors.cs プロジェクト: bszafko/antlrcs
        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);
        }
コード例 #13
0
ファイル: TestSyntaxErrors.cs プロジェクト: bszafko/antlrcs
        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);
        }