transcendental-lisp/test/token/TokenFactoryTester.java

83 lines
2.1 KiB
Java
Raw Normal View History

package token;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import file.FilePosition;
2016-12-12 14:57:34 -05:00
import token.Token.Type;
import token.TokenFactory.BadCharacterException;
public class TokenFactoryTester {
private TokenFactory tokenFactory;
private FilePosition testPosition;
@Before
public void setUp() throws Exception {
tokenFactory = new TokenFactoryImpl();
testPosition = new FilePosition("testFile");
testPosition.setLineNumber(0);
testPosition.setColumnNumber(0);
}
2016-12-12 14:57:34 -05:00
private Type getCreatedTokenType(String text) {
return tokenFactory.createToken(text, testPosition).getType();
}
@Test
public void testEOFTokenCreation() {
2016-12-12 14:57:34 -05:00
assertEquals(Type.EOF, tokenFactory.createEOFToken(testPosition).getType());
}
@Test(expected = RuntimeException.class)
public void testEmptyString_ThrowsException() {
String text = "";
tokenFactory.createToken(text, testPosition);
}
@Test
public void testLeftParenthesisCreation() {
String text = "(";
2016-12-12 14:57:34 -05:00
assertEquals(Type.LEFT_PAREN, getCreatedTokenType(text));
}
@Test
public void testRightParenthesisCreation() {
String text = ")";
2016-12-12 14:57:34 -05:00
assertEquals(Type.RIGHT_PAREN, getCreatedTokenType(text));
}
@Test
public void testQuoteMarkCreation() {
String text = "'";
2016-12-12 14:57:34 -05:00
assertEquals(Type.QUOTE_MARK, getCreatedTokenType(text));
}
@Test
public void testNumberCreation() {
String text = "987";
2016-12-12 14:57:34 -05:00
assertEquals(Type.NUMBER, getCreatedTokenType(text));
}
@Test
public void testIdentifierCreation() {
String text = "identifier";
2016-12-12 14:57:34 -05:00
assertEquals(Type.IDENTIFIER, getCreatedTokenType(text));
}
@Test
public void testStringCreation() {
String text = "\"string\"";
2016-12-12 14:57:34 -05:00
assertEquals(Type.STRING, getCreatedTokenType(text));
}
@Test(expected = BadCharacterException.class)
public void testBadCharacter() {
String text = "[abc]";
tokenFactory.createToken(text, testPosition);
}
}