Пример #1
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);
 }
Пример #2
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);
 }
Пример #3
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);
 }
Пример #4
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);
 }
Пример #5
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);
 }
Пример #6
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);
 }
Пример #7
0
 public void TestList()
 {
     string template = "<[a,b]>";
     CompiledTemplate code = new TemplateCompiler(new TemplateGroup()).Compile(template);
     string asmExpected = "list, load_attr 0, add, load_attr 1, add, write";
     string asmResult = code.GetInstructions();
     Assert.AreEqual(asmExpected, asmResult);
     string stringsExpected = "[a, b]";
     string stringsResult = code.strings.ToListString();
     Assert.AreEqual(stringsExpected, stringsResult);
 }
Пример #8
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);
 }
Пример #9
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);
 }
Пример #10
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);
 }
Пример #11
0
 public void TestIncludeWithPassThrough()
 {
     string template = "hi <foo(...)>";
     CompiledTemplate code = new TemplateCompiler(new TemplateGroup()).Compile(template);
     string asmExpected =
         "write_str 0, args, passthru 1, new_box_args 1, write";
     string asmResult = code.GetInstructions();
     Assert.AreEqual(asmExpected, asmResult);
     string stringsExpected = "[hi , foo]";
     string stringsResult = code.strings.ToListString();
     Assert.AreEqual(stringsExpected, stringsResult);
 }
Пример #12
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);
 }
Пример #13
0
 public void TestIfElse()
 {
     string template = "go: <if(name)>hi, foo<else>bye<endif>";
     CompiledTemplate code = new TemplateCompiler(new TemplateGroup()).Compile(template);
     string asmExpected =
         "write_str 0, " +
         "load_attr 1, " +
         "brf 15, " +
         "write_str 2, " +
         "br 18, " +
         "write_str 3";
     string asmResult = code.GetInstructions();
     Assert.AreEqual(asmExpected, asmResult);
     string stringsExpected = "[go: , name, hi, foo, bye]";
     string stringsResult = code.strings.ToListString();
     Assert.AreEqual(stringsExpected, stringsResult);
 }
Пример #14
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);
 }
Пример #15
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);
 }
Пример #16
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);
 }
Пример #17
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);
 }
Пример #18
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);
 }
Пример #19
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);
 }
Пример #20
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);
 }
Пример #21
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);
 }