2016-12-09 16:04:38 -05:00
|
|
|
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");
|
|
|
|
|
2016-12-10 11:57:49 -05:00
|
|
|
assertEquals(expectedText, lispScanner.getNextToken().getText());
|
2016-12-09 16:04:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertInputFileNameMatches(String input, String expectedInputFileName) throws IOException {
|
|
|
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
|
|
|
LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName);
|
|
|
|
|
2016-12-10 11:57:49 -05:00
|
|
|
assertEquals(expectedInputFileName, lispScanner.getNextToken().getFName());
|
2016-12-09 16:04:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|