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/Chapter10Test.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/Chapter10Test.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/Chapter10Test.java | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/src/test/java/com/seaofnodes/simple/Chapter10Test.java index def9aaa6..2a33031d 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter10Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter10Test.java @@ -1,5 +1,6 @@ package com.seaofnodes.simple; +import com.seaofnodes.simple.evaluator.Evaluator; import com.seaofnodes.simple.node.StopNode; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -38,10 +39,10 @@ return p-r; struct Bar { int a; int b; -} +}; struct Foo { int x; -} +}; Foo? foo = null; Bar bar = new Bar; bar.a = 1; @@ -55,7 +56,7 @@ return bar.a; @Test public void testExample() { Parser parser = new Parser(""" -struct Vector2D { int x; int y; } +struct Vector2D { int x; int y; }; Vector2D v = new Vector2D; v.x = 1; if (arg) @@ -73,7 +74,7 @@ return v; Parser parser = new Parser(""" struct s0 { int v0; -} +}; s0? v1=null; int v3=v1.zAicm; """); @@ -84,7 +85,7 @@ int v3=v1.zAicm; @Test public void testBug2() { Parser parser = new Parser(""" -struct s0 { int v0; } +struct s0 { int v0; }; arg=0+new s0.0; """); try { parser.parse(); fail(); } @@ -94,7 +95,7 @@ arg=0+new s0.0; @Test public void testLoop() { Parser parser = new Parser(""" -struct Bar { int a; } +struct Bar { int a; }; Bar bar = new Bar; while (arg) { bar.a = bar.a + 2; @@ -102,14 +103,14 @@ while (arg) { } return bar.a; """); - StopNode stop = parser.parse(false).iterate(); - assertEquals("return Phi(Loop13,0,(Phi_a+2));", stop.toString()); + StopNode stop = parser.parse().iterate(); + assertEquals("return Phi(Loop16,0,(Phi_a+2));", stop.toString()); } @Test public void testIf() { Parser parser = new Parser(""" -struct Bar { int a; } +struct Bar { int a; }; Bar bar = new Bar; if (arg) bar = null; bar.a = 1; @@ -122,7 +123,7 @@ return bar.a; @Test public void testIf2() { Parser parser = new Parser(""" -struct Bar { int a; } +struct Bar { int a; }; Bar? bar = null; if (arg) bar = new Bar; bar.a = 1; @@ -135,7 +136,7 @@ return bar.a; @Test public void testIf3() { Parser parser = new Parser(""" -struct Bar { int a; } +struct Bar { int a; }; Bar bar = null; if (arg) bar = null; bar.a = 1; @@ -148,21 +149,21 @@ return bar.a; @Test public void testIfOrNull() { Parser parser = new Parser(""" -struct Bar { int a; } +struct Bar { int a; }; Bar? bar = new Bar; if (arg) bar = null; if( bar ) bar.a = 1; return bar; """); StopNode stop = parser.parse(false).iterate(); - assertEquals("return Phi(Region33,(*void)Phi(Region20,null,Bar),null);", stop.toString()); + assertEquals("return Phi(Region38,(*void)Phi(Region24,null,Bar),null);", stop.toString()); } @Test public void testIfOrNull2() { Parser parser = new Parser( """ -struct Bar { int a; } +struct Bar { int a; }; Bar? bar = new Bar; if (arg) bar = null; int rez = 3; @@ -171,13 +172,13 @@ else bar.a = 1; return rez; """); StopNode stop = parser.parse(false).iterate(); - assertEquals("return Phi(Region39,4,3);", stop.toString()); + assertEquals("return Phi(Region44,4,3);", stop.toString()); } @Test public void testWhileWithNullInside() { Parser parser = new Parser(""" -struct s0 {int v0;} +struct s0 {int v0;}; s0? v0 = new s0; int ret = 0; while(arg) { @@ -197,7 +198,7 @@ return ret; Parser parser = new Parser(""" struct s0 { int v0; -} +}; s0? v1=new s0; s0? v1; v1=new s0; @@ -214,7 +215,7 @@ v1=new s0; struct Iter { int x; int len; -} +}; Iter i = new Iter; i.len = arg; int sum=0; @@ -225,16 +226,14 @@ while( i.x < i.len ) { return sum; """); StopNode stop = parser.parse().iterate(); - assertEquals("return Phi(Loop18,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString()); + assertEquals("return Phi(Loop21,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString()); } - - @Test public void test1() { Parser parser = new Parser(""" -struct s0 {int v0;} +struct s0 {int v0;}; s0 ret = new s0; while(arg) { s0 v0 = new s0; @@ -246,13 +245,13 @@ while(arg) { return ret; """); StopNode stop = parser.parse().iterate(); - assertEquals("return Phi(Loop13,s0,Phi(Region37,s0,Phi_ret));", stop.toString()); + assertEquals("return Phi(Loop16,s0,Phi(Region43,s0,Phi_ret));", stop.toString()); } @Test public void test2() { Parser parser = new Parser(""" -struct s0 {int v0;} +struct s0 {int v0;}; s0 ret = new s0; s0 v0 = new s0; while(arg) { @@ -264,14 +263,14 @@ while(arg) { return ret; """); StopNode stop = parser.parse().iterate(); - assertEquals("return Phi(Loop17,s0,Phi(Region38,s0,Phi_ret));", stop.toString()); + assertEquals("return Phi(Loop20,s0,Phi(Region44,s0,Phi_ret));", stop.toString()); } @Test public void test3() { Parser parser = new Parser(""" -struct s0 {int v0;} +struct s0 {int v0;}; s0 ret = new s0; while(arg < 10) { s0 v0 = new s0; @@ -281,21 +280,19 @@ while(arg < 10) { return ret; """); StopNode stop = parser.parse().iterate(); - assertEquals("return Phi(Loop13,s0,Phi(Region35,s0,Phi_ret));", stop.toString()); + assertEquals("return Phi(Loop16,s0,Phi(Region41,s0,Phi_ret));", stop.toString()); } @Test public void testBug3() { Parser parser = new Parser(""" -struct s0 { - int f0; -} -if(0>=0) return new s0; +struct s0 { int f0; }; return new s0; int v0=null.f0; """); - try { parser.parse(); fail(); } - catch( Exception e ) { assertEquals("Accessing unknown field 'f0' from 'null'", e.getMessage()); } + StopNode stop = parser.parse().iterate(); + assertEquals("return s0;", stop.toString()); + assertEquals("Obj<s0>{f0=0}", Evaluator.evaluate(stop, 0).toString()); } @Test @@ -319,7 +316,7 @@ if(0) { Parser parser = new Parser(""" struct s0 { int f0; -} +}; if(0) return 0; else return new s0; if(new s0.f0) return 0; @@ -346,7 +343,7 @@ return 0; @Test public void testBug7() { Parser parser = new Parser(""" -struct s0 { int f0; } +struct s0 { int f0; }; s0 v0 = new s0; while(v0.f0) {} s0 v1 = v0; |
