From 664761624f4b0e3d6d1593b99e576854beec5949 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Tue, 6 May 2025 13:44:10 -0700 Subject: Chapter 23: Methods and Revisiting Types --- src/test/java/com/seaofnodes/simple/Chapter15Test.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/test/java/com/seaofnodes/simple/Chapter15Test.java') diff --git a/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/src/test/java/com/seaofnodes/simple/Chapter15Test.java index a98e62d8..6ba4e2b1 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter15Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter15Test.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import org.junit.Test; +import org.junit.Ignore; import static org.junit.Assert.*; public class Chapter15Test { @@ -49,7 +50,7 @@ output[i] = 1; return output; """); code.parse().opto(); - assertEquals("return [u8];", code.print()); + assertEquals("return []u8;", code.print()); assertEquals("\u0001", Eval2.eval(code, 0)); } @@ -101,8 +102,8 @@ A?[] !a = new A?[2]; return a; """); code.parse().opto(); - assertEquals("return [*A?];", code.print()); - assertEquals("*A {int !i; }?[ null,null]", Eval2.eval(code, 0)); + assertEquals("return []*A?;", code.print()); + assertEquals("*A {i64 !i; }?[ null,null]", Eval2.eval(code, 0)); } @Test @@ -174,7 +175,7 @@ return root; """); code.parse().opto(); assertEquals("return Tree;", code.print()); - assertEquals("Tree{_kids=*Tree?[ Tree{_kids=null},null]}", Eval2.eval(code, 0)); + assertEquals("Tree{_kids=*Tree {*[]*Tree?? !_kids; }?[ Tree{_kids=null},null]}", Eval2.eval(code, 0)); } @Test @@ -212,12 +213,12 @@ return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 assertEquals("1006", Eval2.eval(code, 4)); } - @Test + @Test @Ignore public void sieveOEratosthenes() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/sieve.smp")); CodeGen code = new CodeGen(src+"return sieve(arg);"); code.parse().opto(); - assertEquals("return [u32];", code.print()); + assertEquals("return []u32;", code.print()); assertEquals("u32[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20)); } @@ -254,9 +255,10 @@ return new flt; CodeGen code = new CodeGen( """ flt is = new int[2]; +return is; """); - try { code.parse().opto(); fail(); } - catch( Exception e ) { assertEquals("Type *[int] is not of declared type flt",e.getMessage()); } + try { code.parse().opto().typeCheck(); fail(); } + catch( Exception e ) { assertEquals("Type *[]i64 is not of declared type flt",e.getMessage()); } } @Test -- cgit v1.2.3