diff options
Diffstat (limited to 'chapter05/src/test')
| -rw-r--r-- | chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java index 8f09620e..32ac5aac 100644 --- a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java +++ b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java @@ -95,6 +95,26 @@ return c; StopNode stop = new Parser("return true;").parse(); assertEquals("return 1;",stop.toString()); } + + @Test + public void testChapter5Keyword1() { + try { + new Parser("int true=0; return true;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Expected an identifier, found 'true'",e.getMessage()); + } + } + + @Test + public void testChapter5Keyword2() { + try { + new Parser("int else=arg; if(else) else=2; else else=1; return else;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Expected an identifier, found 'else'",e.getMessage()); + } + } @Test public void testChapter4Peephole() { @@ -197,6 +217,16 @@ return c; } @Test + public void testChapter4Bug3() { + try { + new Parser("inta=1; return a;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Undefined name 'inta'",e.getMessage()); + } + } + + @Test public void testVarDecl() { Parser parser = new Parser("int a=1; return a;"); StopNode ret = parser.parse(); @@ -242,7 +272,6 @@ return c; } } - @Test public void testChapter2ParseGrammar() { Node._disablePeephole = true; // disable peephole so we can observe full graph |
