2016-12-09 16:04:38 -05:00
|
|
|
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() {
|
2016-12-09 16:04:38 -05:00
|
|
|
String input = "identifier";
|
|
|
|
|
|
|
|
assertTokenTextMatches(input, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2016-12-11 11:23:44 -05:00
|
|
|
public void givenNumber_RecordsCorrectText() {
|
2016-12-09 16:04:38 -05:00
|
|
|
String input = "192837456";
|
|
|
|
|
|
|
|
assertTokenTextMatches(input, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2016-12-11 11:23:44 -05:00
|
|
|
public void givenString_RecordsCorrectText() {
|
2016-12-09 16:04:38 -05:00
|
|
|
String input = "\"String!!! \n More... \"";
|
|
|
|
|
|
|
|
assertTokenTextMatches(input, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2016-12-11 15:09:48 -05:00
|
|
|
public void givenEmptyStream_RecordsCorrectFileName() {
|
2016-12-09 16:04:38 -05:00
|
|
|
String input = "";
|
2016-12-11 15:09:48 -05:00
|
|
|
String expectedFileName = "testFileName";
|
2016-12-09 16:04:38 -05:00
|
|
|
|
2016-12-11 15:09:48 -05:00
|
|
|
assertInputFileNameMatches(input, expectedFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void givenNumberFollowedByComment_RecordsCorrectText() {
|
|
|
|
String input = "192837456;comment";
|
|
|
|
String expected = "192837456";
|
|
|
|
|
|
|
|
assertTokenTextMatches(input, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void givenIdentifiersWithCommentBetween_RecordsCorrectText() {
|
|
|
|
String input = "abc123;comment\nabc222";
|
|
|
|
String expected = "abc123";
|
|
|
|
|
|
|
|
assertTokenTextMatches(input, expected);
|
2016-12-09 16:04:38 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 11:23:44 -05:00
|
|
|
private void assertTokenTextMatches(String input, String expectedText) {
|
2016-12-09 16:04:38 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-11 11:23:44 -05:00
|
|
|
private void assertInputFileNameMatches(String input, String expectedInputFileName) {
|
2016-12-09 16:04:38 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|