Package org.stringtemplate.v4.compiler

Examples of org.stringtemplate.v4.compiler.Compiler


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


    assertEquals(expected, errors.toString());
  }

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

    assertEquals(stringsExpected, stringsResult);
  }

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

        assertEquals(stringsExpected, stringsResult);
    }

    @Test public void testProp2() throws Exception {
        String template = "<u.id>: <u.name>";
        CompiledST code = new Compiler().compile(template);
        String asmExpected =
            "load_attr 0, load_prop 1, write, write_str 2, " +
            "load_attr 0, load_prop 3, write";
        String asmResult = code.instrs();
        assertEquals(asmExpected, asmResult);
View Full Code Here

        assertEquals(stringsExpected, stringsResult);
    }

  @Test public void testMap() throws Exception {
    String template = "<name:bold()>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "load_attr 0, null, new 1 1, map, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[name, bold]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testMapAsOption() throws Exception {
    String template = "<a; wrap=name:bold()>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "load_attr 0, options, load_attr 1, null, new 2 1, map, " +
      "store_option 4, write_opt";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testMapArg() throws Exception {
    String template = "<name:bold(x)>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "load_attr 0, null, load_attr 1, new 2 2, map, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[name, x, bold]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testIndirectMapArg() throws Exception {
    String template = "<name:(t)(x)>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "load_attr 0, load_attr 1, tostr, null, load_attr 2, new_ind 2, map, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[name, t, x]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testRepeatedMap() throws Exception {
    String template = "<name:bold():italics()>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "load_attr 0, null, new 1 1, map, null, new 2 1, map, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
    String stringsExpected = "[name, bold, italics]";
View Full Code Here

    assertEquals(stringsExpected, stringsResult);
  }

  @Test public void testRepeatedMapArg() throws Exception {
    String template = "<name:bold(x):italics(x,y)>";
    CompiledST code = new Compiler().compile(template);
    String asmExpected =
      "load_attr 0, null, load_attr 1, new 2 2, map, " +
      "null, load_attr 1, load_attr 3, new 4 3, map, write";
    String asmResult = code.instrs();
    assertEquals(asmExpected, asmResult);
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.