Package org.stringtemplate.v4.misc

Examples of org.stringtemplate.v4.misc.ErrorBuffer


       //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


    Assert.assertEquals(expecting, st.render());
  }

  @Test public void testLineBreakMissingTrailingNewline() throws Exception {
    writeFile(tmpdir, "t.stg", "a(x) ::= <<<\\\\>\r\n>>"); // that is <<<\\>>> not an escaped >>
    ErrorBuffer errors = new ErrorBuffer();
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    ST st = group.getInstanceOf("a");
    assertEquals("t.stg 1:15: Missing newline after newline escape <\\\\>" + newline, errors.toString());
    st.add("x", "parrt");
    String expected = "";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

    assertEquals(expected, result);
  }

  @Test public void testLineBreakWithScarfedTrailingNewline() throws Exception {
    writeFile(tmpdir, "t.stg", "a(x) ::= <<<\\\\>\r\n>>"); // \r\n removed as trailing whitespace
    ErrorBuffer errors = new ErrorBuffer();
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    ST st = group.getInstanceOf("a");
    assertEquals("t.stg 1:15: Missing newline after newline escape <\\\\>" + newline, errors.toString());
    st.add("x", "parrt");
    String expected = "";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

      "t1(x) ::= \"<x>\"\n" +
      "main(x=\"hello\",t=\"t1\") ::= <<\n" +
      "<(t)(...)>\n" +
      ">>");
    STGroup group = new STGroupFile(tmpdir + "/t.stg");
    ErrorBuffer errors = new ErrorBuffer();
    group.setListener(errors);
    ST st = group.getInstanceOf("main");
    assertEquals("t.stg 2:34: mismatched input '...' expecting RPAREN" + newline, errors.toString());
    assertNull(st);
  }
View Full Code Here

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

    STErrorListener errors = new ErrorBuffer();
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    group.setListener(errors);
    group.load(); // force load
    String expected = "t.stg 2:0: mismatched input 'foo' expecting STRING"+newline+
      "t.stg 2:3: missing EOF at '('"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

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

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

    String templates =
      "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 2:0: missing template at '<EOF>'"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

    String templates =
      "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:11: missing final '}' in {...} anonymous template" +newline+
              "t.stg 1:10: no viable alternative at input '{'"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

        String templates =
            "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:5: no viable alternative at input '::='"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
View Full Code Here

        String templates =
            "foo() ::= \"\nfoo\"\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:11: \\n in string"+newline;
    String result = errors.toString();
    assertEquals(expected, result);
  }
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.