use of org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString in project antlr4 by antlr.
the class TestCompositeGrammars method testHeadersPropogatedCorrectlyToImportedGrammars.
@Test
public void testHeadersPropogatedCorrectlyToImportedGrammars() throws Exception {
String slave = "parser grammar S;\n" + "a : B {System.out.print(\"S.a\");} ;\n";
BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave);
String master = "grammar M;\n" + "import S;\n" + "@header{package mypackage;}\n" + "s : a ;\n" + // defines B from inherited token space
"B : 'b' ;" + "WS : (' '|'\\n') -> skip ;\n";
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", master, false);
// should be ok
int expecting = 0;
assertEquals(expecting, equeue.errors.size());
}
use of org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString in project antlr4 by antlr.
the class TestCompositeGrammars method testTokensFileInOutputDirAndImportFileInSubdir.
@Test
public void testTokensFileInOutputDirAndImportFileInSubdir() throws Exception {
String slave = "parser grammar S;\n" + "a : B {System.out.println(\"S.a\");} ;\n";
BaseRuntimeTest.mkdir(tmpdir);
String subdir = tmpdir + "/sub";
BaseRuntimeTest.mkdir(subdir);
writeFile(subdir, "S.g4", slave);
String parser = "parser grammar MParser;\n" + "import S;\n" + "options {tokenVocab=MLexer;}\n" + "s : a ;\n";
writeFile(tmpdir, "MParser.g4", parser);
String lexer = "lexer grammar MLexer;\n" + // defines B from inherited token space
"B : 'b' ;" + "WS : (' '|'\\n') -> skip ;\n";
writeFile(tmpdir, "MLexer.g4", lexer);
String outdir = tmpdir + "/out";
BaseRuntimeTest.mkdir(outdir);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "MLexer.g4", false, "-o", outdir);
assertEquals(0, equeue.size());
equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "MParser.g4", false, "-o", outdir, "-lib", subdir);
assertEquals(0, equeue.size());
}
use of org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString in project antlr4 by antlr.
the class TestCompositeGrammars method testImportFileNotSearchedForInOutputDir.
@Test
public void testImportFileNotSearchedForInOutputDir() throws Exception {
String slave = "parser grammar S;\n" + "a : B {System.out.println(\"S.a\");} ;\n";
BaseRuntimeTest.mkdir(tmpdir);
String outdir = tmpdir + "/out";
BaseRuntimeTest.mkdir(outdir);
writeFile(outdir, "S.g4", slave);
String master = "grammar M;\n" + "import S;\n" + "s : a ;\n" + // defines B from inherited token space
"B : 'b' ;" + "WS : (' '|'\\n') -> skip ;\n";
writeFile(tmpdir, "M.g4", master);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-o", outdir);
assertEquals(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, equeue.errors.get(0).getErrorType());
}
use of org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString in project antlr4 by antlr.
the class TestCompositeGrammars method testImportFileLocationInSubdir.
@Test
public void testImportFileLocationInSubdir() throws Exception {
String slave = "parser grammar S;\n" + "a : B {System.out.println(\"S.a\");} ;\n";
BaseRuntimeTest.mkdir(tmpdir);
String subdir = tmpdir + "/sub";
BaseRuntimeTest.mkdir(subdir);
writeFile(subdir, "S.g4", slave);
String master = "grammar M;\n" + "import S;\n" + "s : a ;\n" + // defines B from inherited token space
"B : 'b' ;" + "WS : (' '|'\\n') -> skip ;\n";
writeFile(tmpdir, "M.g4", master);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", subdir);
assertEquals(0, equeue.size());
}
use of org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString in project antlr4 by antlr.
the class TestCompositeGrammars method testErrorInImportedGetsRightFilename.
@Test
public void testErrorInImportedGetsRightFilename() throws Exception {
String slave = "parser grammar S;\n" + "a : 'a' | c;\n";
BaseRuntimeTest.mkdir(tmpdir);
writeFile(tmpdir, "S.g4", slave);
String master = "grammar M;\n" + "import S;\n";
writeFile(tmpdir, "M.g4", master);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", tmpdir);
ANTLRMessage msg = equeue.errors.get(0);
assertEquals(ErrorType.UNDEFINED_RULE_REF, msg.getErrorType());
assertEquals("c", msg.getArgs()[0]);
assertEquals(2, msg.line);
assertEquals(10, msg.charPosition);
assertEquals("S.g4", new File(msg.fileName).getName());
}
Aggregations