Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroup


  @Test public void testPassThruWithDefaultValueThatLacksDefinitionAbove() throws Exception {
    String templates =
      "a(x) ::= \"<b(...)>\"\n" + // should not set y when it sees "no definition" 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


  @Test public void testPassThruPartialArgs() throws Exception {
    String templates =
      "a(x,y) ::= \"<b(y={99},...)>\"\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 = "x99";
    String result = a.render();
    assertEquals(expected, result);
View Full Code Here

  @Test public void testPassThruNoMissingArgs() throws Exception {
    String templates =
      "a(x,y) ::= \"<b(y={99},x={1},...)>\"\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 = "199";
    String result = a.render();
    assertEquals(expected, result);
View Full Code Here

    String result = a.render();
    assertEquals(expected, result);
  }

    @Test public void testDefineTemplate() throws Exception {
        STGroup group = new STGroup();
        group.defineTemplate("inc", "x", "<x>+1");
        group.defineTemplate("test", "name", "hi <name>!");
        ST st = group.getInstanceOf("test");
        st.add("name", "Ter");
        st.add("name", "Tom");
        st.add("name", "Sumana");
        String expected =
            "hi TerTomSumana!";
View Full Code Here

        String result = st.render();
        assertEquals(expected, result);
    }

  @Test public void testMap() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("inc", "x", "[<x>]");
    group.defineTemplate("test", "name", "hi <name:inc()>!");
    ST st = group.getInstanceOf("test");
    st.add("name", "Ter");
    st.add("name", "Tom");
    st.add("name", "Sumana");
    String expected =
      "hi [Ter][Tom][Sumana]!";
View Full Code Here

    String result = st.render();
    assertEquals(expected, result);
  }

  @Test public void testIndirectMap() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("inc", "x", "[<x>]");
    group.defineTemplate("test", "t,name", "<name:(t)()>!");
    ST st = group.getInstanceOf("test");
    st.add("t", "inc");
    st.add("name", "Ter");
    st.add("name", "Tom");
    st.add("name", "Sumana");
    String expected =
View Full Code Here

        String templates =
            "d ::= [\"foo\":\"bold\"]\n" +
            "test(name) ::= \"<name:(d.foo)()>\"\n" +
            "bold(x) ::= <<*<x>*>>\n";
        writeFile(tmpdir, "t.stg", templates);
        STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
        ST st = group.getInstanceOf("test");
        st.add("name", "Ter");
        st.add("name", "Tom");
        st.add("name", "Sumana");
        String expected = "*Ter**Tom**Sumana*";
        String result = st.render();
View Full Code Here

        String result = st.render();
        assertEquals(expected, result);
    }

    @Test public void testParallelMap() throws Exception {
        STGroup group = new STGroup();
        group.defineTemplate("test", "names,phones", "hi <names,phones:{n,p | <n>:<p>;}>");
        ST st = group.getInstanceOf("test");
        st.add("names", "Ter");
        st.add("names", "Tom");
        st.add("names", "Sumana");
        st.add("phones", "x5001");
        st.add("phones", "x5002");
View Full Code Here

        String result = st.render();
        assertEquals(expected, result);
    }

    @Test public void testParallelMapWith3Versus2Elements() throws Exception {
        STGroup group = new STGroup();
        group.defineTemplate("test", "names,phones", "hi <names,phones:{n,p | <n>:<p>;}>");
        ST st = group.getInstanceOf("test");
        st.add("names", "Ter");
        st.add("names", "Tom");
        st.add("names", "Sumana");
        st.add("phones", "x5001");
        st.add("phones", "x5002");
View Full Code Here

        String result = st.render();
        assertEquals(expected, result);
    }

  @Test public void testParallelMapThenMap() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("bold", "x", "[<x>]");
    group.defineTemplate("test", "names,phones",
               "hi <names,phones:{n,p | <n>:<p>;}:bold()>");
    ST st = group.getInstanceOf("test");
    st.add("names", "Ter");
    st.add("names", "Tom");
    st.add("names", "Sumana");
    st.add("phones", "x5001");
    st.add("phones", "x5002");
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.