diff options
Diffstat (limited to 'chapter05/src')
| -rw-r--r-- | chapter05/src/main/java/com/seaofnodes/simple/Parser.java | 2 | ||||
| -rw-r--r-- | chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/chapter05/src/main/java/com/seaofnodes/simple/Parser.java b/chapter05/src/main/java/com/seaofnodes/simple/Parser.java index 7ea74306..a66ee278 100644 --- a/chapter05/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter05/src/main/java/com/seaofnodes/simple/Parser.java @@ -479,7 +479,7 @@ public class Parser { private String parsePunctuation() { int start = _position; - return new String(_input, start, start+1); + return new String(_input, start, 1); } } diff --git a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java index 32ac5aac..2ad7e59a 100644 --- a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java +++ b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java @@ -115,7 +115,16 @@ return c; assertEquals("Expected an identifier, found 'else'",e.getMessage()); } } - + + @Test + public void testChapter5Keyword3() { + try { + new Parser("int a=1; ififif(arg)inta=2;return a;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Syntax error, expected =: (",e.getMessage()); + } + } @Test public void testChapter4Peephole() { Parser parser = new Parser("return 1+arg+2; #showGraph;"); |
