Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroupFile


        String templates =
                "A(x) ::= \"<B()>\""+newline+
                "B(y={<(x)>}) ::= \"<y> <x> <x> <y>\""+newline
                ;
        writeFile(tmpdir, "group.stg", templates);
        STGroup group = new STGroupFile(tmpdir+"/group.stg");
        ST a = group.getInstanceOf("A");
        a.add("x", new Counter());
        String expecting = "0 1 2 0"; // trace must be false to get these numbers
        String result = a.render();
        //System.err.println("result='"+result+"'");
        assertEquals(expecting, result);
View Full Code Here


    String dir = getRandomDir();
    String groupFile =
      "f(x,y) ::= \"<x><y>\"\n" +
      "g() ::= \"<f(true,{a})>\"";
    writeFile(dir, "group.stg", groupFile);
    STGroupFile group = new STGroupFile(dir+"/group.stg");
    ST st = group.getInstanceOf("g");
    String expected = "truea";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

    String dir = getRandomDir();
    String groupFile =
      "f(x,y) ::= \"<x><y>\"\n" +
      "g() ::= \"<f(x={a},y={b})>\"";
    writeFile(dir, "group.stg", groupFile);
    STGroupFile group = new STGroupFile(dir+"/group.stg");
    ST st = group.getInstanceOf("g");
    String expected = "ab";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

    String dir = getRandomDir();
    String groupFile =
      "f(x,y) ::= \"<x><y>\"\n" +
      "g() ::= \"<f(y={b},x={a})>\"";
    writeFile(dir, "group.stg", groupFile);
    STGroupFile group = new STGroupFile(dir+"/group.stg");
    ST st = group.getInstanceOf("g");
    String expected = "ab";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

      "f(x,y) ::= \"<x><y>\"\n" +
      "g() ::= \"<f(x={a},z={b})>\"";
       //012345678901234567

    writeFile(dir, "group.stg", groupFile);
    STGroupFile group = new STGroupFile(dir+"/group.stg");
    ErrorBuffer errors = new ErrorBuffer();
    group.setListener(errors);
    ST st = group.getInstanceOf("g");
    st.render();
    String expected = "context [/g] 1:1 attribute z isn't defined"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

      "f(x,y) ::= \"<x><y>\"\n" +
      "g() ::= \"<f(x={a},{b})>\"";
       //01234567890123456789

    writeFile(dir, "group.stg", groupFile);
    STGroupFile group = new STGroupFile(dir+"/group.stg");
    ErrorBuffer errors = new ErrorBuffer();
    group.setListener(errors);
    group.load();
    String expected = "group.stg 2:18: mismatched input '{' expecting ELLIPSIS"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

        "f(x,y) ::= \"<x><y>\"\n" +
       //01234567890 1234567 8 9
        "g(name) ::= \"<(name)(x={a},y={b})>\"";
       //012345678901 2345678901234567890123 4
    writeFile(dir, "group.stg", groupFile);
    STGroupFile group = new STGroupFile(dir+"/group.stg");
    ErrorBuffer errors = new ErrorBuffer();
    group.setListener(errors);
    group.load();
    String expected = "group.stg 2:22: '=' came as a complete surprise to me"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

    String dir = getRandomDir();
    String a =
      "a(x) ::= <<foo>>\n" +
      "b() ::= <<bar>>\n";
    writeFile(dir, "a.stg", a);
    STGroup group = new STGroupFile(dir+"/a.stg");
    group.load(); // force load
    ST st = group.getInstanceOf("a");
    int originalHashCode = System.identityHashCode(st);
    group.unload(); // blast cache
    st = group.getInstanceOf("a");
    int newHashCode = System.identityHashCode(st);
    assertEquals(originalHashCode==newHashCode, false); // diff objects
    String expected = "foo";
    String result = st.render();
    assertEquals(expected, result);
    st = group.getInstanceOf("b");
    expected = "bar";
    result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

            ">>\n";
        writeFile(dir, "group1.stg", groupFile1);
        String groupFile2 =
            "b() ::= \"bar\"\n";
        writeFile(dir, "group2.stg", groupFile2);
        STGroup group1 = new STGroupFile(dir+"/group1.stg");

        // Is the imported template b found?
        ST stb = group1.getInstanceOf("b");
        assertEquals("bar", stb.render());

        // Is the include of b() resolved?
        ST sta = group1.getInstanceOf("a");
        assertEquals("foobar", sta.render());

        // Are the correct "ThatCreatedThisInstance" groups assigned
        assertEquals("group1",sta.groupThatCreatedThisInstance.getName());
        assertEquals("group1",stb.groupThatCreatedThisInstance.getName());
View Full Code Here

    String templates =
      "t() ::= \"foo\"\n" +
      "main() ::= \"<t()>\"";
    writeFile(tmpdir, "t.stg", templates);

    STGroup group = new STGroupFile(tmpdir + "/t.stg");
    // try to get an undefined template.
    // This will add an entry to the "templates" field in STGroup, however
    // this should not be returned.
    group.lookupTemplate("t2");

    Set<String> names = group.getTemplateNames();

    // Should only contain "t" and "main" (not "t2")
    assertEquals(2, names.size());
    assertTrue(names.contains("/t"));
    assertTrue(names.contains("/main"));
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.STGroupFile

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.