Converted over to runtime exceptions
This commit is contained in:
parent
abdd89737f
commit
f50b07842c
|
@ -1,5 +1,8 @@
|
||||||
package constructs;
|
package constructs;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import error.LispException;
|
||||||
import file.FilePosition;
|
import file.FilePosition;
|
||||||
|
|
||||||
public interface TokenFactory {
|
public interface TokenFactory {
|
||||||
|
@ -8,4 +11,28 @@ public interface TokenFactory {
|
||||||
|
|
||||||
Token createEOFToken(FilePosition position);
|
Token createEOFToken(FilePosition position);
|
||||||
|
|
||||||
|
public static class BadCharacterException extends LispException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String text;
|
||||||
|
private FilePosition position;
|
||||||
|
|
||||||
|
public BadCharacterException(String text, FilePosition position) {
|
||||||
|
this.text = text;
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeverity() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return MessageFormat.format("illegal character >>{0}<< - line {1}, column {2}", text,
|
||||||
|
position.getLineNumber(), position.getColumnNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class TokenFactoryImpl implements TokenFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException("oh no!");
|
throw new BadCharacterException(text, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token createEOFToken(FilePosition position) {
|
public Token createEOFToken(FilePosition position) {
|
||||||
|
|
|
@ -14,6 +14,10 @@ public class ErrorManager {
|
||||||
public static final String ANSI_YELLOW = "\u001B[33m";
|
public static final String ANSI_YELLOW = "\u001B[33m";
|
||||||
public static final String ANSI_PURPLE = "\u001B[35m";
|
public static final String ANSI_PURPLE = "\u001B[35m";
|
||||||
|
|
||||||
|
public static void generateError(LispException lispException) {
|
||||||
|
generateError(lispException.getMessage(), lispException.getSeverity());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints out the specified error message to the console and decides whether
|
* Prints out the specified error message to the console and decides whether
|
||||||
* or not to terminate the currently running program.
|
* or not to terminate the currently running program.
|
||||||
|
|
|
@ -2,60 +2,87 @@ package scanner;
|
||||||
|
|
||||||
import static util.Characters.*;
|
import static util.Characters.*;
|
||||||
|
|
||||||
import java.io.FilterInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes Lisp comments from an input stream.
|
* Removes Lisp comments from an input stream.
|
||||||
*/
|
*/
|
||||||
public class LispFilterInputStream extends FilterInputStream {
|
public class LispFilterInputStream implements LispInputStream {
|
||||||
|
|
||||||
|
private InputStream underlyingInputStream;
|
||||||
private boolean isInQuotedString;
|
private boolean isInQuotedString;
|
||||||
|
private boolean rereadLastCharacter;
|
||||||
private int previousCharacter;
|
private int previousCharacter;
|
||||||
private int nextCharacter;
|
private int currentCharacter;
|
||||||
|
|
||||||
public LispFilterInputStream(InputStream underlyingInputStream) {
|
public LispFilterInputStream(InputStream underlyingInputStream) {
|
||||||
super(underlyingInputStream);
|
this.underlyingInputStream = underlyingInputStream;
|
||||||
|
this.isInQuotedString = false;
|
||||||
isInQuotedString = false;
|
this.rereadLastCharacter = false;
|
||||||
previousCharacter = 0;
|
this.previousCharacter = 0;
|
||||||
nextCharacter = 0;
|
this.currentCharacter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() {
|
||||||
|
try {
|
||||||
|
return readWithIOException();
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
throw new UncheckedIOException(ioException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int readWithIOException() throws IOException {
|
||||||
|
if (!rereadLastCharacter)
|
||||||
|
return readFromUnderlyingInputStream();
|
||||||
|
|
||||||
|
rereadLastCharacter = false;
|
||||||
|
|
||||||
|
return currentCharacter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int readFromUnderlyingInputStream() throws IOException {
|
||||||
readNextCharacter();
|
readNextCharacter();
|
||||||
|
|
||||||
if (haveEnteredComment())
|
if (haveEnteredComment())
|
||||||
consumeAllBytesInComment();
|
consumeAllBytesInComment();
|
||||||
|
|
||||||
return nextCharacter;
|
return currentCharacter;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readNextCharacter() throws IOException {
|
private void readNextCharacter() throws IOException {
|
||||||
previousCharacter = nextCharacter;
|
previousCharacter = currentCharacter;
|
||||||
nextCharacter = super.read();
|
currentCharacter = underlyingInputStream.read();
|
||||||
|
|
||||||
if (haveEncounteredStringBoundary())
|
if (haveEncounteredStringBoundary())
|
||||||
isInQuotedString = !isInQuotedString;
|
isInQuotedString = !isInQuotedString;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean haveEncounteredStringBoundary() {
|
private boolean haveEncounteredStringBoundary() {
|
||||||
return (previousCharacter != BACKSLASH) && (nextCharacter == DOUBLE_QUOTE);
|
return (previousCharacter != BACKSLASH) && (currentCharacter == DOUBLE_QUOTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean haveEnteredComment() {
|
private boolean haveEnteredComment() {
|
||||||
return (nextCharacter == SEMICOLON) && (!isInQuotedString);
|
return (currentCharacter == SEMICOLON) && (!isInQuotedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void consumeAllBytesInComment() throws IOException {
|
private void consumeAllBytesInComment() throws IOException {
|
||||||
while (stillInComment())
|
while (stillInComment())
|
||||||
nextCharacter = super.read();
|
currentCharacter = underlyingInputStream.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean stillInComment() {
|
private boolean stillInComment() {
|
||||||
return (nextCharacter != NEWLINE) && (nextCharacter != EOF);
|
return (currentCharacter != NEWLINE) && (currentCharacter != EOF);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unreadLastCharacter() {
|
||||||
|
if (rereadLastCharacter)
|
||||||
|
throw new MaximumUnreadsExceededException();
|
||||||
|
|
||||||
|
this.rereadLastCharacter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package scanner;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import error.ErrorManager;
|
||||||
|
import error.LispException;
|
||||||
|
|
||||||
|
public interface LispInputStream {
|
||||||
|
|
||||||
|
int read();
|
||||||
|
|
||||||
|
void unreadLastCharacter();
|
||||||
|
|
||||||
|
public static class MaximumUnreadsExceededException extends LispException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeverity() {
|
||||||
|
return ErrorManager.CRITICAL_LEVEL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class UncheckedIOException extends LispException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IOException ioException;
|
||||||
|
|
||||||
|
public UncheckedIOException(IOException ioException) {
|
||||||
|
this.ioException = ioException;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeverity() {
|
||||||
|
return ErrorManager.CRITICAL_LEVEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return ioException.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,8 +2,6 @@ package scanner;
|
||||||
|
|
||||||
import static util.Characters.*;
|
import static util.Characters.*;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -21,17 +19,17 @@ import util.Characters;
|
||||||
*/
|
*/
|
||||||
public class LispScanner {
|
public class LispScanner {
|
||||||
|
|
||||||
private InputStream inputStream;
|
private LispInputStream inputStream;
|
||||||
private FilePositionTracker positionTracker;
|
private FilePositionTracker positionTracker;
|
||||||
private TokenFactory tokenFactory;
|
private TokenFactory tokenFactory;
|
||||||
|
|
||||||
public LispScanner(InputStream in, String fileName) {
|
public LispScanner(InputStream in, String fileName) {
|
||||||
this.inputStream = new LispFilterInputStream(new BufferedInputStream(in));
|
this.inputStream = new LispFilterInputStream(in);
|
||||||
this.positionTracker = new FilePositionTracker(fileName);
|
this.positionTracker = new FilePositionTracker(fileName);
|
||||||
this.tokenFactory = new TokenFactoryImpl();
|
this.tokenFactory = new TokenFactoryImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token getNextToken() throws IOException {
|
public Token getNextToken() {
|
||||||
for (int c = inputStream.read(); c != EOF; c = inputStream.read()) {
|
for (int c = inputStream.read(); c != EOF; c = inputStream.read()) {
|
||||||
char currentCharacter = (char) c;
|
char currentCharacter = (char) c;
|
||||||
positionTracker.incrementColumn();
|
positionTracker.incrementColumn();
|
||||||
|
@ -45,14 +43,14 @@ public class LispScanner {
|
||||||
return tokenFactory.createEOFToken(positionTracker.getCurrentPosition());
|
return tokenFactory.createEOFToken(positionTracker.getCurrentPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Token createTokenFromCharacter(char c) throws IOException {
|
private Token createTokenFromCharacter(char c) {
|
||||||
FilePosition currentPosition = positionTracker.getCurrentPosition();
|
FilePosition currentPosition = positionTracker.getCurrentPosition();
|
||||||
String tokenText = retrieveTokenText(c);
|
String tokenText = retrieveTokenText(c);
|
||||||
|
|
||||||
return tokenFactory.createToken(tokenText, currentPosition);
|
return tokenFactory.createToken(tokenText, currentPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String retrieveTokenText(char firstCharacter) throws IOException {
|
private String retrieveTokenText(char firstCharacter) {
|
||||||
String tokenText = "" + firstCharacter;
|
String tokenText = "" + firstCharacter;
|
||||||
|
|
||||||
if (firstCharacter == DOUBLE_QUOTE)
|
if (firstCharacter == DOUBLE_QUOTE)
|
||||||
|
@ -65,20 +63,20 @@ public class LispScanner {
|
||||||
return tokenText;
|
return tokenText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String retrieveStringTokenText(char firstDoubleQuote) throws IOException {
|
private String retrieveStringTokenText(char firstDoubleQuote) {
|
||||||
ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstDoubleQuote,
|
ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstDoubleQuote,
|
||||||
Characters::isLegalStringCharacter);
|
Characters::isLegalStringCharacter);
|
||||||
|
|
||||||
return retriever.retrieveToken();
|
return retriever.retrieveToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String retrieveNumberTokenText(char firstDigit) throws IOException {
|
private String retrieveNumberTokenText(char firstDigit) {
|
||||||
ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstDigit, Character::isDigit);
|
ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstDigit, Character::isDigit);
|
||||||
|
|
||||||
return retriever.retrieveToken();
|
return retriever.retrieveToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String retrieveIdentifierTokenText(char firstCharacter) throws IOException {
|
private String retrieveIdentifierTokenText(char firstCharacter) {
|
||||||
ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstCharacter,
|
ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstCharacter,
|
||||||
Characters::isLegalIdentifierCharacter);
|
Characters::isLegalIdentifierCharacter);
|
||||||
|
|
||||||
|
@ -103,15 +101,14 @@ public class LispScanner {
|
||||||
this.previousCharacter = firstCharacter;
|
this.previousCharacter = firstCharacter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String retrieveToken() throws IOException {
|
public String retrieveToken() {
|
||||||
text.append(firstCharacter);
|
text.append(firstCharacter);
|
||||||
inputStream.mark(1);
|
|
||||||
|
|
||||||
for (int c = inputStream.read(); c != EOF; c = inputStream.read()) {
|
for (int c = inputStream.read(); c != EOF; c = inputStream.read()) {
|
||||||
currentCharacter = (char) c;
|
currentCharacter = (char) c;
|
||||||
|
|
||||||
if (!isPartOfToken.apply(currentCharacter)) {
|
if (!isPartOfToken.apply(currentCharacter)) {
|
||||||
inputStream.reset();
|
inputStream.unreadLastCharacter();
|
||||||
|
|
||||||
return text.toString();
|
return text.toString();
|
||||||
}
|
}
|
||||||
|
@ -130,7 +127,6 @@ public class LispScanner {
|
||||||
private void addCharacterToToken() {
|
private void addCharacterToToken() {
|
||||||
text.append(currentCharacter);
|
text.append(currentCharacter);
|
||||||
positionTracker.incrementColumn();
|
positionTracker.incrementColumn();
|
||||||
inputStream.mark(1);
|
|
||||||
|
|
||||||
if (currentCharacter == NEWLINE)
|
if (currentCharacter == NEWLINE)
|
||||||
positionTracker.incrementLine();
|
positionTracker.incrementLine();
|
||||||
|
|
|
@ -2,7 +2,6 @@ package scanner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -20,21 +19,21 @@ public class LispFilterInputStreamTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noBytesIn_noBytesOut() throws IOException {
|
public void noBytesIn_noBytesOut() {
|
||||||
String input = "";
|
String input = "";
|
||||||
|
|
||||||
assertEquals(input, getLispFilterInputStreamResult(input));
|
assertEquals(input, getLispFilterInputStreamResult(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void oneCharacter_notRemoved() throws IOException {
|
public void oneCharacter_notRemoved() {
|
||||||
String input = "x";
|
String input = "x";
|
||||||
|
|
||||||
assertEquals(input, getLispFilterInputStreamResult(input));
|
assertEquals(input, getLispFilterInputStreamResult(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allNonCommentCharacters_notRemoved() throws IOException {
|
public void allNonCommentCharacters_notRemoved() {
|
||||||
String input = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
String input = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
+ "`1234567890-=~!@#$%^&*()_+[]\\',./{}|:\"<>?";
|
+ "`1234567890-=~!@#$%^&*()_+[]\\',./{}|:\"<>?";
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ public class LispFilterInputStreamTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void oneComment_Removed() throws IOException {
|
public void oneComment_Removed() {
|
||||||
String input = ";comment";
|
String input = ";comment";
|
||||||
String expectedResult = "";
|
String expectedResult = "";
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class LispFilterInputStreamTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleComments_Removed() throws IOException {
|
public void multipleComments_Removed() {
|
||||||
String input = ";comment1\n;comment2\n;comment3";
|
String input = ";comment1\n;comment2\n;comment3";
|
||||||
String expectedResult = "\n\n";
|
String expectedResult = "\n\n";
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ public class LispFilterInputStreamTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nil_NotRemoved() throws IOException {
|
public void nil_NotRemoved() {
|
||||||
String input = "()";
|
String input = "()";
|
||||||
String expectedResult = "()";
|
String expectedResult = "()";
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ public class LispFilterInputStreamTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void interiorComment_Removed() throws IOException {
|
public void interiorComment_Removed() {
|
||||||
String input = "(;this is a comment\n)";
|
String input = "(;this is a comment\n)";
|
||||||
String expectedResult = "(\n)";
|
String expectedResult = "(\n)";
|
||||||
|
|
||||||
|
@ -74,42 +73,109 @@ public class LispFilterInputStreamTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commentInString_NotRemoved() throws IOException {
|
public void commentInString_NotRemoved() {
|
||||||
String input = "\"string;this should remain\"";
|
String input = "\"string;this should remain\"";
|
||||||
|
|
||||||
assertEquals(input, getLispFilterInputStreamResult(input));
|
assertEquals(input, getLispFilterInputStreamResult(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commentInStringWithNewline_NotRemoved() throws IOException {
|
public void commentInStringWithNewline_NotRemoved() {
|
||||||
String input = "\"string;this should\n remain\"";
|
String input = "\"string;this should\n remain\"";
|
||||||
|
|
||||||
assertEquals(input, getLispFilterInputStreamResult(input));
|
assertEquals(input, getLispFilterInputStreamResult(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commentInStringWithEscapedDoubleQuote_NotRemoved() throws IOException {
|
public void commentInStringWithEscapedDoubleQuote_NotRemoved() {
|
||||||
String input = "\"string \\\" ;this should remain\"";
|
String input = "\"string \\\" ;this should remain\"";
|
||||||
|
|
||||||
assertEquals(input, getLispFilterInputStreamResult(input));
|
assertEquals(input, getLispFilterInputStreamResult(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void manyCommentsWithStatements_OnlyCommentsRemoved() throws IOException {
|
public void manyCommentsWithStatements_OnlyCommentsRemoved() {
|
||||||
String input = ";first comment \n '(1 2 3) \n ;second comment \n (defun add1 (x) (+ x 1)) ;third comment";
|
String input = ";first comment \n '(1 2 3) \n ;second comment \n (defun add1 (x) (+ x 1)) ;third comment";
|
||||||
String expectedResult = "\n '(1 2 3) \n \n (defun add1 (x) (+ x 1)) ";
|
String expectedResult = "\n '(1 2 3) \n \n (defun add1 (x) (+ x 1)) ";
|
||||||
|
|
||||||
assertEquals(expectedResult, getLispFilterInputStreamResult(input));
|
assertEquals(expectedResult, getLispFilterInputStreamResult(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLispFilterInputStreamResult(String inputString) throws IOException {
|
@Test
|
||||||
InputStream stringInputStream = TestUtilities.createInputStreamFromString(inputString);
|
public void unreadOneCharacter_ReturnsSameCharacter() {
|
||||||
LispFilterInputStream lispFilterInputStream = new LispFilterInputStream(stringInputStream);
|
String input = "abc";
|
||||||
|
char expectedResult = 'a';
|
||||||
|
LispInputStream lispInputStream = createLispInputStream(input);
|
||||||
|
|
||||||
return readInputStreamIntoString(lispFilterInputStream);
|
lispInputStream.read();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
|
||||||
|
assertEquals(expectedResult, lispInputStream.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readInputStreamIntoString(InputStream inputStream) throws IOException {
|
@Test
|
||||||
|
public void unreadAndRereadSameCharacterMultipleTimes_ReturnsSameCharacter() {
|
||||||
|
String input = "abc";
|
||||||
|
char expectedResult = 'a';
|
||||||
|
LispInputStream lispInputStream = createLispInputStream(input);
|
||||||
|
|
||||||
|
lispInputStream.read();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
lispInputStream.read();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
lispInputStream.read();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
|
||||||
|
assertEquals(expectedResult, lispInputStream.read());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unreadOneCharacterAndRereadIt_ReturnsNextCharacterOnNextRead() {
|
||||||
|
String input = "abc";
|
||||||
|
char expectedResult = 'b';
|
||||||
|
LispInputStream lispInputStream = createLispInputStream(input);
|
||||||
|
|
||||||
|
lispInputStream.read();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
lispInputStream.read();
|
||||||
|
|
||||||
|
assertEquals(expectedResult, lispInputStream.read());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = LispInputStream.MaximumUnreadsExceededException.class)
|
||||||
|
public void callUnreadMultipleTimes_ThrowsException() {
|
||||||
|
String input = "abc";
|
||||||
|
LispInputStream lispInputStream = createLispInputStream(input);
|
||||||
|
|
||||||
|
lispInputStream.read();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unreadNewlineInStringAfterComment_ReturnsNewline() {
|
||||||
|
String input = "a;123\n";
|
||||||
|
char expectedResult = '\n';
|
||||||
|
LispInputStream lispInputStream = createLispInputStream(input);
|
||||||
|
|
||||||
|
lispInputStream.read();
|
||||||
|
lispInputStream.read();
|
||||||
|
lispInputStream.unreadLastCharacter();
|
||||||
|
|
||||||
|
assertEquals(expectedResult, lispInputStream.read());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLispFilterInputStreamResult(String inputString) {
|
||||||
|
return readInputStreamIntoString(createLispInputStream(inputString));
|
||||||
|
}
|
||||||
|
|
||||||
|
private LispInputStream createLispInputStream(String inputString) {
|
||||||
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(inputString);
|
||||||
|
|
||||||
|
return new LispFilterInputStream(stringInputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readInputStreamIntoString(LispInputStream inputStream) {
|
||||||
int c = inputStream.read();
|
int c = inputStream.read();
|
||||||
|
|
||||||
while (c != -1) {
|
while (c != -1) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package scanner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -18,7 +17,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNothing_RecordsCorrectEOFLocation() throws IOException {
|
public void givenNothing_RecordsCorrectEOFLocation() {
|
||||||
String input = "";
|
String input = "";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 0) };
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 0) };
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSimpleString_RecordsCorrectLocation() throws IOException {
|
public void givenSimpleString_RecordsCorrectLocation() {
|
||||||
String input = "\"string\"";
|
String input = "\"string\"";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenStringWithTrailingSpace_RecordsCorrectLocation() throws IOException {
|
public void givenStringWithTrailingSpace_RecordsCorrectLocation() {
|
||||||
String input = "\"string\" ";
|
String input = "\"string\" ";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenIdentifier_RecordsCorrectLocation() throws IOException {
|
public void givenIdentifier_RecordsCorrectLocation() {
|
||||||
String input = "identifier";
|
String input = "identifier";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenIdentifierWithTrailingSpace_RecordsCorrectLocation() throws IOException {
|
public void givenIdentifierWithTrailingSpace_RecordsCorrectLocation() {
|
||||||
String input = "identifier ";
|
String input = "identifier ";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNumber_RecordsCorrectLocation() throws IOException {
|
public void givenNumber_RecordsCorrectLocation() {
|
||||||
String input = "123456789";
|
String input = "123456789";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
||||||
|
|
||||||
|
@ -66,16 +65,15 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNumberWithTrailingSpace_RecordsCorrectLocation() throws IOException {
|
public void givenNumberWithTrailingSpace_RecordsCorrectLocation() {
|
||||||
String input = "123456789 ";
|
String input = "123456789 ";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) };
|
||||||
|
|
||||||
assertTokenLineAndColumnsMatch(input, expectedLinesAndColumns);
|
assertTokenLineAndColumnsMatch(input, expectedLinesAndColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenMultipleStrings_RecordsCorrectLocations() throws IOException {
|
public void givenMultipleStrings_RecordsCorrectLocations() {
|
||||||
String input = "\"string1\" \n \"string2 \n with newline\" \n \"string3\"";
|
String input = "\"string1\" \n \"string2 \n with newline\" \n \"string3\"";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1), LineColumn.create(2, 2),
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1), LineColumn.create(2, 2),
|
||||||
LineColumn.create(4, 3) };
|
LineColumn.create(4, 3) };
|
||||||
|
@ -84,7 +82,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenQuotedList_RecordsCorrectLocations() throws IOException {
|
public void givenQuotedList_RecordsCorrectLocations() {
|
||||||
String input = "'(1 2 3 4 5)";
|
String input = "'(1 2 3 4 5)";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1), LineColumn.create(1, 2),
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1), LineColumn.create(1, 2),
|
||||||
LineColumn.create(1, 3), LineColumn.create(1, 5),
|
LineColumn.create(1, 3), LineColumn.create(1, 5),
|
||||||
|
@ -95,7 +93,7 @@ public class LispScannerLineColumnTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenListSpanningMultipleLines_RecordsCorrectLocations() throws IOException {
|
public void givenListSpanningMultipleLines_RecordsCorrectLocations() {
|
||||||
String input = " ( 1 2 \n 3 4 \n5 ) ";
|
String input = " ( 1 2 \n 3 4 \n5 ) ";
|
||||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 2), LineColumn.create(1, 4),
|
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 2), LineColumn.create(1, 4),
|
||||||
LineColumn.create(1, 6), LineColumn.create(2, 2),
|
LineColumn.create(1, 6), LineColumn.create(2, 2),
|
||||||
|
@ -105,7 +103,7 @@ public class LispScannerLineColumnTester {
|
||||||
assertTokenLineAndColumnsMatch(input, expectedLinesAndColumns);
|
assertTokenLineAndColumnsMatch(input, expectedLinesAndColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTokenLineAndColumnsMatch(String input, LineColumn[] expectedLineColumnList) throws IOException {
|
private void assertTokenLineAndColumnsMatch(String input, LineColumn[] expectedLineColumnList) {
|
||||||
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
||||||
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
|
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package scanner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -12,42 +11,42 @@ import testutils.TestUtilities;
|
||||||
public class LispScannerTextTester {
|
public class LispScannerTextTester {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenIdentifier_RecordsCorrectText() throws IOException {
|
public void givenIdentifier_RecordsCorrectText() {
|
||||||
String input = "identifier";
|
String input = "identifier";
|
||||||
|
|
||||||
assertTokenTextMatches(input, input);
|
assertTokenTextMatches(input, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNumber_RecordsCorrectText() throws IOException {
|
public void givenNumber_RecordsCorrectText() {
|
||||||
String input = "192837456";
|
String input = "192837456";
|
||||||
|
|
||||||
assertTokenTextMatches(input, input);
|
assertTokenTextMatches(input, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenString_RecordsCorrectText() throws IOException {
|
public void givenString_RecordsCorrectText() {
|
||||||
String input = "\"String!!! \n More... \"";
|
String input = "\"String!!! \n More... \"";
|
||||||
|
|
||||||
assertTokenTextMatches(input, input);
|
assertTokenTextMatches(input, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEmptyStream_RecordsCorrectInputStreamName() throws IOException {
|
public void givenEmptyStream_RecordsCorrectInputStreamName() {
|
||||||
String input = "";
|
String input = "";
|
||||||
String expectedInputStreamName = "testInputStream";
|
String expectedInputStreamName = "testInputStream";
|
||||||
|
|
||||||
assertInputFileNameMatches(input, expectedInputStreamName);
|
assertInputFileNameMatches(input, expectedInputStreamName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTokenTextMatches(String input, String expectedText) throws IOException {
|
private void assertTokenTextMatches(String input, String expectedText) {
|
||||||
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
||||||
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
|
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
|
||||||
|
|
||||||
assertEquals(expectedText, lispScanner.getNextToken().getText());
|
assertEquals(expectedText, lispScanner.getNextToken().getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertInputFileNameMatches(String input, String expectedInputFileName) throws IOException {
|
private void assertInputFileNameMatches(String input, String expectedInputFileName) {
|
||||||
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
||||||
LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName);
|
LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName);
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,29 @@
|
||||||
package scanner;
|
package scanner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import constructs.Token;
|
import constructs.Token;
|
||||||
import constructs.Token.Type;
|
import constructs.Token.Type;
|
||||||
|
import constructs.TokenFactory;
|
||||||
import error.ErrorManager;
|
import error.ErrorManager;
|
||||||
import testutils.TestUtilities;
|
import testutils.TestUtilities;
|
||||||
|
|
||||||
public class LispScannerTypeTester {
|
public class LispScannerTypeTester {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEmptyFile_ReturnsCorrectTypes() throws IOException {
|
public void givenEmptyFile_ReturnsCorrectTypes() {
|
||||||
String input = "";
|
String input = "";
|
||||||
Token.Type[] expectedTypes = {};
|
Token.Type[] expectedTypes = {};
|
||||||
|
|
||||||
assertTokenTypesMatch(input, expectedTypes);
|
assertTokenTypesMatch(input, expectedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = RuntimeException.class)
|
@Test(expected = TokenFactory.BadCharacterException.class)
|
||||||
public void givenBadCharacter_ThrowsException() throws IOException {
|
public void givenBadCharacter_ThrowsException() {
|
||||||
String input = "[";
|
String input = "[";
|
||||||
Token.Type[] expectedTypes = {};
|
Token.Type[] expectedTypes = {};
|
||||||
|
|
||||||
|
@ -33,7 +31,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNil_ReturnsCorrectTypes() throws IOException {
|
public void givenNil_ReturnsCorrectTypes() {
|
||||||
String input = "()";
|
String input = "()";
|
||||||
Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.RIGHT_PAREN };
|
Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.RIGHT_PAREN };
|
||||||
|
|
||||||
|
@ -41,7 +39,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenListOfNumbers_ReturnsCorrectTypes() throws IOException {
|
public void givenListOfNumbers_ReturnsCorrectTypes() {
|
||||||
String input = "(1 2)";
|
String input = "(1 2)";
|
||||||
Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.NUMBER, Type.NUMBER, Type.RIGHT_PAREN };
|
Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.NUMBER, Type.NUMBER, Type.RIGHT_PAREN };
|
||||||
|
|
||||||
|
@ -49,7 +47,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenString_ReturnsCorrectTypes() throws IOException {
|
public void givenString_ReturnsCorrectTypes() {
|
||||||
String input = "\"string\"";
|
String input = "\"string\"";
|
||||||
Token.Type[] expectedTypes = { Type.STRING };
|
Token.Type[] expectedTypes = { Type.STRING };
|
||||||
|
|
||||||
|
@ -57,7 +55,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenStringWithEscapedDoubleQuote_ReturnsCorrectTypes() throws IOException {
|
public void givenStringWithEscapedDoubleQuote_ReturnsCorrectTypes() {
|
||||||
String input = "\"string \n hi \\\" bye\"";
|
String input = "\"string \n hi \\\" bye\"";
|
||||||
Token.Type[] expectedTypes = { Type.STRING };
|
Token.Type[] expectedTypes = { Type.STRING };
|
||||||
|
|
||||||
|
@ -65,7 +63,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenStringWithEscapedDoubleQuoteAndComment_ReturnsCorrectTypes() throws IOException {
|
public void givenStringWithEscapedDoubleQuoteAndComment_ReturnsCorrectTypes() {
|
||||||
String input = "\"string \n hi \\\" ; bye\"";
|
String input = "\"string \n hi \\\" ; bye\"";
|
||||||
Token.Type[] expectedTypes = { Type.STRING };
|
Token.Type[] expectedTypes = { Type.STRING };
|
||||||
|
|
||||||
|
@ -73,7 +71,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = LispScanner.UnterminatedStringException.class)
|
@Test(expected = LispScanner.UnterminatedStringException.class)
|
||||||
public void givenUnterminatedString_ThrowsException() throws IOException {
|
public void givenUnterminatedString_ThrowsException() {
|
||||||
String input = "\"oh no!";
|
String input = "\"oh no!";
|
||||||
Token.Type[] expectedTypes = { Type.STRING };
|
Token.Type[] expectedTypes = { Type.STRING };
|
||||||
|
|
||||||
|
@ -81,7 +79,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
public void givenUnterminatedString_ExceptionHasCorrectSeverity() throws IOException {
|
public void givenUnterminatedString_ExceptionHasCorrectSeverity() {
|
||||||
String input = "\"oh no!";
|
String input = "\"oh no!";
|
||||||
Token.Type[] expectedTypes = { Type.STRING };
|
Token.Type[] expectedTypes = { Type.STRING };
|
||||||
|
|
||||||
|
@ -93,7 +91,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
public void givenUnterminatedString_ExceptionContainsMessage() throws IOException {
|
public void givenUnterminatedString_ExceptionContainsMessage() {
|
||||||
String input = "\"oh no!";
|
String input = "\"oh no!";
|
||||||
Token.Type[] expectedTypes = { Type.STRING };
|
Token.Type[] expectedTypes = { Type.STRING };
|
||||||
|
|
||||||
|
@ -107,7 +105,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenIdentifier_ReturnsCorrectTypes() throws IOException {
|
public void givenIdentifier_ReturnsCorrectTypes() {
|
||||||
String input = "abcdefgHIJKLMNOP1234";
|
String input = "abcdefgHIJKLMNOP1234";
|
||||||
Token.Type[] expectedTypes = { Type.IDENTIFIER };
|
Token.Type[] expectedTypes = { Type.IDENTIFIER };
|
||||||
|
|
||||||
|
@ -115,7 +113,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSingleDigitNumber_ReturnsCorrectTypes() throws IOException {
|
public void givenSingleDigitNumber_ReturnsCorrectTypes() {
|
||||||
String input = "1";
|
String input = "1";
|
||||||
Token.Type[] expectedTypes = { Type.NUMBER };
|
Token.Type[] expectedTypes = { Type.NUMBER };
|
||||||
|
|
||||||
|
@ -123,7 +121,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenMultipleDigitNumber_ReturnsCorrectTypes() throws IOException {
|
public void givenMultipleDigitNumber_ReturnsCorrectTypes() {
|
||||||
String input = "1234567890";
|
String input = "1234567890";
|
||||||
Token.Type[] expectedTypes = { Type.NUMBER };
|
Token.Type[] expectedTypes = { Type.NUMBER };
|
||||||
|
|
||||||
|
@ -131,7 +129,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenQuote_ReturnsCorrectTypes() throws IOException {
|
public void givenQuote_ReturnsCorrectTypes() {
|
||||||
String input = "'";
|
String input = "'";
|
||||||
Token.Type[] expectedTypes = { Type.QUOTE_MARK };
|
Token.Type[] expectedTypes = { Type.QUOTE_MARK };
|
||||||
|
|
||||||
|
@ -139,7 +137,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenManyTypesWithNoWhitespace_ReturnsCorrectTypes() throws IOException {
|
public void givenManyTypesWithNoWhitespace_ReturnsCorrectTypes() {
|
||||||
String input = "xxx\"hi\"999()'aaa";
|
String input = "xxx\"hi\"999()'aaa";
|
||||||
Token.Type[] expectedTypes = { Type.IDENTIFIER, Type.STRING, Type.NUMBER, Type.LEFT_PAREN, Type.RIGHT_PAREN,
|
Token.Type[] expectedTypes = { Type.IDENTIFIER, Type.STRING, Type.NUMBER, Type.LEFT_PAREN, Type.RIGHT_PAREN,
|
||||||
Type.QUOTE_MARK, Type.IDENTIFIER };
|
Type.QUOTE_MARK, Type.IDENTIFIER };
|
||||||
|
@ -148,7 +146,7 @@ public class LispScannerTypeTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenFunctionCall_ReturnsCorrectTypes() throws IOException {
|
public void givenFunctionCall_ReturnsCorrectTypes() {
|
||||||
String input = "(defun myFunction (x)\n (print x))";
|
String input = "(defun myFunction (x)\n (print x))";
|
||||||
Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.IDENTIFIER, Type.IDENTIFIER, Type.LEFT_PAREN,
|
Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.IDENTIFIER, Type.IDENTIFIER, Type.LEFT_PAREN,
|
||||||
Type.IDENTIFIER, Type.RIGHT_PAREN, Type.LEFT_PAREN, Type.IDENTIFIER,
|
Type.IDENTIFIER, Type.RIGHT_PAREN, Type.LEFT_PAREN, Type.IDENTIFIER,
|
||||||
|
@ -157,7 +155,7 @@ public class LispScannerTypeTester {
|
||||||
assertTokenTypesMatch(input, expectedTypes);
|
assertTokenTypesMatch(input, expectedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTokenTypesMatch(String input, Token.Type[] expectedTypeList) throws IOException {
|
private void assertTokenTypesMatch(String input, Token.Type[] expectedTypeList) {
|
||||||
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
||||||
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
|
LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue