summaryrefslogtreecommitdiff
path: root/chapter33/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'chapter33/src/test/java/com')
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java b/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java
index 99dc4452..b625f989 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java
@@ -3,6 +3,9 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.codegen.CodeGen;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.util.WorkList;
+import com.seaofnodes.simple.type.TypeInteger;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -41,4 +44,56 @@ public class Chapter33Test {
assertTrue(rewritten.isDead());
assertEquals("42",Eval2.eval(code,42));
}
+ // Reduced from Clock: the preceding qualified new used to leave only
+ // a sys placeholder, causing the parameter to stop at the first dot.
+ @Test public void testSourceQualifiedCanvasParameter() throws Exception {
+ Path out=Files.createTempDirectory(Files.createDirectories(Path.of("build/objs")),"canvas-source-");
+ CodeGen code=new CodeGen("src/main/smp",out.toString(),null,"Clock","""
+ val _survey_sys = sys;
+ val main = { -> new sys.draw.Canvas(320,240); };
+ val _draw = { sys.draw.Canvas screen -> screen.width; };
+ return 0;
+ """,456,true,TypeInteger.BOT);
+ code.driver(CodeGen.Phase.Parse);
+ }
+
+ @Test public void testQualifiedForwardTypeChain() {
+ CodeGen code=new CodeGen("""
+ val make={ -> new A.B.C.D(); };
+ val read={ A.B.C.D d -> d.x; };
+ A.B.C.D? saved=null;
+ struct A { struct B { struct C { struct D { int x=42; }; }; }; };
+ return read(make());
+ """).driver(CodeGen.Phase.TypeCheck);
+ assertEquals("42",Eval2.eval(code,0));
+ }
+
+ @Test public void testQualifiedTypeThroughOpenDefinition() {
+ CodeGen code=new CodeGen("""
+ struct A {
+ val make={ -> new A.B.C.D(); };
+ struct B { struct C { struct D { int x=42; }; }; };
+ };
+ return new A.make().x;
+ """).driver(CodeGen.Phase.TypeCheck);
+ assertEquals("42",Eval2.eval(code,0));
+ }
+
+ @Test public void testQualifiedExpressionIsMemberAccess() throws Exception {
+ Path root=Files.createTempDirectory(Files.createDirectories(Path.of("build/objs")),"qualified-expr-");
+ Files.createDirectories(root.resolve("sys/draw"));
+ Files.writeString(root.resolve("sys.smp"),"val draw=draw;");
+ Files.writeString(root.resolve("sys/draw.smp"),"val Canvas=Canvas;");
+ Files.writeString(root.resolve("sys/draw/Canvas.smp"),"int foo=42;");
+ CodeGen code=new CodeGen(root.toString(),root.resolve("obj").toString(),null,"Clock","""
+ val keep=sys;
+ sys.draw.Canvas.foo;
+ if( sys.draw.Canvas.foo ) return sys.draw.Canvas.foo;
+ return 0;
+ """,456,true,TypeInteger.BOT).driver(CodeGen.Phase.TypeCheck);
+ assertEquals("42",Eval2.eval(code,0));
+ for( String name : com.seaofnodes.simple.parser.Parser.TYPES.keySet() )
+ assertFalse("Expression lookahead created a type: "+name,name.endsWith(".foo"));
+ }
+
}