71 lines
1.9 KiB
Java
71 lines
1.9 KiB
Java
package constructs;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import file.FilePosition;
|
|
|
|
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 = TokenFactory.BadCharacterException.class)
|
|
public void testBadCharacter() {
|
|
String text = "[abc]";
|
|
tokenFactory.createToken(text, testPosition);
|
|
}
|
|
|
|
}
|