2016-12-12 10:15:20 -05:00
|
|
|
package token;
|
2016-12-11 15:09:48 -05:00
|
|
|
|
2016-12-13 10:41:14 -05:00
|
|
|
import static org.junit.Assert.assertTrue;
|
2016-12-11 15:09:48 -05:00
|
|
|
|
2017-02-06 13:44:35 -05:00
|
|
|
import org.junit.*;
|
2016-12-11 15:09:48 -05:00
|
|
|
|
|
|
|
import file.FilePosition;
|
2016-12-12 10:15:20 -05:00
|
|
|
import token.TokenFactory.BadCharacterException;
|
|
|
|
|
2016-12-11 15:09:48 -05:00
|
|
|
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-13 10:41:14 -05:00
|
|
|
private Token createToken(String text) {
|
|
|
|
return tokenFactory.createToken(text, testPosition);
|
2016-12-12 14:57:34 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 15:09:48 -05:00
|
|
|
@Test
|
|
|
|
public void testEOFTokenCreation() {
|
2016-12-13 10:41:14 -05:00
|
|
|
assertTrue(tokenFactory.createEOFToken(testPosition) instanceof Eof);
|
2016-12-12 14:57:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = RuntimeException.class)
|
|
|
|
public void testEmptyString_ThrowsException() {
|
|
|
|
String text = "";
|
2016-12-13 10:41:14 -05:00
|
|
|
createToken(text);
|
2016-12-11 15:09:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLeftParenthesisCreation() {
|
|
|
|
String text = "(";
|
2016-12-13 10:41:14 -05:00
|
|
|
assertTrue(createToken(text) instanceof LeftParenthesis);
|
2016-12-11 15:09:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testRightParenthesisCreation() {
|
|
|
|
String text = ")";
|
2016-12-13 10:41:14 -05:00
|
|
|
assertTrue(createToken(text) instanceof RightParenthesis);
|
2016-12-11 15:09:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testQuoteMarkCreation() {
|
|
|
|
String text = "'";
|
2016-12-13 10:41:14 -05:00
|
|
|
assertTrue(createToken(text) instanceof QuoteMark);
|
2016-12-11 15:09:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testNumberCreation() {
|
|
|
|
String text = "987";
|
2016-12-13 10:41:14 -05:00
|
|
|
assertTrue(createToken(text) instanceof Number);
|
2016-12-11 15:09:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testIdentifierCreation() {
|
|
|
|
String text = "identifier";
|
2016-12-13 10:41:14 -05:00
|
|
|
assertTrue(createToken(text) instanceof Identifier);
|
2016-12-11 15:09:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testStringCreation() {
|
|
|
|
String text = "\"string\"";
|
2016-12-13 10:41:14 -05:00
|
|
|
assertTrue(createToken(text) instanceof QuotedString);
|
2016-12-11 15:09:48 -05:00
|
|
|
}
|
|
|
|
|
2016-12-12 10:15:20 -05:00
|
|
|
@Test(expected = BadCharacterException.class)
|
2016-12-11 15:09:48 -05:00
|
|
|
public void testBadCharacter() {
|
|
|
|
String text = "[abc]";
|
|
|
|
tokenFactory.createToken(text, testPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|