package notpure.antlr4.macro.processor;

import notpure.antlr4.macro.processor.impl.SimpleLexer;
import notpure.antlr4.macro.processor.impl.SimpleParser;
import notpure.antlr4.macro.processor.model.statement.GenericStatement;
import notpure.antlr4.macro.processor.model.statement.Statement;
import notpure.antlr4.macro.processor.model.token.Token;
import notpure.antlr4.macro.processor.model.token.TokenDefinition;
import notpure.antlr4.macro.processor.util.FileHelper;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static notpure.antlr4.macro.processor.TokenHelper.*;
import static org.junit.Assert.assertEquals;

/**
 * A set of tests for {@link SimpleParser}. These tests rely on {@link SimpleLexerTest} passing.
 */
public final class SimpleParserTest {

    @Test
    public void parserTestOfMacroRuleDefinitions() {
        // Create array, try parse and compare
        List<Token> tokens = new SimpleLexer().tokenize("#HELLO290woRld:'HELLO';").getTokens();
        assertStatement(tokens, "HELLO290woRld:'HELLO'");

        // Create array, try parse and compare
        tokens = new SimpleLexer().tokenize("#HELLO290woRld  :'HELLO';").getTokens();
        assertStatement(tokens, "HELLO290woRld:'HELLO'");

        // Create array, try parse and compare
        tokens = new SimpleLexer().tokenize("#HELLO290woRld  : 'HELLO' ;").getTokens();
        assertStatement(tokens, "HELLO290woRld:'HELLO'");

        // Create array, try parse and compare
        tokens = new SimpleLexer().tokenize("#HELLO290woRld  :'HELLO\r\n|WORLD';").getTokens();
        assertStatement(tokens, "HELLO290woRld:'HELLO|WORLD'");
    }

    @Test
    public void parserTestOfParserRuleDefinitions() {
        // TODO add
    }

    @Test
    public void parserTestOfLexerRuleDefinitions() {
        // TODO add
    }

    @Test
    public void parserTestOfFileHeaderDefinitions() {
        // TODO add
    }

    private static void assertStatement(List<Token> tokens, String value) {
        List<Statement> output = new SimpleParser().parse(tokens).getStatements();;
        assertEquals(1, output.size());
        assertEquals(GenericStatement.class.getSimpleName(), output.get(0).getName());
        assertEquals(value, output.get(0).getValue());
    }
}

@@ -864,173 +864,49 @@
     
-// Create array, try parse and compare%0A        List%3CToken%3E tokens = new SimpleLexer().tokenize(%22#HELLO290woRld:'HELLO';%22).getTokens();%0A        assertStatement(tokens
+assertStatement(%22#HELLO290woRld:'HELLO';%22
 , %22H
@@ -925,33 +925,32 @@
 :'HELLO'%22);%0A
-%0A
         
 // Create ar
@@ -941,163 +941,51 @@
     
-// Create array, try parse and compare%0A        tokens = new SimpleLexer().tokenize(%22#HELLO290woRld  :'HELLO';%22).getTokens();%0A        assertStatement(tokens
+assertStatement(%22#HELLO290woRld  :'HELLO';%22
 , %22H
@@ -1004,33 +1004,32 @@
 :'HELLO'%22);%0A
-%0A
         
 // Create ar
@@ -1020,165 +1020,53 @@
     
-// Create array, try parse and compare%0A        tokens = new SimpleLexer().tokenize(%22#HELLO290woRld  : 'HELLO' ;%22).getTokens();%0A        assertStatement(tokens
+assertStatement(%22#HELLO290woRld  : 'HELLO' ;%22
 , %22H
@@ -1089,25 +1089,24 @@
 LLO'%22);%0A
-%0A
         
 // Creat
@@ -1101,173 +1101,61 @@
     
-// Create array, try parse and compare%0A        tokens = new SimpleLexer().tokenize(%22#HELLO290woRld  :'HELLO%5Cr%5Cn%7CWORLD';%22).getTokens();%0A        assertStatement(tokens
+assertStatement(%22#HELLO290woRld  :'HELLO%5Cr%5Cn%7CWORLD';%22
 , %22H
@@ -1507,43 +1507,139 @@
 ent(
-List%3CToken%3E tokens, String value) %7B
+String input, String outputValue) %7B%0A        // Generate%0A        List%3CToken%3E tokens = new SimpleLexer().tokenize(input).getTokens();
 %0A   
@@ -1717,17 +1717,35 @@
 ments();
-;
+%0A%0A        // Assert
 %0A       
@@ -1885,17 +1885,23 @@
 tEquals(
-v
+outputV
 alue, ou

Refactor parser test