58 lines
1.7 KiB
Java
58 lines
1.7 KiB
Java
package scanner;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
import org.junit.Test;
|
|
|
|
import testutils.TestUtilities;
|
|
|
|
public class LispScannerTextTester {
|
|
|
|
@Test
|
|
public void givenIdentifier_RecordsCorrectText() throws IOException {
|
|
String input = "identifier";
|
|
|
|
assertTokenTextMatches(input, input);
|
|
}
|
|
|
|
@Test
|
|
public void givenNumber_RecordsCorrectText() throws IOException {
|
|
String input = "192837456";
|
|
|
|
assertTokenTextMatches(input, input);
|
|
}
|
|
|
|
@Test
|
|
public void givenString_RecordsCorrectText() throws IOException {
|
|
String input = "\"String!!! \n More... \"";
|
|
|
|
assertTokenTextMatches(input, input);
|
|
}
|
|
|
|
@Test
|
|
public void givenEmptyStream_RecordsCorrectInputStreamName() throws IOException {
|
|
String input = "";
|
|
String expectedInputStreamName = "testInputStream";
|
|
|
|
assertInputFileNameMatches(input, expectedInputStreamName);
|
|
}
|
|
|
|
private void assertTokenTextMatches(String input, String expectedText) throws IOException {
|
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
|
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
|
|
|
|
assertEquals(expectedText, lispScanner.getNextToken().getText());
|
|
}
|
|
|
|
private void assertInputFileNameMatches(String input, String expectedInputFileName) throws IOException {
|
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
|
LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName);
|
|
|
|
assertEquals(expectedInputFileName, lispScanner.getNextToken().getFName());
|
|
}
|
|
|
|
}
|