use of org.snt.inmemantlr.listener.DefaultListener in project inmemantlr by julianthome.
the class TestGenericParser method testParser.
@Test
public void testParser() {
GenericParser gp = null;
try {
gp = new GenericParser(grammar);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Assertions.assertNotNull(gp);
// Incorrect workflows
boolean thrown = false;
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
Assertions.assertTrue(thrown);
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
Assertions.assertTrue(compile);
// Incorrect workflows
thrown = false;
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
if (e instanceof RedundantCompilationException)
compile = true;
else
compile = false;
}
Assertions.assertTrue(compile);
thrown = false;
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
Assertions.assertFalse(thrown);
thrown = false;
Assertions.assertNotSame(gp.getListener(), null);
// Correct workflow
gp.setListener(new DefaultListener());
Assertions.assertNotNull(gp.getListener());
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
if (e instanceof RedundantCompilationException)
compile = true;
else
compile = false;
}
Assertions.assertTrue(compile);
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
Assertions.assertFalse(thrown);
}
Aggregations