diff options
Diffstat (limited to 'chapter16/src/test/java/com')
| -rw-r--r-- | chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java | 6 | ||||
| -rw-r--r-- | chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java index 2b07234f..408a4814 100644 --- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java +++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java @@ -48,6 +48,7 @@ public class Chapter10Test { public void testNullGuardErrors() { for( String body : new String[] { "return p.x;", + "if (p == null) return p.x; return -1;", "if (!!points) return p.x; return -1;", "if (!!p) { int x = p.x; } return p.x;" } ) { @@ -55,7 +56,10 @@ public class Chapter10Test { new Parser(NULLABLE_POINT_SOURCE+body).parse().iterate(); fail(body); } catch( RuntimeException e ) { - assertEquals(body,"Might be null accessing 'x'",e.getMessage()); + // Known null is rejected during parsing in these chapters. + String expected = body.startsWith("if (p == null)") + ? "Accessing unknown field 'x' from 'null'" : "Might be null accessing 'x'"; + assertEquals(body,expected,e.getMessage()); } } } diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java index ad287e82..6fb41233 100644 --- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java +++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java @@ -9,6 +9,15 @@ import static org.junit.Assert.fail; public class Chapter16Test { @Test + public void testStructFinal3() { + for( String fields : new String[] { "int[] x;", "int[] !x;" } ) { + String src = "struct Point { "+fields+" }; Point p = new Point; p.x++; return p;"; + try { new Parser(src).parse().iterate(); fail(fields); } + catch( Exception e ) { assertEquals("'Point' is not fully initialized, field 'x' needs to be set in a constructor",e.getMessage()); } + } + } + + @Test public void testJig() { Parser parser = new Parser( """ |
