package bfrc.bf;

import static bfrc.lexer.Token.TokenType.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

import org.junit.Test;

import bfrc.lexer.Token;

public class BFLexerTest {

	private BFLexer l = new BFLexer();

	@Test
	public void parseEmptyString() throws IOException {
		try (Reader in = new StringReader("")) {
			l.setInput(in);
			assertNull(l.next());
		}
	}

	@Test
	public void parseJustComment() throws IOException {
		try (Reader in = new StringReader("Hello World!!123")) {
			l.setInput(in);
			assertNull(l.next());
		}
	}

	@Test
	public void parseCommands() throws IOException {
		try (Reader in = new StringReader("+-<>[].,")) {
			l.setInput(in);
			assertEquals(PLUS, l.next().type);
			assertEquals(MINUS, l.next().type);
			assertEquals(LEFT, l.next().type);
			assertEquals(RIGHT, l.next().type);
			assertEquals(BEGIN, l.next().type);
			assertEquals(END, l.next().type);
			assertEquals(OUT, l.next().type);
			assertEquals(IN, l.next().type);
		}
	}

	@Test
	public void trackPositions() throws IOException {
		try (Reader in = new StringReader("+  ++\n\n+\t+")) {
			l.setInput(in);

			assertPosition(1, 1, l.next());
			assertPosition(1, 4, l.next());
			assertPosition(1, 5, l.next());
			assertPosition(3, 1, l.next());
			assertPosition(3, 3, l.next());
		}
	}

	public static void assertPosition(int expectedLine, int expectedOffset,
			Token actual) {
		assertNotNull(actual);
		assertEquals(expectedLine, actual.line);
		assertEquals(expectedOffset, actual.offset);
	}
}

@@ -1257,16 +1257,20 @@
 +%5Cn%5Cn+%5Ct
++%5Cn 
 +%22)) %7B%0A%09
@@ -1455,32 +1455,67 @@
 , 3, l.next());%0A
+%09%09%09assertPosition(4, 2, l.next());%0A
 %09%09%7D%0A%09%7D%0A%0A%09public 

extend test case