Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroup


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

  @Test public void testMapThenParallelMap() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("bold", "x", "[<x>]");
    group.defineTemplate("test", "names,phones",
               "hi <[names:bold()],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 testMapIndexes() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("inc", "x,i", "<i>:<x>");
    group.defineTemplate("test", "name", "<name:{n|<inc(n,i)>}; separator=\", \">");
    ST st = group.getInstanceOf("test");
    st.add("name", "Ter");
    st.add("name", "Tom");
    st.add("name", null); // don't count this one
    st.add("name", "Sumana");
    String expected =
View Full Code Here

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

  @Test public void testMapIndexes2() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("test", "name", "<name:{n | <i>:<n>}; separator=\", \">");
    ST st = group.getInstanceOf("test");
    st.add("name", "Ter");
    st.add("name", "Tom");
    st.add("name", null); // don't count this one. still can't apply subtemplate to null value
    st.add("name", "Sumana");
    String expected =
View Full Code Here

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

  @Test public void testMapSingleValue() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("a", "x", "[<x>]");
    group.defineTemplate("test", "name", "hi <name:a()>!");
    ST st = group.getInstanceOf("test");
    st.add("name", "Ter");
    String expected = "hi [Ter]!";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

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

  @Test public void testMapNullValue() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("a", "x", "[<x>]");
    group.defineTemplate("test", "name", "hi <name:a()>!");
    ST st = group.getInstanceOf("test");
    String expected = "hi !";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

import static org.junit.Assert.assertEquals;

public class TestSubtemplates extends BaseTest {

  @Test public void testSimpleIteration() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("test", "names", "<names:{n|<n>}>!");
    ST st = group.getInstanceOf("test");
    st.add("names", "Ter");
    st.add("names", "Tom");
    st.add("names", "Sumana");
    String expected = "TerTomSumana!";
    String result = st.render();
View Full Code Here

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

  @Test public void testMapIterationIsByKeys() throws Exception {
    STGroup group = new STGroup();
    group.defineTemplate("test", "emails", "<emails:{n|<n>}>!");
    ST st = group.getInstanceOf("test");
    Map<String,String> emails = new LinkedHashMap<String,String>();
    emails.put("parrt", "Ter");
    emails.put("tombu", "Tom");
    emails.put("dmose", "Dan");
    st.add("emails", emails);
View Full Code Here

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

    @Test public void testSimpleIterationWithArg() throws Exception {
        STGroup group = new STGroup();
        group.defineTemplate("test", "names", "<names:{n | <n>}>!");
        ST st = group.getInstanceOf("test");
        st.add("names", "Ter");
        st.add("names", "Tom");
        st.add("names", "Sumana");
        String expected = "TerTomSumana!";
        String result = st.render();
View Full Code Here

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

    @Test public void testNestedIterationWithArg() throws Exception {
        STGroup group = new STGroup();
        group.defineTemplate("test", "users", "<users:{u | <u.id:{id | <id>=}><u.name>}>!");
        ST st = group.getInstanceOf("test");
        st.add("users", new TestCoreBasics.User(1, "parrt"));
        st.add("users", new TestCoreBasics.User(2, "tombu"));
        st.add("users", new TestCoreBasics.User(3, "sri"));
        String expected = "1=parrt2=tombu3=sri!";
        String result = st.render();
View Full Code Here

      "x: <x>\n" +
      "y: <y>\n" +
      ">>"+newline
      ;
    writeFile(tmpdir, "group.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/group.stg");
    ST b = group.getInstanceOf("t");
    b.add("x", "a");
    String expecting =
      "x: a" +newline+
      "y: aa";
    String result = b.render();
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.