transcendental-lisp/test/scanner/LispScannerTextTester.java

57 lines
1.6 KiB
Java
Raw Normal View History

package scanner;
import static org.junit.Assert.assertEquals;
import java.io.InputStream;
import org.junit.Test;
import testutils.TestUtilities;
public class LispScannerTextTester {
@Test
2016-12-11 11:23:44 -05:00
public void givenIdentifier_RecordsCorrectText() {
String input = "identifier";
assertTokenTextMatches(input, input);
}
@Test
2016-12-11 11:23:44 -05:00
public void givenNumber_RecordsCorrectText() {
String input = "192837456";
assertTokenTextMatches(input, input);
}
@Test
2016-12-11 11:23:44 -05:00
public void givenString_RecordsCorrectText() {
String input = "\"String!!! \n More... \"";
assertTokenTextMatches(input, input);
}
@Test
2016-12-11 11:23:44 -05:00
public void givenEmptyStream_RecordsCorrectInputStreamName() {
String input = "";
String expectedInputStreamName = "testInputStream";
assertInputFileNameMatches(input, expectedInputStreamName);
}
2016-12-11 11:23:44 -05:00
private void assertTokenTextMatches(String input, String expectedText) {
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
assertEquals(expectedText, lispScanner.getNextToken().getText());
}
2016-12-11 11:23:44 -05:00
private void assertInputFileNameMatches(String input, String expectedInputFileName) {
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName);
assertEquals(expectedInputFileName, lispScanner.getNextToken().getFName());
}
}