Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroup


  public void testEarlyEval2() throws Exception {
    String templates = "main() ::= <<\n<f(p=\"x\")>*\n>>\n\n"
        + "f(p,q={<({a<p>})>}) ::= <<\n-<q>-\n>>";
    writeFile(tmpdir, "t.stg", templates);

    STGroup group = new STGroupFile(tmpdir + "/t.stg");

    ST st = group.getInstanceOf("main");

    String s = st.render();
    Assert.assertEquals("-ax-*", s);

    // When <f(...)> is invoked only once inspect throws no Exception in
View Full Code Here


        + "t2() ::= \"Hello\"\n" //
        + "t(x={<(t2())>}) ::= \"<x>\"";

    writeFile(tmpdir, "t.stg", templates);

    STGroup group = new STGroupFile(tmpdir + "/t.stg");

    ST st = group.getInstanceOf("main");

    String s = st.render();
    Assert.assertEquals("Hello", s);

    // Inspecting this template threw an ArrayIndexOutOfBoundsException
View Full Code Here

  @Test
  public void testEarlyEvalInIfExpr() throws Exception {
    String templates = "main(x) ::= << <if((x))>foo<else>bar<endif> >>";
    writeFile(tmpdir, "t.stg", templates);

    STGroup group = new STGroupFile(tmpdir + "/t.stg");

    ST st = group.getInstanceOf("main");

    String s = st.render();
    Assert.assertEquals(" bar ", s);

    st.add("x", "true");
View Full Code Here

  @Test
  public void testEarlyEvalOfSubtemplateInIfExpr() throws Exception {
    String templates = "main(x) ::= << <if(({a<x>b}))>foo<else>bar<endif> >>";
    writeFile(tmpdir, "t.stg", templates);

    STGroup group = new STGroupFile(tmpdir + "/t.stg");

    ST st = group.getInstanceOf("main");

    String s = st.render();
    Assert.assertEquals(" foo ", s);
  }
View Full Code Here

      "  default: \"other\"\n"+
      "]\n" +
      "main(x) ::= << p<x>t: <m.({p<x>t})>, <if(m.({p<x>t}))>if<else>else<endif> >>\n";
    writeFile(tmpdir, "t.stg", templates);

    STGroup group = new STGroupFile(tmpdir + "/t.stg");

    ST st = group.getInstanceOf("main");

    st.add("x", null);
    String s = st.render();
    Assert.assertEquals(" pt: other, if ", s);
View Full Code Here

  public void testEarlyEvalOfMapInIfExprPassInHashMap() throws Exception {
    String templates =
      "main(m,x) ::= << p<x>t: <m.({p<x>t})>, <if(m.({p<x>t}))>if<else>else<endif> >>\n";
    writeFile(tmpdir, "t.stg", templates);

    STGroup group = new STGroupFile(tmpdir + "/t.stg");

    ST st = group.getInstanceOf("main");
    st.add("m", new HashMap<String, String>() {{put("parrt","value");}});

    st.add("x", null);
    String s = st.render();
    Assert.assertEquals(" pt: , else ", s); // m[null] has no default value so else clause
View Full Code Here

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

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

  }

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

    String template =
      "t(x) ::= <%\n" +
      "  foo\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

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.