Search in sources :

Example 1 with MockGrammarSettings

use of org.batfish.grammar.MockGrammarSettings in project batfish by batfish.

the class RecoveryGrammarTest method testParsingRecoveryWithModes.

@Test
public void testParsingRecoveryWithModes() {
    String recoveryText = CommonUtil.readResource("org/batfish/grammar/recovery/recovery_badmode");
    GrammarSettings settings = new MockGrammarSettings(false, 0, 0, 0, false, true, true);
    RecoveryCombinedParser cp = new RecoveryCombinedParser(recoveryText, settings);
    RecoveryContext ctx = cp.parse();
    RecoveryExtractor extractor = new RecoveryExtractor();
    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(extractor, ctx);
    assertThat(extractor.getFirstErrorLine(), equalTo(4));
    assertThat(extractor.getNumErrorNodes(), equalTo(1));
}
Also used : MockGrammarSettings(org.batfish.grammar.MockGrammarSettings) MockGrammarSettings(org.batfish.grammar.MockGrammarSettings) GrammarSettings(org.batfish.grammar.GrammarSettings) RecoveryContext(org.batfish.grammar.recovery.RecoveryParser.RecoveryContext) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Test(org.junit.Test)

Example 2 with MockGrammarSettings

use of org.batfish.grammar.MockGrammarSettings in project batfish by batfish.

the class RecoveryGrammarTest method testParsingRecovery.

@Test
public void testParsingRecovery() {
    String recoveryText = CommonUtil.readResource("org/batfish/grammar/recovery/recovery_text");
    int totalLines = recoveryText.split("\n", -1).length;
    GrammarSettings settings = new MockGrammarSettings(false, 0, 0, 0, false, true, true);
    RecoveryCombinedParser cp = new RecoveryCombinedParser(recoveryText, settings);
    RecoveryContext ctx = cp.parse();
    RecoveryExtractor extractor = new RecoveryExtractor();
    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(extractor, ctx);
    assertThat(extractor.getFirstErrorLine(), equalTo(2));
    assertThat(extractor.getNumBlockStatements(), equalTo(2));
    assertThat(extractor.getNumErrorNodes(), equalTo(15));
    assertThat(extractor.getNumInnerStatements(), equalTo(1));
    assertThat(extractor.getNumSimpleStatements(), equalTo(5));
    assertThat(extractor.getNumStatements(), equalTo(extractor.getNumBlockStatements() + extractor.getNumSimpleStatements()));
    assertThat(extractor.getNumTailWords(), equalTo(5));
    /*
     *  We don't know how many lines were hidden comments, so we only know there should be more
     *  lines than the ones that actually end up in the parse tree.
     */
    assertThat(totalLines, greaterThanOrEqualTo(extractor.getNumBlockStatements() + extractor.getNumInnerStatements() + extractor.getNumSimpleStatements() + extractor.getNumErrorNodes()));
}
Also used : MockGrammarSettings(org.batfish.grammar.MockGrammarSettings) MockGrammarSettings(org.batfish.grammar.MockGrammarSettings) GrammarSettings(org.batfish.grammar.GrammarSettings) RecoveryContext(org.batfish.grammar.recovery.RecoveryParser.RecoveryContext) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Test(org.junit.Test)

Aggregations

ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)2 GrammarSettings (org.batfish.grammar.GrammarSettings)2 MockGrammarSettings (org.batfish.grammar.MockGrammarSettings)2 RecoveryContext (org.batfish.grammar.recovery.RecoveryParser.RecoveryContext)2 Test (org.junit.Test)2