Esempio n. 1
0
        public void TestGroupFileInDirImportsAnotherGroupFile()
        {
            // /randomdir/group.stg with a() imports /randomdir/imported.stg with b()
            // can't have groupdir then groupfile inside that imports
            string dir       = tmpdir;
            string groupFile =
                "import \"imported.stg\"\n" +
                "a() ::= \"a: <b()>\"\n";

            writeFile(dir, "group.stg", groupFile);
            string importedFile =
                "b() ::= \"b\"\n";

            writeFile(dir, "imported.stg", importedFile);
            ITemplateErrorListener errors = new ErrorBuffer();
            TemplateGroup          group  = new TemplateGroupDirectory(dir);

            group.Listener = errors;
            group.GetInstanceOf("/group/a");
            string result    = errors.ToString();
            string substring =
                "import illegal in group files embedded in TemplateGroupDirectory; import \"imported.stg\" in TemplateGroupDirectory";

            StringAssert.Contains(result, substring);
        }
Esempio n. 2
0
        public void TestMessedUpTemplateDoesntCauseRuntimeError()
        {
            string templates =
                "main(p) ::= <<\n" +
                "<f(x=\"abc\")>\n" +
                ">>\n" +
                "\n" +
                "f() ::= <<\n" +
                "<x>\n" +
                ">>\n";

            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group  = null;
            ErrorBuffer       errors = new ErrorBuffer();

            group          = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            Template st = group.GetInstanceOf("main");

            st.Render();

            string expected = "[context [/main] 1:1 passed 1 arg(s) to template /f with 0 declared arg(s)," +
                              " context [/main] 1:1 attribute x isn't defined," +
                              " context [/main /f] 1:1 attribute x isn't defined]";
            string result = errors.Errors.ToListString();

            Assert.AreEqual(expected, result);
        }
 public void TestIndirectCallWithPassThru()
 {
     // pass-through for dynamic template invocation is not supported by the
     // bytecode representation
     writeFile(tmpdir, "t.stg",
         "t1(x) ::= \"<x>\"\n" +
         "main(x=\"hello\",t=\"t1\") ::= <<\n" +
         "<(t)(...)>\n" +
         ">>");
     TemplateGroup group = new TemplateGroupFile(tmpdir + "/t.stg");
     ErrorBuffer errors = new ErrorBuffer();
     group.Listener = errors;
     Template st = group.GetInstanceOf("main");
     Assert.AreEqual("t.stg 2:34: mismatched input '...' expecting RPAREN" + newline, errors.ToString());
     Assert.IsNull(st);
 }
        public void TestIndirectCallWithPassThru()
        {
            // pass-through for dynamic template invocation is not supported by the
            // bytecode representation
            writeFile(tmpdir, "t.stg",
                      "t1(x) ::= \"<x>\"\n" +
                      "main(x=\"hello\",t=\"t1\") ::= <<\n" +
                      "<(t)(...)>\n" +
                      ">>");
            TemplateGroup group  = new TemplateGroupFile(tmpdir + "/t.stg");
            ErrorBuffer   errors = new ErrorBuffer();

            group.Listener = errors;
            Template st = group.GetInstanceOf("main");

            Assert.AreEqual("t.stg 2:34: mismatched input '...' expecting RPAREN" + newline, errors.ToString());
            Assert.IsNull(st);
        }
Esempio n. 5
0
 public void TestGroupFileInDirImportsAnotherGroupFile()
 {
     // /randomdir/group.stg with a() imports /randomdir/imported.stg with b()
     // can't have groupdir then groupfile inside that imports
     string dir = tmpdir;
     string groupFile =
         "import \"imported.stg\"\n" +
         "a() ::= \"a: <b()>\"\n";
     writeFile(dir, "group.stg", groupFile);
     string importedFile =
         "b() ::= \"b\"\n";
     writeFile(dir, "imported.stg", importedFile);
     ITemplateErrorListener errors = new ErrorBuffer();
     TemplateGroup group = new TemplateGroupDirectory(dir);
     group.Listener = errors;
     group.GetInstanceOf("/group/a");
     string result = errors.ToString();
     string substring =
         "import illegal in group files embedded in TemplateGroupDirectory; import \"imported.stg\" in TemplateGroupDirectory";
     StringAssert.Contains(result, substring);
 }
Esempio n. 6
0
        public void TestMessedUpTemplateDoesntCauseRuntimeError()
        {
            string templates =
                "main(p) ::= <<\n" +
                "<f(x=\"abc\")>\n" +
                ">>\n" +
                "\n" +
                "f() ::= <<\n" +
                "<x>\n" +
                ">>\n";
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroupFile group = null;
            ErrorBuffer errors = new ErrorBuffer();
            group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.Listener = errors;
            Template st = group.GetInstanceOf("main");
            st.Render();

            string expected = "[context [/main] 1:1 passed 1 arg(s) to template /f with 0 declared arg(s)," +
                              " context [/main] 1:1 attribute x isn't defined," +
                              " context [/main /f] 1:1 attribute x isn't defined]";
            string result = errors.Errors.ToListString();
            Assert.AreEqual(expected, result);
        }