Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroupString


  @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

  @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 Sub =
      "t() ::= <<\n" +
      "<d.a>\n" +
      ">>\n";
    STGroup r = new STGroupString(Root);
    STGroup s = new STGroupString(Sub);
    s.importTemplates(r);
    ST st = s.getInstanceOf("t"); // visible only if we can see inherited dicts
    String expected = "b";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

  @Test public void testTrimmedNewlinesBeforeAfterInTemplate() throws Exception {
    String templates =
      "a(x) ::= <<"+newline+
      "foo"+newline+
      ">>"+newline;
    STGroupString group = new STGroupString(templates);
    ST st = group.getInstanceOf("a");
    String expected = "foo";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

  }

  @Test public void testDontTrimJustSpaceBeforeAfterInTemplate() throws Exception {
    String templates =
      "a(x) ::= << foo >>\n";
    STGroupString group = new STGroupString(templates);
    ST st = group.getInstanceOf("a");
    String expected = " foo ";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

  @Test public void testSimpleGroupFromString() throws Exception {
    String g =
      "a(x) ::= <<foo>>\n"+
      "b() ::= <<bar>>\n";
    STGroup group = new STGroupString(g);
    ST st = group.getInstanceOf("a");
    String expected = "foo";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

  }

  @Test public void testEarlyEvalOfDefaultArgs() throws Exception {
    String templates =
      "s(x,y={<(x)>}) ::= \"<x><y>\"\n"; // should see x in def arg
    STGroup group = new STGroupString(templates);
    ST b = group.getInstanceOf("s");
    b.add("x", "a");
    String expecting = "aa";
    String result = b.render();
    assertEquals(expecting, result);
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.STGroupString

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.