package nl.dvberkel.demonstration;

import nl.dvberkel.demonstration.grammar.CalculatorParser;
import org.junit.Test;
import org.parboiled.Parboiled;
import org.parboiled.parserunners.ReportingParseRunner;
import org.parboiled.support.ParseTreeUtils;
import org.parboiled.support.ParsingResult;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class ParboiledTest {
    @Test
    public void shouldCorrectlyParse() {
        CalculatorParser parser = Parboiled.createParser(CalculatorParser.class);
        ParsingResult<?> result = ReportingParseRunner.run(parser.Expression(), "1+2");
        String parseTreeOutput = ParseTreeUtils.printNodeTree(result);

        assertThat(parseTreeOutput, is("[Expression] '1+2'\n  [Term] '1'\n    [Factor] '1'\n      [Number] '1'\n        [0..9] '1'\n    [ZeroOrMore]\n  [ZeroOrMore] '+2'\n    [Sequence] '+2'\n      [[+-]] '+'\n      [Term] '2'\n        [Factor] '2'\n          [Number] '2'\n            [0..9] '2'\n        [ZeroOrMore]\n"));
    }
}


@@ -84,24 +84,49 @@
 atorParser;%0A
+import org.junit.Before;%0A
 import org.j
@@ -430,17 +430,58 @@
 t %7B%0A
+%0A
     
-@Test
+private CalculatorParser parser;%0A%0A    @Before
 %0A   
@@ -497,28 +497,20 @@
 oid 
-shouldCorrectly
+create
 Parse
+r
 () %7B
@@ -518,33 +518,16 @@
         
-CalculatorParser 
 parser =
@@ -575,16 +575,74 @@
 class);%0A
+    %7D%0A%0A    @Test%0A    public void shouldCorrectlyParse() %7B%0A
         
@@ -721,16 +721,17 @@
 %221+2%22);%0A
+%0A
         

create parser before tests