Search in sources :

Example 1 with DefaultListener

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);
}
Also used : DefaultListener(org.snt.inmemantlr.listener.DefaultListener) FileNotFoundException(java.io.FileNotFoundException) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 Test (org.junit.jupiter.api.Test)1 GenericParser (org.snt.inmemantlr.GenericParser)1 DefaultListener (org.snt.inmemantlr.listener.DefaultListener)1