package bool;

import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;

public class LexerTest {
    @Test
    public void test_simple_lex() throws IOException {
        Lexer lexer = new Lexer("foo && bar");
        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("foo", lexer.yytext());

        assertEquals(Parser.TOKEN_AND, lexer.yylex());
        assertEquals("&&", lexer.yytext());

        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("bar", lexer.yytext());
    }
    
    @Test
    public void test_lex_or() throws IOException {
        Lexer lexer = new Lexer("foo || bar");
        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("foo", lexer.yytext());

        assertEquals(Parser.TOKEN_OR, lexer.yylex());
        assertEquals("||", lexer.yytext());

        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("bar", lexer.yytext());
    }
    
    @Test
    public void test_less_simple_lex() throws IOException {
    	Lexer lexer = new Lexer("a && b && (!c || !d)");
        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("a", lexer.yytext());

        assertEquals(Parser.TOKEN_AND, lexer.yylex());
        assertEquals("&&", lexer.yytext());

        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("b", lexer.yytext());
        
        assertEquals(Parser.TOKEN_AND, lexer.yylex());
        assertEquals("&&", lexer.yytext());

        assertEquals(Parser.TOKEN_LPAREN, lexer.yylex());
        assertEquals("(", lexer.yytext());
        
        assertEquals(Parser.TOKEN_NOT, lexer.yylex());
        assertEquals("!", lexer.yytext());
        
        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("c", lexer.yytext());
        
        assertEquals(Parser.TOKEN_OR, lexer.yylex());
        assertEquals("||", lexer.yytext());
        
        assertEquals(Parser.TOKEN_NOT, lexer.yylex());
        assertEquals("!", lexer.yytext());
        
        assertEquals(Parser.TOKEN_VAR, lexer.yylex());
        assertEquals("d", lexer.yytext());
        
        assertEquals(Parser.TOKEN_RPAREN, lexer.yylex());
        assertEquals(")", lexer.yytext());
    }
    
}

@@ -449,427 +449,8 @@
 );%0A%0A
-        assertEquals(Parser.TOKEN_VAR, lexer.yylex());%0A        assertEquals(%22bar%22, lexer.yytext());%0A    %7D%0A    %0A    @Test%0A    public void test_lex_or() throws IOException %7B%0A        Lexer lexer = new Lexer(%22foo %7C%7C bar%22);%0A        assertEquals(Parser.TOKEN_VAR, lexer.yylex());%0A        assertEquals(%22foo%22, lexer.yytext());%0A%0A        assertEquals(Parser.TOKEN_OR, lexer.yylex());%0A        assertEquals(%22%7C%7C%22, lexer.yytext());%0A%0A
     

remove unnecessary test