Ejemplo n.º 1
0
        public void TestAnonIncludeArgs()
        {
            string           template    = "<({ a, b | <a><b>})>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "new 0 0, tostr, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[_sub1]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 2
0
        public void TestIndirectIncludeWitArgs()
        {
            string           template    = "hi <(foo)(a,b)>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, load_attr 1, tostr, load_attr 2, load_attr 3, new_ind 2, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[hi , foo, a, b]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 3
0
        public void TestSuperIncludeWithArgs()
        {
            string           template    = "<super.foo(a,{b})>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, new 1 0, super_new 2 2, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[a, _sub1, foo]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 4
0
        public void TestSuperIncludeWithNamedArgs()
        {
            string           template    = "<super.foo(x=a,y={b})>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "args, load_attr 0, store_arg 1, new 2 0, store_arg 3, super_new_box_args 4, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[a, x, _sub1, y, foo]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 5
0
        public void TestInclude()
        {
            string           template    = "hi <foo()>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, new 1 0, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[hi , foo]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 6
0
        public void TestIncludeWithPartialPassThrough()
        {
            string           template    = "hi <foo(x=y,...)>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, args, load_attr 1, store_arg 2, passthru 3, new_box_args 3, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[hi , y, x, foo]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 7
0
        public void TestOptionAsTemplate()
        {
            string           template    = "hi <name; separator={, }>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, load_attr 1, options, new 2 0, store_option 3, write_opt";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[hi , name, _sub1]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 8
0
        public void TestIf()
        {
            string           template    = "go: <if(name)>hi, foo<endif>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, load_attr 1, brf 12, write_str 2";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[go: , name, hi, foo]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 9
0
        public void TestAnonZipMap()
        {
            string           template    = "<a,b:{x,y | <x><y>}>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, load_attr 1, null, null, new 2 2, zip_map 2, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[a, b, _sub1]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 10
0
        public void TestAnonMap()
        {
            string           template    = "<name:{n | <n>}>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, null, new 1 1, map, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[name, _sub1]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 11
0
        public void TestProp()
        {
            string           template    = "hi <a.b>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, load_attr 1, load_prop 2, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[hi , a, b]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 12
0
        public void TestZipMapArg()
        {
            string           template    = "<names,phones:bold(x)>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, load_attr 1, null, null, load_attr 2, new 3 3, zip_map 2, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[names, phones, x, bold]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 13
0
        public void TestRotMapArg()
        {
            string           template    = "<name:bold(x),italics()>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, null, load_attr 1, new 2 2, null, new 3 1, rot_map 2, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[name, x, bold, italics]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 14
0
        public void TestRepeatedMap()
        {
            string           template    = "<name:bold():italics()>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, null, new 1 1, map, null, new 2 1, map, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[name, bold, italics]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 15
0
        public void TestIndirectMapArg()
        {
            string           template    = "<name:(t)(x)>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, load_attr 1, tostr, null, load_attr 2, new_ind 2, map, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[name, t, x]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 16
0
        public void TestRegion()
        {
            string template = "x:<@r()>";
            // compile as if in root dir and in template 'a'
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup('<', '>')).Compile("a", template);
            string           asmExpected =
                "write_str 0, new 1 0, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[x:, region__a__r]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 17
0
        public void TestEmbeddedRegion()
        {
            string template = "<@r>foo<@end>";
            // compile as if in root dir and in template 'a'
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup('<', '>')).Compile("a", template);
            string           asmExpected =
                "new 0 0, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[region__a__r]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 18
0
        public void TestMapAsOption()
        {
            string           template    = "<a; wrap=name:bold()>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, options, load_attr 1, null, new 2 1, map, " +
                "store_option 4, write_opt";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[a, name, bold]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 19
0
        public void TestProp2()
        {
            string           template    = "<u.id>: <u.name>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "load_attr 0, load_prop 1, write, write_str 2, " +
                "load_attr 0, load_prop 3, write";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[u, id, : , name]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 20
0
        public void TestSuperInclude()
        {
            string           template    = "<super.foo()>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "super_new 0 0, write";

            code.Dump();
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[foo]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 21
0
        public void TestElseIf()
        {
            string           template    = "go: <if(name)>hi, foo<elseif(user)>a user<endif>";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, " +
                "load_attr 1, " +
                "brf 15, " +
                "write_str 2, " +
                "br 24, " +
                "load_attr 3, " +
                "brf 24, " +
                "write_str 4";
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
            string stringsExpected = "[go: , name, hi, foo, user, a user]";
            string stringsResult   = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
        }
Ejemplo n.º 22
0
        public void TestOptions()
        {
            string           template    = "hi <name; anchor, wrap=foo(), separator=\", \">";
            CompiledTemplate code        = new TemplateCompiler(new TemplateGroup()).Compile(template);
            string           asmExpected =
                "write_str 0, " +
                "load_attr 1, " +
                "options, " +
                "load_str 2, " +
                "store_option 0, " +
                "new 3 0, " +
                "store_option 4, " +
                "load_str 4, " +
                "store_option 3, " +
                "write_opt";
            string stringsExpected = // the ", , ," is the ", " separator string
                                     "[hi , name, true, foo, , ]";
            string stringsResult = code.strings.ToListString();

            Assert.AreEqual(stringsExpected, stringsResult);
            string asmResult = code.GetInstructions();

            Assert.AreEqual(asmExpected, asmResult);
        }