diff --git a/src/constructs/TokenFactory.java b/src/constructs/TokenFactory.java index 6b6fb3e..83e2463 100644 --- a/src/constructs/TokenFactory.java +++ b/src/constructs/TokenFactory.java @@ -1,11 +1,38 @@ package constructs; +import java.text.MessageFormat; + +import error.LispException; import file.FilePosition; public interface TokenFactory { - + Token createToken(String text, 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()); + } + + } } diff --git a/src/constructs/TokenFactoryImpl.java b/src/constructs/TokenFactoryImpl.java index 980339a..27cf75b 100644 --- a/src/constructs/TokenFactoryImpl.java +++ b/src/constructs/TokenFactoryImpl.java @@ -27,7 +27,7 @@ public class TokenFactoryImpl implements TokenFactory { } } - throw new RuntimeException("oh no!"); + throw new BadCharacterException(text, position); } public Token createEOFToken(FilePosition position) { diff --git a/src/error/ErrorManager.java b/src/error/ErrorManager.java index c9a599d..bd065a1 100644 --- a/src/error/ErrorManager.java +++ b/src/error/ErrorManager.java @@ -14,6 +14,10 @@ public class ErrorManager { public static final String ANSI_YELLOW = "\u001B[33m"; 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 * or not to terminate the currently running program. diff --git a/src/scanner/LispFilterInputStream.java b/src/scanner/LispFilterInputStream.java index 2e3644a..438149f 100644 --- a/src/scanner/LispFilterInputStream.java +++ b/src/scanner/LispFilterInputStream.java @@ -2,60 +2,87 @@ package scanner; import static util.Characters.*; -import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; /** * 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 rereadLastCharacter; private int previousCharacter; - private int nextCharacter; + private int currentCharacter; public LispFilterInputStream(InputStream underlyingInputStream) { - super(underlyingInputStream); - - isInQuotedString = false; - previousCharacter = 0; - nextCharacter = 0; + this.underlyingInputStream = underlyingInputStream; + this.isInQuotedString = false; + this.rereadLastCharacter = false; + this.previousCharacter = 0; + this.currentCharacter = 0; } @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(); if (haveEnteredComment()) consumeAllBytesInComment(); - return nextCharacter; + return currentCharacter; + } private void readNextCharacter() throws IOException { - previousCharacter = nextCharacter; - nextCharacter = super.read(); + previousCharacter = currentCharacter; + currentCharacter = underlyingInputStream.read(); if (haveEncounteredStringBoundary()) isInQuotedString = !isInQuotedString; } private boolean haveEncounteredStringBoundary() { - return (previousCharacter != BACKSLASH) && (nextCharacter == DOUBLE_QUOTE); + return (previousCharacter != BACKSLASH) && (currentCharacter == DOUBLE_QUOTE); } private boolean haveEnteredComment() { - return (nextCharacter == SEMICOLON) && (!isInQuotedString); + return (currentCharacter == SEMICOLON) && (!isInQuotedString); } private void consumeAllBytesInComment() throws IOException { while (stillInComment()) - nextCharacter = super.read(); + currentCharacter = underlyingInputStream.read(); } 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; } } diff --git a/src/scanner/LispInputStream.java b/src/scanner/LispInputStream.java new file mode 100644 index 0000000..d2f93d4 --- /dev/null +++ b/src/scanner/LispInputStream.java @@ -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(); + } + } + +} diff --git a/src/scanner/LispScanner.java b/src/scanner/LispScanner.java index e6194e1..7a1b84e 100644 --- a/src/scanner/LispScanner.java +++ b/src/scanner/LispScanner.java @@ -2,8 +2,6 @@ package scanner; import static util.Characters.*; -import java.io.BufferedInputStream; -import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import java.util.function.Function; @@ -21,17 +19,17 @@ import util.Characters; */ public class LispScanner { - private InputStream inputStream; + private LispInputStream inputStream; private FilePositionTracker positionTracker; private TokenFactory tokenFactory; public LispScanner(InputStream in, String fileName) { - this.inputStream = new LispFilterInputStream(new BufferedInputStream(in)); + this.inputStream = new LispFilterInputStream(in); this.positionTracker = new FilePositionTracker(fileName); this.tokenFactory = new TokenFactoryImpl(); } - public Token getNextToken() throws IOException { + public Token getNextToken() { for (int c = inputStream.read(); c != EOF; c = inputStream.read()) { char currentCharacter = (char) c; positionTracker.incrementColumn(); @@ -45,14 +43,14 @@ public class LispScanner { return tokenFactory.createEOFToken(positionTracker.getCurrentPosition()); } - private Token createTokenFromCharacter(char c) throws IOException { + private Token createTokenFromCharacter(char c) { FilePosition currentPosition = positionTracker.getCurrentPosition(); String tokenText = retrieveTokenText(c); return tokenFactory.createToken(tokenText, currentPosition); } - private String retrieveTokenText(char firstCharacter) throws IOException { + private String retrieveTokenText(char firstCharacter) { String tokenText = "" + firstCharacter; if (firstCharacter == DOUBLE_QUOTE) @@ -65,20 +63,20 @@ public class LispScanner { return tokenText; } - private String retrieveStringTokenText(char firstDoubleQuote) throws IOException { + private String retrieveStringTokenText(char firstDoubleQuote) { ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstDoubleQuote, Characters::isLegalStringCharacter); return retriever.retrieveToken(); } - private String retrieveNumberTokenText(char firstDigit) throws IOException { + private String retrieveNumberTokenText(char firstDigit) { ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstDigit, Character::isDigit); return retriever.retrieveToken(); } - private String retrieveIdentifierTokenText(char firstCharacter) throws IOException { + private String retrieveIdentifierTokenText(char firstCharacter) { ComplexTokenTextRetriever retriever = new ComplexTokenTextRetriever(firstCharacter, Characters::isLegalIdentifierCharacter); @@ -103,15 +101,14 @@ public class LispScanner { this.previousCharacter = firstCharacter; } - public String retrieveToken() throws IOException { + public String retrieveToken() { text.append(firstCharacter); - inputStream.mark(1); for (int c = inputStream.read(); c != EOF; c = inputStream.read()) { currentCharacter = (char) c; if (!isPartOfToken.apply(currentCharacter)) { - inputStream.reset(); + inputStream.unreadLastCharacter(); return text.toString(); } @@ -130,7 +127,6 @@ public class LispScanner { private void addCharacterToToken() { text.append(currentCharacter); positionTracker.incrementColumn(); - inputStream.mark(1); if (currentCharacter == NEWLINE) positionTracker.incrementLine(); diff --git a/test/scanner/LispFilterInputStreamTester.java b/test/scanner/LispFilterInputStreamTester.java index 92d65f3..bc7cad7 100644 --- a/test/scanner/LispFilterInputStreamTester.java +++ b/test/scanner/LispFilterInputStreamTester.java @@ -2,7 +2,6 @@ package scanner; import static org.junit.Assert.assertEquals; -import java.io.IOException; import java.io.InputStream; import org.junit.Before; @@ -20,29 +19,29 @@ public class LispFilterInputStreamTester { } @Test - public void noBytesIn_noBytesOut() throws IOException { + public void noBytesIn_noBytesOut() { String input = ""; assertEquals(input, getLispFilterInputStreamResult(input)); } @Test - public void oneCharacter_notRemoved() throws IOException { + public void oneCharacter_notRemoved() { String input = "x"; assertEquals(input, getLispFilterInputStreamResult(input)); } @Test - public void allNonCommentCharacters_notRemoved() throws IOException { + public void allNonCommentCharacters_notRemoved() { String input = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - + "`1234567890-=~!@#$%^&*()_+[]\\',./{}|:\"<>?"; + + "`1234567890-=~!@#$%^&*()_+[]\\',./{}|:\"<>?"; assertEquals(input, getLispFilterInputStreamResult(input)); } @Test - public void oneComment_Removed() throws IOException { + public void oneComment_Removed() { String input = ";comment"; String expectedResult = ""; @@ -50,7 +49,7 @@ public class LispFilterInputStreamTester { } @Test - public void multipleComments_Removed() throws IOException { + public void multipleComments_Removed() { String input = ";comment1\n;comment2\n;comment3"; String expectedResult = "\n\n"; @@ -58,7 +57,7 @@ public class LispFilterInputStreamTester { } @Test - public void nil_NotRemoved() throws IOException { + public void nil_NotRemoved() { String input = "()"; String expectedResult = "()"; @@ -66,7 +65,7 @@ public class LispFilterInputStreamTester { } @Test - public void interiorComment_Removed() throws IOException { + public void interiorComment_Removed() { String input = "(;this is a comment\n)"; String expectedResult = "(\n)"; @@ -74,42 +73,109 @@ public class LispFilterInputStreamTester { } @Test - public void commentInString_NotRemoved() throws IOException { + public void commentInString_NotRemoved() { String input = "\"string;this should remain\""; assertEquals(input, getLispFilterInputStreamResult(input)); } @Test - public void commentInStringWithNewline_NotRemoved() throws IOException { + public void commentInStringWithNewline_NotRemoved() { String input = "\"string;this should\n remain\""; assertEquals(input, getLispFilterInputStreamResult(input)); } @Test - public void commentInStringWithEscapedDoubleQuote_NotRemoved() throws IOException { + public void commentInStringWithEscapedDoubleQuote_NotRemoved() { String input = "\"string \\\" ;this should remain\""; assertEquals(input, getLispFilterInputStreamResult(input)); } @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 expectedResult = "\n '(1 2 3) \n \n (defun add1 (x) (+ x 1)) "; assertEquals(expectedResult, getLispFilterInputStreamResult(input)); } - private String getLispFilterInputStreamResult(String inputString) throws IOException { - InputStream stringInputStream = TestUtilities.createInputStreamFromString(inputString); - LispFilterInputStream lispFilterInputStream = new LispFilterInputStream(stringInputStream); + @Test + public void unreadOneCharacter_ReturnsSameCharacter() { + 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(); while (c != -1) { diff --git a/test/scanner/LispScannerLineColumnTester.java b/test/scanner/LispScannerLineColumnTester.java index 7771408..fb922c9 100644 --- a/test/scanner/LispScannerLineColumnTester.java +++ b/test/scanner/LispScannerLineColumnTester.java @@ -2,7 +2,6 @@ package scanner; import static org.junit.Assert.assertTrue; -import java.io.IOException; import java.io.InputStream; import org.junit.Before; @@ -18,7 +17,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenNothing_RecordsCorrectEOFLocation() throws IOException { + public void givenNothing_RecordsCorrectEOFLocation() { String input = ""; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 0) }; @@ -26,7 +25,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenSimpleString_RecordsCorrectLocation() throws IOException { + public void givenSimpleString_RecordsCorrectLocation() { String input = "\"string\""; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) }; @@ -34,7 +33,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenStringWithTrailingSpace_RecordsCorrectLocation() throws IOException { + public void givenStringWithTrailingSpace_RecordsCorrectLocation() { String input = "\"string\" "; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) }; @@ -42,7 +41,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenIdentifier_RecordsCorrectLocation() throws IOException { + public void givenIdentifier_RecordsCorrectLocation() { String input = "identifier"; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) }; @@ -50,7 +49,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenIdentifierWithTrailingSpace_RecordsCorrectLocation() throws IOException { + public void givenIdentifierWithTrailingSpace_RecordsCorrectLocation() { String input = "identifier "; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) }; @@ -58,7 +57,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenNumber_RecordsCorrectLocation() throws IOException { + public void givenNumber_RecordsCorrectLocation() { String input = "123456789"; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) }; @@ -66,16 +65,15 @@ public class LispScannerLineColumnTester { } @Test - public void givenNumberWithTrailingSpace_RecordsCorrectLocation() throws IOException { + public void givenNumberWithTrailingSpace_RecordsCorrectLocation() { String input = "123456789 "; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1) }; assertTokenLineAndColumnsMatch(input, expectedLinesAndColumns); } - @Test - public void givenMultipleStrings_RecordsCorrectLocations() throws IOException { + public void givenMultipleStrings_RecordsCorrectLocations() { String input = "\"string1\" \n \"string2 \n with newline\" \n \"string3\""; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1), LineColumn.create(2, 2), LineColumn.create(4, 3) }; @@ -84,7 +82,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenQuotedList_RecordsCorrectLocations() throws IOException { + public void givenQuotedList_RecordsCorrectLocations() { String input = "'(1 2 3 4 5)"; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 1), LineColumn.create(1, 2), LineColumn.create(1, 3), LineColumn.create(1, 5), @@ -95,7 +93,7 @@ public class LispScannerLineColumnTester { } @Test - public void givenListSpanningMultipleLines_RecordsCorrectLocations() throws IOException { + public void givenListSpanningMultipleLines_RecordsCorrectLocations() { String input = " ( 1 2 \n 3 4 \n5 ) "; LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 2), LineColumn.create(1, 4), LineColumn.create(1, 6), LineColumn.create(2, 2), @@ -105,7 +103,7 @@ public class LispScannerLineColumnTester { assertTokenLineAndColumnsMatch(input, expectedLinesAndColumns); } - private void assertTokenLineAndColumnsMatch(String input, LineColumn[] expectedLineColumnList) throws IOException { + private void assertTokenLineAndColumnsMatch(String input, LineColumn[] expectedLineColumnList) { InputStream stringInputStream = TestUtilities.createInputStreamFromString(input); LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream"); diff --git a/test/scanner/LispScannerTextTester.java b/test/scanner/LispScannerTextTester.java index 7a4d8c1..7887df5 100644 --- a/test/scanner/LispScannerTextTester.java +++ b/test/scanner/LispScannerTextTester.java @@ -2,7 +2,6 @@ package scanner; import static org.junit.Assert.assertEquals; -import java.io.IOException; import java.io.InputStream; import org.junit.Test; @@ -12,42 +11,42 @@ import testutils.TestUtilities; public class LispScannerTextTester { @Test - public void givenIdentifier_RecordsCorrectText() throws IOException { + public void givenIdentifier_RecordsCorrectText() { String input = "identifier"; assertTokenTextMatches(input, input); } @Test - public void givenNumber_RecordsCorrectText() throws IOException { + public void givenNumber_RecordsCorrectText() { String input = "192837456"; assertTokenTextMatches(input, input); } @Test - public void givenString_RecordsCorrectText() throws IOException { + public void givenString_RecordsCorrectText() { String input = "\"String!!! \n More... \""; assertTokenTextMatches(input, input); } @Test - public void givenEmptyStream_RecordsCorrectInputStreamName() throws IOException { + public void givenEmptyStream_RecordsCorrectInputStreamName() { String input = ""; String expectedInputStreamName = "testInputStream"; assertInputFileNameMatches(input, expectedInputStreamName); } - private void assertTokenTextMatches(String input, String expectedText) throws IOException { + private void assertTokenTextMatches(String input, String expectedText) { 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 { + private void assertInputFileNameMatches(String input, String expectedInputFileName) { InputStream stringInputStream = TestUtilities.createInputStreamFromString(input); LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName); diff --git a/test/scanner/LispScannerTypeTester.java b/test/scanner/LispScannerTypeTester.java index b0c95dd..5349f58 100644 --- a/test/scanner/LispScannerTypeTester.java +++ b/test/scanner/LispScannerTypeTester.java @@ -1,31 +1,29 @@ package scanner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; -import java.io.IOException; import java.io.InputStream; import org.junit.Test; import constructs.Token; import constructs.Token.Type; +import constructs.TokenFactory; import error.ErrorManager; import testutils.TestUtilities; public class LispScannerTypeTester { @Test - public void givenEmptyFile_ReturnsCorrectTypes() throws IOException { + public void givenEmptyFile_ReturnsCorrectTypes() { String input = ""; Token.Type[] expectedTypes = {}; assertTokenTypesMatch(input, expectedTypes); } - @Test(expected = RuntimeException.class) - public void givenBadCharacter_ThrowsException() throws IOException { + @Test(expected = TokenFactory.BadCharacterException.class) + public void givenBadCharacter_ThrowsException() { String input = "["; Token.Type[] expectedTypes = {}; @@ -33,7 +31,7 @@ public class LispScannerTypeTester { } @Test - public void givenNil_ReturnsCorrectTypes() throws IOException { + public void givenNil_ReturnsCorrectTypes() { String input = "()"; Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.RIGHT_PAREN }; @@ -41,7 +39,7 @@ public class LispScannerTypeTester { } @Test - public void givenListOfNumbers_ReturnsCorrectTypes() throws IOException { + public void givenListOfNumbers_ReturnsCorrectTypes() { String input = "(1 2)"; Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.NUMBER, Type.NUMBER, Type.RIGHT_PAREN }; @@ -49,7 +47,7 @@ public class LispScannerTypeTester { } @Test - public void givenString_ReturnsCorrectTypes() throws IOException { + public void givenString_ReturnsCorrectTypes() { String input = "\"string\""; Token.Type[] expectedTypes = { Type.STRING }; @@ -57,7 +55,7 @@ public class LispScannerTypeTester { } @Test - public void givenStringWithEscapedDoubleQuote_ReturnsCorrectTypes() throws IOException { + public void givenStringWithEscapedDoubleQuote_ReturnsCorrectTypes() { String input = "\"string \n hi \\\" bye\""; Token.Type[] expectedTypes = { Type.STRING }; @@ -65,7 +63,7 @@ public class LispScannerTypeTester { } @Test - public void givenStringWithEscapedDoubleQuoteAndComment_ReturnsCorrectTypes() throws IOException { + public void givenStringWithEscapedDoubleQuoteAndComment_ReturnsCorrectTypes() { String input = "\"string \n hi \\\" ; bye\""; Token.Type[] expectedTypes = { Type.STRING }; @@ -73,7 +71,7 @@ public class LispScannerTypeTester { } @Test(expected = LispScanner.UnterminatedStringException.class) - public void givenUnterminatedString_ThrowsException() throws IOException { + public void givenUnterminatedString_ThrowsException() { String input = "\"oh no!"; Token.Type[] expectedTypes = { Type.STRING }; @@ -81,7 +79,7 @@ public class LispScannerTypeTester { } @Test() - public void givenUnterminatedString_ExceptionHasCorrectSeverity() throws IOException { + public void givenUnterminatedString_ExceptionHasCorrectSeverity() { String input = "\"oh no!"; Token.Type[] expectedTypes = { Type.STRING }; @@ -93,7 +91,7 @@ public class LispScannerTypeTester { } @Test() - public void givenUnterminatedString_ExceptionContainsMessage() throws IOException { + public void givenUnterminatedString_ExceptionContainsMessage() { String input = "\"oh no!"; Token.Type[] expectedTypes = { Type.STRING }; @@ -107,7 +105,7 @@ public class LispScannerTypeTester { } @Test - public void givenIdentifier_ReturnsCorrectTypes() throws IOException { + public void givenIdentifier_ReturnsCorrectTypes() { String input = "abcdefgHIJKLMNOP1234"; Token.Type[] expectedTypes = { Type.IDENTIFIER }; @@ -115,7 +113,7 @@ public class LispScannerTypeTester { } @Test - public void givenSingleDigitNumber_ReturnsCorrectTypes() throws IOException { + public void givenSingleDigitNumber_ReturnsCorrectTypes() { String input = "1"; Token.Type[] expectedTypes = { Type.NUMBER }; @@ -123,7 +121,7 @@ public class LispScannerTypeTester { } @Test - public void givenMultipleDigitNumber_ReturnsCorrectTypes() throws IOException { + public void givenMultipleDigitNumber_ReturnsCorrectTypes() { String input = "1234567890"; Token.Type[] expectedTypes = { Type.NUMBER }; @@ -131,7 +129,7 @@ public class LispScannerTypeTester { } @Test - public void givenQuote_ReturnsCorrectTypes() throws IOException { + public void givenQuote_ReturnsCorrectTypes() { String input = "'"; Token.Type[] expectedTypes = { Type.QUOTE_MARK }; @@ -139,7 +137,7 @@ public class LispScannerTypeTester { } @Test - public void givenManyTypesWithNoWhitespace_ReturnsCorrectTypes() throws IOException { + public void givenManyTypesWithNoWhitespace_ReturnsCorrectTypes() { String input = "xxx\"hi\"999()'aaa"; Token.Type[] expectedTypes = { Type.IDENTIFIER, Type.STRING, Type.NUMBER, Type.LEFT_PAREN, Type.RIGHT_PAREN, Type.QUOTE_MARK, Type.IDENTIFIER }; @@ -148,7 +146,7 @@ public class LispScannerTypeTester { } @Test - public void givenFunctionCall_ReturnsCorrectTypes() throws IOException { + public void givenFunctionCall_ReturnsCorrectTypes() { String input = "(defun myFunction (x)\n (print x))"; Token.Type[] expectedTypes = { Type.LEFT_PAREN, Type.IDENTIFIER, Type.IDENTIFIER, Type.LEFT_PAREN, Type.IDENTIFIER, Type.RIGHT_PAREN, Type.LEFT_PAREN, Type.IDENTIFIER, @@ -157,7 +155,7 @@ public class LispScannerTypeTester { 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); LispScanner lispScanner = new LispScanner(stringInputStream, "stringInputStream");