Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroup


      "  <if(x)>\n" +
      "    foo\n" +
      "  <endif>\n" +
      "  <x>\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "foo99";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here


  @Test public void testKeepWS() throws Exception {
    String template =
      "t(x) ::= <%\n" +
      "  <x> <x> hi\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "99 99 hi";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

      "  Ignore\n" +
      "  newlines and indents\n" +
      "<x>\n\n\n" +
      "<@end>\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "Ignorenewlines and indents99";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

    String g2 = "@a.r() ::= <%\n" +
    "  foo\n\n\n" +
    "%>\n";
    writeFile(dir, "g2.stg", g2);

    STGroup group1 = new STGroupFile(dir+"/g1.stg");
    STGroup group2 = new STGroupFile(dir+"/g2.stg");
    group2.importTemplates(group1); // define r in g2
    ST st = group2.getInstanceOf("a");
    String expected = "[foo]";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

    @Test public void testSetUnknownAttr() throws Exception {
        String templates =
            "t() ::= <<hi <name>!>>\n";
        ErrorBuffer errors = new ErrorBuffer();
        writeFile(tmpdir, "t.stg", templates);
        STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
        ST st = group.getInstanceOf("t");
        String result = null;
    try {
      st.add("name", "Ter");
    }
    catch (IllegalArgumentException iae) {
View Full Code Here

  }

  @Test public void testNoSuchProp() throws Exception {
    ErrorBufferAllErrors errors = new ErrorBufferAllErrors();
    String template = "<u.qqq>";
    STGroup group = new STGroup();
    group.setListener(errors);
    ST st = new ST(group, template);
    st.add("u", new User(1, "parrt"));
    String expected = "";
    String result = st.render();
    assertEquals(expected, result);
View Full Code Here

    assertEquals("org.stringtemplate.v4.test.BaseTest$User.qqq", e.propertyName);
  }

  @Test public void testNullIndirectProp() throws Exception {
    ErrorBufferAllErrors errors = new ErrorBufferAllErrors();
    STGroup group = new STGroup();
    group.setListener(errors);
    String template = "<u.(qqq)>";
    ST st = new ST(group, template);
    st.add("u", new User(1, "parrt"));
    st.add("qqq", null);
    String expected = "";
View Full Code Here

    assertEquals("org.stringtemplate.v4.test.BaseTest$User.null", e.propertyName);
  }

  @Test public void testPropConvertsToString() throws Exception {
    ErrorBufferAllErrors errors = new ErrorBufferAllErrors();
    STGroup group = new STGroup();
    group.setListener(errors);
    String template = "<u.(name)>";
    ST st = new ST(group, template);
    st.add("u", new User(1, "parrt"));
    st.add("name", 100);
    String expected = "";
View Full Code Here

  @Test public void testPassThru() throws Exception {
    String templates =
      "a(x,y) ::= \"<b(...)>\"\n" +
      "b(x,y) ::= \"<x><y>\"\n";
    STGroup group = new STGroupString(templates);
    ST a = group.getInstanceOf("a");
    a.add("x", "x");
    a.add("y", "y");
    String expected = "xy";
    String result = a.render();
    assertEquals(expected, result);
View Full Code Here

  @Test public void testPassThruWithDefaultValue() throws Exception {
    String templates =
      "a(x,y) ::= \"<b(...)>\"\n" + // should not set y when it sees "no value" from above
      "b(x,y={99}) ::= \"<x><y>\"\n";
    STGroup group = new STGroupString(templates);
    ST a = group.getInstanceOf("a");
    a.add("x", "x");
    String expected = "x99";
    String result = a.render();
    assertEquals(expected, result);
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.STGroup

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.