Load() защищенный Метод

protected Load ( string name ) : CompiledTemplate
name string
Результат Antlr4.StringTemplate.Compiler.CompiledTemplate
Пример #1
0
        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: the explicit definition of region /a.r hides an embedded definition in the same group" + newline;
            string result = errors.ToString();
            Assert.AreEqual(expected, result);
        }
Пример #2
0
        public void TestArg()
        {
            string templates =
                "foo(a,) ::= << >>\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:6: missing ID at ')'" + newline;
            string result = errors.ToString();
            Assert.AreEqual(expected, result);
        }
Пример #3
0
 public void TestNamedArgsNotAllowInIndirectInclude()
 {
     string dir = tmpdir;
     string groupFile =
         "f(x,y) ::= \"<x><y>\"\n" +
         "g(name) ::= \"<(name)(x={a},y={b})>\"";
     //0123456789012345678901234567890
     writeFile(dir, "group.stg", groupFile);
     TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "group.stg"));
     ErrorBuffer errors = new ErrorBuffer();
     group.Listener = errors;
     group.Load();
     // TODO: this could be more informative about the incorrect use of named arguments
     string expected = "group.stg 2:22: '=' came as a complete surprise to me" + newline;
     string result = errors.ToString();
     Assert.AreEqual(expected, result);
 }
Пример #4
0
        public void TestUnclosedTemplate()
        {
            string templates =
                "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: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);
        }
Пример #5
0
        public void TestParen()
        {
            string templates =
                "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:5: no viable alternative at input '::='" + newline;
            string result = errors.ToString();
            Assert.AreEqual(expected, result);
        }
Пример #6
0
        public void TestMissingImportString()
        {
            string templates =
                "import\n" +
                "foo() ::= <<>>\n";
            writeFile(tmpdir, "t.stg", templates);

            ITemplateErrorListener errors = new ErrorBuffer();
            TemplateGroup group = new TemplateGroupFile(Path.Combine(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: missing EndOfFile at '('" + newline;
            string result = errors.ToString();
            Assert.AreEqual(expected, result);
        }
Пример #7
0
        public void TestMap2()
        {
            string templates =
                "d ::= [\"k\":]\n";
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            group.Load(); // force load
            string expected = "[t.stg 1:11: missing value for key at ']']";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }
Пример #8
0
        public void TestDefaultArgsOutOfOrder()
        {
            string templates =
                "foo(a={hi}, b) ::= << >>\n";
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            group.Load(); // force load
            string expected =
                "[t.stg 1:13: Optional parameters must appear after all required parameters]";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }
Пример #9
0
        public void TestNestedDefaultValueTemplate()
        {
            string templates =
                "t(a={x | <x:{y|<y>}>}) ::= \"ick\"" + Environment.NewLine;

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Load();
            string expected =
                "t(a={x | <x:{y|<y>}>}) ::= <<" + Environment.NewLine +
                "ick" + Environment.NewLine +
                ">>" + Environment.NewLine;
            string result = group.Show();
            Assert.AreEqual(expected, result);
        }
Пример #10
0
        public void TestCantDefineEmbeddedRegionAgainInTemplate()
        {
            string dir = tmpdir;
            string g =
                "a() ::= <<\n" +
                "[\n" +
                "<@r>foo<@end>\n" +
                "<@r()>\n" +
                "]\n" +
                ">>\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();
            Assert.AreEqual(0, errors.Errors.Count);

            Template template = group.GetInstanceOf("a");
            string expected =
                "[" + newline +
                "foo" + newline +
                "foo" + newline +
                "]";
            string result = template.Render();
            Assert.AreEqual(expected, result);
        }
Пример #11
0
        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);
        }
Пример #12
0
        public void TestEmptyDictionary()
        {
            string templates =
                "d ::= []\n";
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group = null;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            group.Load(); // force load
            Assert.AreEqual(0, errors.Errors.Count);
        }
