summaryrefslogtreecommitdiff
path: root/chapter18/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter18/src/test/java')
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Chapter01Test.java4
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Chapter05Test.java10
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java14
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java3
4 files changed, 21 insertions, 10 deletions
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter01Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter01Test.java
index 224a5f01..934eda76 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter01Test.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter01Test.java
@@ -32,7 +32,7 @@ public class Chapter01Test {
@Test
public void testBad1() {
try {
- new CodeGen("ret").parse();
+ new CodeGen("ret;").parse();
fail();
} catch( RuntimeException e ) {
assertEquals("Undefined name 'ret'",e.getMessage());
@@ -74,7 +74,7 @@ public class Chapter01Test {
@Test
public void testBad6() {
try {
- new CodeGen("return100").parse();
+ new CodeGen("return100;").parse();
fail();
} catch( RuntimeException e ) {
assertEquals("Undefined name 'return100'",e.getMessage());
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 3bea9b9a..f4db5624 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -142,10 +142,10 @@ return a;
@Test
public void testHalfDef() {
try {
- new Parser("if( arg==1 ) int b=2; return b;").parse();
+ new CodeGen("if( arg==1 ) int b=2; return b;").parse();
fail();
} catch( RuntimeException e ) {
- assertEquals("Cannot define a new name on one arm of an if",e.getMessage());
+ assertEquals("Cannot define a 'b' on one arm of an if",e.getMessage());
}
}
@@ -162,10 +162,10 @@ return a;
@Test
public void testRegress1() {
try {
- new Parser("if(arg==2) int a=1; else int b=2; return a;").parse();
+ new CodeGen("if(arg==2) int a=1; else int b=2; return a;").parse();
fail();
} catch( RuntimeException e ) {
- assertEquals("Cannot define a new name on one arm of an if",e.getMessage());
+ assertEquals("Cannot define a 'a' on one arm of an if",e.getMessage());
}
}
@@ -203,7 +203,7 @@ return a;
@Test
public void testKeyword3() {
try {
- new Parser("int a=1; ififif(arg)inta=2;return a;").parse();
+ new CodeGen("int a=1; ififif(arg);a=2;return a;").parse();
fail();
} catch( RuntimeException e ) {
assertEquals("Undefined name 'ififif'",e.getMessage());
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
index 6fc2cc98..fc67e090 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
@@ -11,7 +11,7 @@ public class Chapter18Test {
@Test
public void testJig() {
CodeGen code = new CodeGen("""
- return 0;
+return 0;
""");
code.parse(true).opto().typeCheck().GCM();
assertEquals("return 0;", code._stop.toString());
@@ -76,4 +76,16 @@ return sq(2)+sq(3);
assertEquals("Stop[ return (sq( 3)+sq( 2)); return (Parm_x(sq,int,3,2)*x); ]", code._stop.toString());
assertEquals("13", Eval2.eval(code, 0));
}
+
+ @Ignore @Test
+ public void testFcn2() {
+ CodeGen code = new CodeGen("val fact = { int x -> x < 1 ? 1 : x*fact(x-1); }; return fact(arg);");
+ code.parse().opto();
+ assertEquals("Stop[ return fact( arg); return Phi(Region,1,(Parm_x(fact,int,arg,(x-1))*fact( Sub))); ]", code._stop.toString());
+ assertEquals( "1", Eval2.eval(code, 0));
+ assertEquals( "1", Eval2.eval(code, 1));
+ assertEquals( "2", Eval2.eval(code, 2));
+ assertEquals( "6", Eval2.eval(code, 3));
+ assertEquals("24", Eval2.eval(code, 4));
+ }
}
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
index a6bef4d3..f57a0031 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
@@ -1,6 +1,5 @@
package com.seaofnodes.simple.fuzzer;
-import com.seaofnodes.simple.Utils;
import com.seaofnodes.simple.Parser;
import com.seaofnodes.simple.Eval2;
import com.seaofnodes.simple.CodeGen;
@@ -89,7 +88,7 @@ public class Fuzzer {
FuzzerUtils.parse(script, true);
} catch (RuntimeException e2) {
if (FuzzerUtils.isExceptionFromSameCause(e1, e2)) {
- if (!valid || e1.getClass() == Parser.ParserException.class) return;
+ if (!valid || e1.getClass() == Parser.ParseException.class) return;
} else {
e1.addSuppressed(e2);
}