transcendental-lisp/test/token/TokenFactoryTester.java

122 lines
3.0 KiB
Java
Raw Normal View History

package token;
2017-02-11 10:42:07 -05:00
import static error.ErrorManager.Severity.CRITICAL;
import static org.junit.Assert.*;
2017-02-06 13:44:35 -05:00
import org.junit.*;
import file.FilePosition;
import token.TokenFactory.*;
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);
}
private Token createToken(String text) {
return tokenFactory.createToken(text, testPosition);
2016-12-12 14:57:34 -05:00
}
@Test
public void eofTokenCreation() {
assertTrue(tokenFactory.createEofToken(testPosition) instanceof Eof);
2016-12-12 14:57:34 -05:00
}
@Test
public void leftParenthesisCreation() {
String text = "(";
assertTrue(createToken(text) instanceof LeftParenthesis);
}
@Test
public void rightParenthesisCreation() {
String text = ")";
assertTrue(createToken(text) instanceof RightParenthesis);
}
@Test
public void quoteMarkCreation() {
String text = "'";
assertTrue(createToken(text) instanceof QuoteMark);
}
@Test
public void numberCreation() {
String text = "987";
assertTrue(createToken(text) instanceof Number);
}
@Test
public void prefixedNumberCreation() {
String text = "-987";
assertTrue(createToken(text) instanceof Number);
}
@Test
public void identifierCreation() {
String text = "identifier";
assertTrue(createToken(text) instanceof Identifier);
}
@Test
public void prefixedIdentifierCreation() {
String text = "-identifier";
assertTrue(createToken(text) instanceof Identifier);
}
@Test
public void stringCreation() {
String text = "\"string\"";
assertTrue(createToken(text) instanceof QuotedString);
}
@Test(expected = EmptyTokenTextException.class)
public void emptyString_ThrowsException() {
createToken("");
}
@Test
2017-03-11 15:41:07 -05:00
public void emptyTokenTextException_ContainsCorrectAttributes() {
try {
createToken("");
} catch (EmptyTokenTextException e) {
String message = e.getMessage();
assertNotNull(message);
assertTrue(message.length() > 0);
2017-03-11 15:41:07 -05:00
assertEquals(CRITICAL, e.getSeverity());
}
}
@Test(expected = BadCharacterException.class)
public void badCharacter_ThrowsException() {
createToken("[abc]");
}
2017-03-11 15:41:07 -05:00
@Test
public void backTickCreation() {
String text = "`";
assertTrue(createToken(text) instanceof Backquote);
2017-03-11 15:41:07 -05:00
}
@Test
public void commaCreation() {
String text = ",";
assertTrue(createToken(text) instanceof Comma);
}
@Test
public void atSignCreation() {
String text = "@";
assertTrue(createToken(text) instanceof AtSign);
}
}