Пример #13
0
 public void TestDictEmptyDefaultValue()
 {
     string templates =
             "typeInit ::= [\"int\":\"0\", default:] " + newline +
             "var(type,name) ::= \"<type> <name> = <typeInit.(type)>;\"" + newline
             ;
     writeFile(tmpdir, "test.stg", templates);
     ErrorBuffer errors = new ErrorBuffer();
     TemplateGroupFile group = new TemplateGroupFile(Path.Combine(tmpdir, "test.stg"));
     group.Listener = errors;
     group.Load();
     string expected = "[test.stg 1:33: missing value for key at ']']";
     string result = errors.Errors.ToListString();
     Assert.AreEqual(expected, result);
 }
Пример #14
0
 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);
 }
Пример #15
0
        public void TestValidButOutOfPlaceCharOnDifferentLine()
        {
            string templates =
                    "foo() ::= \"hi <\n" +
                    ".> mom\"\n";
            writeFile(tmpdir, "t.stg", templates);

            ErrorBuffer 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: \\n in string, t.stg 1:14: doesn't look like an expression]";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }
Пример #16
0
        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);
        }
Пример #17
0
        public void TestEOFInExpr()
        {
            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);
        }
Пример #18
0
        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);
        }
Пример #19
0
        public void TestErrorWithinTemplate()
        {
            string templates =
                "foo(a) ::= \"<a b>\"\n";
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            group.Load(); // force load
            string expected = "[t.stg 1:15: 'b' came as a complete surprise to me]";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }
Пример #20
0
        public void TestIt()
        {
            string templates =
                "main() ::= <<" + newline +
                "<@r>a<@end>" + newline +
                "<@r()>" + newline +
                ">>";
            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            ErrorBuffer errors = new ErrorBuffer();
            group.Listener = errors;
            group.Load();
            Assert.AreEqual(0, errors.Errors.Count);

            Template template = group.GetInstanceOf("main");
            string expected =
                "a" + newline +
                "a";
            string result = template.Render();
            Assert.AreEqual(expected, result);
        }
Пример #21
0
        public void TestMap3()
        {
            string templates =
                "d ::= [\"k\":{dfkj}}]\n"; // extra }
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            group.Load(); // force load
            string expected = "[t.stg 1:17: invalid character '}']";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }
Пример #22
0
        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);
        }
Пример #23
0
        public void TestNewlineInString()
        {
            string templates =
                "foo() ::= \"\nfoo\"\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:11: \\n in string" + newline;
            string result = errors.ToString();
            Assert.AreEqual(expected, result);
        }
Пример #24
0
        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);
        }
Пример #25
0
        public void TestParen2()
        {
            string templates =
                "foo) ::= << >>\n" +
                "bar() ::= <<bar>>\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:0: garbled template definition starting at 'foo'" + newline;
            string result = errors.ToString();
            Assert.AreEqual(expected, result);
        }
Пример #26
0
        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);
        }
Пример #27
0
        public void TestUnterminatedString()
        {
            string templates =
                "f() ::= \""; // extra }
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            group.Load(); // force load
            string expected = "[t.stg 1:9: unterminated string, t.stg 1:9: missing template at '<EOF>']";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }
Пример #28
0
        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);
        }
Пример #29
0
        public void TestArg3()
        {
            string templates =
                "foo(a b) ::= << >>\n";
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            group.Load(); // force load
            string expected =
                "[t.stg 1:6: no viable alternative at input 'b']";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }
Пример #30
0
        public void TestMissingNamedArg()
        {
            string dir = tmpdir;
            string groupFile =
                "f(x,y) ::= \"<x><y>\"\n" +
                "g() ::= \"<f(x={a},{b})>\"";
            //012345678901234567

            writeFile(dir, "group.stg", groupFile);
            TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "group.stg"));
            ErrorBuffer errors = new ErrorBuffer();
            group.Listener = errors;
            group.Load();
            string expected = "group.stg 2:18: mismatched input '{' expecting ELLIPSIS" + newline;
            string result = errors.ToString();
            Assert.AreEqual(expected, result);
        }