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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }