summaryrefslogtreecommitdiff
path: root/chapter23/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter23/src/test/java')
-rw-r--r--chapter23/src/test/java/com/seaofnodes/simple/Chapter12Test.java7
-rw-r--r--chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java9
2 files changed, 16 insertions, 0 deletions
diff --git a/chapter23/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter23/src/test/java/com/seaofnodes/simple/Chapter12Test.java
index 21759b78..c50be559 100644
--- a/chapter23/src/test/java/com/seaofnodes/simple/Chapter12Test.java
+++ b/chapter23/src/test/java/com/seaofnodes/simple/Chapter12Test.java
@@ -7,6 +7,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class Chapter12Test {
+ @Test public void testSubZeroFloat() {
+ var code = new CodeGen("flt x = arg; return 0-x;").parse().opto().typeCheck();
+ // Compare strings so +0.0 and -0.0 remain distinct.
+ assertEquals("0.0", Eval2.eval(code,0));
+ assertEquals("-1.0", Eval2.eval(code,1));
+ }
+
@Test public void testDeadNumericReturns() {
for( String[] test : new String[][] {
{"if(1) return 7; else return 2.5;", "7"},
diff --git a/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java
index a3e9a016..bca06f0c 100644
--- a/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java
+++ b/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java
@@ -13,6 +13,15 @@ import org.junit.Test;
import static org.junit.Assert.*;
public class Chapter22Test {
+ @Test public void testSubZeroTypeError() {
+ try {
+ new CodeGen("return null-0;").parse().opto().typeCheck();
+ fail("Subtraction must reject null even when the other operand is zero");
+ } catch( Parser.ParseException e ) {
+ assertEquals("Cannot '-' null",e.getMessage());
+ }
+ }
+
@Test public void testInfiniteReturn() {
String src = "struct S { int i; }; S !s = new S; while(1) s.i++; return s.i;";
testCPU(src,"x86_64_v2","SystemV",0,"return Top;");