Package org.stringtemplate.v4.compiler

Examples of org.stringtemplate.v4.compiler.Compiler


  @Override
    public void setUp() { org.stringtemplate.v4.compiler.Compiler.subtemplateCount = 0; }

    @Test public void testAttr() throws Exception {
        String template = "hi <name>";
        CompiledST code = new Compiler().compile(template);
        String asmExpected =
            "write_str 0, " +
            "load_attr 1, " +
            "write";
        String asmResult = code.instrs();
View Full Code Here


        assertEquals(stringsExpected, stringsResult);
    }

  @Test public void testInclude() throws Exception {
    String template = "hi <foo()>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "write_str 0, new 1 0, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[hi , foo]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testIncludeWithPassThrough() throws Exception {
    String template = "hi <foo(...)>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "write_str 0, args, passthru 1, new_box_args 1, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[hi , foo]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testIncludeWithPartialPassThrough() throws Exception {
    String template = "hi <foo(x=y,...)>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "write_str 0, args, load_attr 1, store_arg 2, passthru 3, new_box_args 3, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[hi , y, x, foo]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testSuperInclude() throws Exception {
    String template = "<super.foo()>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "super_new 0 0, write";
    code.dump();
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testSuperIncludeWithArgs() throws Exception {
    String template = "<super.foo(a,{b})>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "load_attr 0, new 1 0, super_new 2 2, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[a, _sub1, foo]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testSuperIncludeWithNamedArgs() throws Exception {
    String template = "<super.foo(x=a,y={b})>";
    CompiledST code = new Compiler().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.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[a, x, _sub1, y, foo]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testAnonIncludeArgs() throws Exception {
    String template = "<({ a, b | <a><b>})>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "new 0 0, tostr, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[_sub1]";
View Full Code Here

  @Test public void testAnonIncludeArgMismatch() throws Exception {
    STErrorListener errors = new ErrorBuffer();
    String template = "<a:{foo}>";
    STGroup g = new STGroup();
    g.errMgr = new ErrorManager(errors);
    CompiledST code = new Compiler(g).compile(template);
    String expected = "1:3: anonymous template has 0 arg(s) but mapped across 1 value(s)"+newline;
    assertEquals(expected, errors.toString());
  }
View Full Code Here

  @Test public void testAnonIncludeArgMismatch2() throws Exception {
    STErrorListener errors = new ErrorBuffer();
    String template = "<a,b:{x|foo}>";
    STGroup g = new STGroup();
    g.errMgr = new ErrorManager(errors);
    CompiledST code = new Compiler(g).compile(template);
    String expected = "1:5: anonymous template has 1 arg(s) but mapped across 2 value(s)"+newline;
    assertEquals(expected, errors.toString());
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.compiler.Compiler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.