transcendental-lisp/test/token/TokenFactoryTester.java

73 lines
2.0 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;
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);
}
@Test
public void testEOFTokenCreation() {
assertEquals(Token.Type.EOF, tokenFactory.createEOFToken(testPosition).getType());
}
@Test
public void testLeftParenthesisCreation() {
String text = "(";
assertEquals(Token.Type.LEFT_PAREN, tokenFactory.createToken(text, testPosition).getType());
}
@Test
public void testRightParenthesisCreation() {
String text = ")";
assertEquals(Token.Type.RIGHT_PAREN, tokenFactory.createToken(text, testPosition).getType());
}
@Test
public void testQuoteMarkCreation() {
String text = "'";
assertEquals(Token.Type.QUOTE_MARK, tokenFactory.createToken(text, testPosition).getType());
}
@Test
public void testNumberCreation() {
String text = "987";
assertEquals(Token.Type.NUMBER, tokenFactory.createToken(text, testPosition).getType());
}
@Test
public void testIdentifierCreation() {
String text = "identifier";
assertEquals(Token.Type.IDENTIFIER, tokenFactory.createToken(text, testPosition).getType());
}
@Test
public void testStringCreation() {
String text = "\"string\"";
assertEquals(Token.Type.STRING, tokenFactory.createToken(text, testPosition).getType());
}
@Test(expected = BadCharacterException.class)
public void testBadCharacter() {
String text = "[abc]";
tokenFactory.createToken(text, testPosition);
}
}