Package org.stringtemplate.v4.misc

Examples of org.stringtemplate.v4.misc.ErrorBuffer


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

    STGroupFile group = null;
    STErrorListener errors = new ErrorBuffer();
    group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected = "t.stg 1:20: EOF in string"+newline +
              "t.stg 1:20: premature EOF"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here


    String templates =
      "foo() ::= << <!foo> >>";
    writeFile(tmpdir, "t.stg", templates);

    STGroupFile group = null;
    STErrorListener errors = new ErrorBuffer();
    group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected =
      "t.stg 1:20: Nonterminated comment starting at 1:1: '!>' missing" +newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

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

    STGroupFile group = null;
    STErrorListener errors = new ErrorBuffer();
    group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected = "t.stg 1:19: '>' came as a complete surprise to me"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

    String templates =
      "foo() ::= \"<a,b:t(),u()>\"\n";
    writeFile(tmpdir, "t.stg", templates);

    STGroupFile group = null;
    STErrorListener errors = new ErrorBuffer();
    group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected = "t.stg 1:19: mismatched input ',' expecting RDELIM"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

  @Test
  public void testHandleBuggyDefaultArgument() throws Exception {
    String templates = "main(a={(<\"\")>}) ::= \"\"";
    writeFile(tmpdir, "t.stg", templates);

    final ErrorBuffer errors = new ErrorBuffer();
    STGroup group = new STGroupFile(tmpdir + "/t.stg");
    group.setListener(errors);

    ST st = group.getInstanceOf("main");
    String s = st.render();

    // Check the errors. This contained an "NullPointerException" before
    Assert.assertEquals(
        "t.stg 1:12: mismatched input ')' expecting RDELIM"+newline,
        errors.toString());
  }
View Full Code Here

    "a() ::= \"a: <b()>\"\n";
    writeFile(dir, "group.stg", groupFile);
    String importedFile =
      "b() ::= \"b\"\n";
    writeFile(dir, "imported.stg", importedFile);
    STErrorListener errors = new ErrorBuffer();
    STGroup group = new STGroupDir(dir);
    group.setListener(errors);
    group.getInstanceOf("/group/a");
    String result = errors.toString();
    String expecting =
      "import illegal in group files embedded in STGroupDirs; import \"imported.stg\" in STGroupDir";
    assertTrue(result.contains(expecting));
  }
View Full Code Here

public class TestSyntaxErrors extends BaseTest {
    @Test public void testEmptyExpr() throws Exception {
        String template = " <> ";
        STGroup group = new STGroup();
    ErrorBuffer errors = new ErrorBuffer();
    group.setListener(errors);
    try {
          group.defineTemplate("test", template);
    }
    catch (STException se) {
      assert false;
    }
    String result = errors.toString();
        String expected = "test 1:0: this doesn't look like a template: \" <> \""+newline;
        assertEquals(expected, result);
    }
View Full Code Here

    }

    @Test public void testEmptyExpr2() throws Exception {
        String template = "hi <> ";
        STGroup group = new STGroup();
    ErrorBuffer errors = new ErrorBuffer();
    group.setListener(errors);
    try {
          group.defineTemplate("test", template);
    }
    catch (STException se) {
      assert false;
    }
    String result = errors.toString();
        String expected = "test 1:3: doesn't look like an expression"+newline;
        assertEquals(expected, result);
    }
View Full Code Here

    }

  @Test public void testUnterminatedExpr() throws Exception {
    String template = "hi <t()$";
    STGroup group = new STGroup();
    ErrorBuffer errors = new ErrorBuffer();
    group.setListener(errors);
    try {
      group.defineTemplate("test", template);
    }
    catch (STException se) {
      assert false;
    }
    String result = errors.toString();
    String expected = "test 1:7: invalid character '$'" +newline+
      "test 1:7: invalid character '<EOF>'" +newline+
      "test 1:7: premature EOF"+newline;
    assertEquals(expected, result);
  }
View Full Code Here

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

    @Test public void testIllegalOption() throws Exception {
        ErrorBuffer errors = new ErrorBuffer();
        STGroup group = new STGroup();
    group.setListener(errors);
    group.defineTemplate("test", "name", "<name; bad=\"ugly\">");
        ST st = group.getInstanceOf("test");
        st.add("name", "Ter");
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.misc.ErrorBuffer

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.