diff options
| author | Cliff Click <cliffc@acm.org> | 2024-10-12 14:02:06 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2024-10-23 17:51:09 -0700 |
| commit | 1ee105dce9c32460feed5c3a20c42abbaa7c1896 (patch) | |
| tree | 1746b458d995622bc11d796e48fe288240709f99 /src/test/java/com/seaofnodes/simple/Chapter13Test.java | |
| parent | 67dc6202dee2ce983778ba3143cc3f00196aeb7c (diff) | |
| download | Simple-linear-chapter16.tar.gz Simple-linear-chapter16.zip | |
Chapter 16: Constructors and Final fieldslinear-chapter16
Co-authored-by: Thalia Archibald <thalia@archibald.dev>
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter13Test.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/Chapter13Test.java | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/src/test/java/com/seaofnodes/simple/Chapter13Test.java index 416aba31..165d23e5 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter13Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter13Test.java @@ -2,7 +2,6 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.evaluator.Evaluator; import com.seaofnodes.simple.node.StopNode; -import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -23,7 +22,7 @@ return 3.14; public void testLinkedList0() { Parser parser = new Parser( """ -struct LLI { LLI? next; int i; } +struct LLI { LLI? next; int i; }; LLI? head = null; while( arg ) { LLI x = new LLI; @@ -35,14 +34,14 @@ while( arg ) { return head.next.i; """); try { parser.parse().iterate(); fail(); } - catch( Exception e ) { assertEquals("Might be null accessing 'next'",e.getMessage()); } + catch( Exception e ) { assertEquals("Might be null accessing 'i'",e.getMessage()); } } @Test public void testLinkedList1() { Parser parser = new Parser( """ -struct LLI { LLI? next; int i; } +struct LLI { LLI? next; int i; }; LLI? head = null; while( arg ) { LLI x = new LLI; @@ -65,8 +64,8 @@ return next.i; public void testCoRecur() { Parser parser = new Parser( """ -struct int0 { int i; flt0? f; } -struct flt0 { flt f; int0? i; } +struct int0 { int i; flt0? f; }; +struct flt0 { flt f; int0? i; }; int0 i0 = new int0; i0.i = 17; flt0 f0 = new flt0; @@ -83,7 +82,7 @@ return f0.i.f.i.i; public void testNullRef0() { Parser parser = new Parser( """ -struct N { N next; int i; } +struct N { N? next; int i; }; N n = new N; return n.next; """); @@ -95,33 +94,33 @@ return n.next; public void testNullRef1() { Parser parser = new Parser( """ -struct N { N next; int i; } -N n = new N; -n.next = new N; +struct M { int m; }; +struct N { M next; int i; }; +N n = new N { next = new M; }; return n.next; """); StopNode stop = parser.parse().iterate(); - assertEquals("return N;", stop.toString()); + assertEquals("return M;", stop.toString()); } @Test public void testNullRef2() { Parser parser = new Parser( """ -struct N { N next; int i; } -N n = new N; -n.next = null; +struct M { int m; }; +struct N { M next; int i; }; +N n = new N { next = null; } return n.next; """); try { parser.parse().iterate(); fail(); } - catch( Exception e ) { assertEquals("Cannot store null into field *N next",e.getMessage()); } + catch( Exception e ) { assertEquals("Type null is not of declared type *M",e.getMessage()); } } @Test public void testNullRef3() { Parser parser = new Parser( """ -struct N { N next; int i; } +struct N { N? next; int i; }; N n = new N; n.i = 3.14; return n.i; @@ -145,7 +144,7 @@ struct S{}; public void testForwardRef0() { Parser parser = new Parser( """ -struct S1 { S2 s; } +struct S1 { S2 s; }; return new S2; """); try { parser.parse().iterate(); fail(); } @@ -156,8 +155,8 @@ return new S2; public void testForwardRef1() { Parser parser = new Parser( """ -struct S1 { S2? s; } -struct S2 { int x; } +struct S1 { S2? s; }; +struct S2 { int x; }; return new S1.s=new S2; """); StopNode stop = parser.parse().iterate(); @@ -168,8 +167,8 @@ return new S1.s=new S2; public void testcheckNull() { Parser parser = new Parser( """ -struct I {int i;} -struct P {I pi;} +struct I {int i;}; +struct P { I? pi; }; P p1 = new P; P p2 = new P; p2.pi = new I; |
