From b3f15e1ddcd1c2d02c796048079474a3061a7afa Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 20 Jul 2019 01:33:42 -0400 Subject: [PATCH] lang: Add more tests for class and include --- .../TestAstFunc2/class-capture1.output | 1 + .../TestAstFunc2/class-capture1/main.mcl | 5 +++++ .../TestAstFunc2/class-capture2.output | 1 + .../TestAstFunc2/class-capture2/main.mcl | 5 +++++ .../TestAstFunc2/class-capture3.output | 1 + .../TestAstFunc2/class-capture3/main.mcl | 5 +++++ .../TestAstFunc2/class-capture4.output | 2 ++ .../TestAstFunc2/class-capture4/main.mcl | 7 +++++++ .../TestAstFunc2/class-capture5.output | 2 ++ .../TestAstFunc2/class-capture5/main.mcl | 7 +++++++ .../TestAstFunc2/class-capture6.output | 3 +++ .../TestAstFunc2/class-capture6/main.mcl | 12 ++++++++++++ .../TestAstFunc2/class-capture7.output | 1 + .../TestAstFunc2/class-capture7/main.mcl | 9 +++++++++ .../TestAstFunc2/class-capture8.output | 1 + .../TestAstFunc2/class-capture8/defs.mcl | 4 ++++ .../TestAstFunc2/class-capture8/main.mcl | 4 ++++ .../TestAstFunc2/class-recursion1.output | 1 + .../TestAstFunc2/class-recursion1/main.mcl | 6 ++++++ .../TestAstFunc2/class-recursion2.output | 1 + .../TestAstFunc2/class-recursion2/main.mcl | 9 +++++++++ .../TestAstFunc2/class-shadowing1.output | 1 + .../TestAstFunc2/class-shadowing1/main.mcl | 10 ++++++++++ .../TestAstFunc2/class-shadowing2.output | 1 + .../TestAstFunc2/class-shadowing2/main.mcl | 10 ++++++++++ .../TestAstFunc2/class-shadowing3.output | 2 ++ .../TestAstFunc2/class-shadowing3/main.mcl | 17 +++++++++++++++++ 27 files changed, 128 insertions(+) create mode 100644 lang/interpret_test/TestAstFunc2/class-capture1.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture1/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture2.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture2/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture3.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture3/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture4.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture4/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture5.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture5/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture6.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture6/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture7.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture7/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture8.output create mode 100644 lang/interpret_test/TestAstFunc2/class-capture8/defs.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-capture8/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-recursion1.output create mode 100644 lang/interpret_test/TestAstFunc2/class-recursion1/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-recursion2.output create mode 100644 lang/interpret_test/TestAstFunc2/class-recursion2/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-shadowing1.output create mode 100644 lang/interpret_test/TestAstFunc2/class-shadowing1/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-shadowing2.output create mode 100644 lang/interpret_test/TestAstFunc2/class-shadowing2/main.mcl create mode 100644 lang/interpret_test/TestAstFunc2/class-shadowing3.output create mode 100644 lang/interpret_test/TestAstFunc2/class-shadowing3/main.mcl diff --git a/lang/interpret_test/TestAstFunc2/class-capture1.output b/lang/interpret_test/TestAstFunc2/class-capture1.output new file mode 100644 index 00000000..7e2b993a --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture1.output @@ -0,0 +1 @@ +Vertex: test[t1] diff --git a/lang/interpret_test/TestAstFunc2/class-capture1/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture1/main.mcl new file mode 100644 index 00000000..b3abb6dd --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture1/main.mcl @@ -0,0 +1,5 @@ +$x1 = "t1" +class foo { + test $x1 {} +} +include foo diff --git a/lang/interpret_test/TestAstFunc2/class-capture2.output b/lang/interpret_test/TestAstFunc2/class-capture2.output new file mode 100644 index 00000000..7e2b993a --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture2.output @@ -0,0 +1 @@ +Vertex: test[t1] diff --git a/lang/interpret_test/TestAstFunc2/class-capture2/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture2/main.mcl new file mode 100644 index 00000000..f8a7c896 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture2/main.mcl @@ -0,0 +1,5 @@ +include foo +class foo { + test $x1 {} +} +$x1 = "t1" diff --git a/lang/interpret_test/TestAstFunc2/class-capture3.output b/lang/interpret_test/TestAstFunc2/class-capture3.output new file mode 100644 index 00000000..7e2b993a --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture3.output @@ -0,0 +1 @@ +Vertex: test[t1] diff --git a/lang/interpret_test/TestAstFunc2/class-capture3/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture3/main.mcl new file mode 100644 index 00000000..351fa365 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture3/main.mcl @@ -0,0 +1,5 @@ +$x1 = "bad1" +class foo($x1) { + test $x1 {} +} +include foo("t1") diff --git a/lang/interpret_test/TestAstFunc2/class-capture4.output b/lang/interpret_test/TestAstFunc2/class-capture4.output new file mode 100644 index 00000000..d13cb34b --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture4.output @@ -0,0 +1,2 @@ +Vertex: test[t1] +Vertex: test[t2] diff --git a/lang/interpret_test/TestAstFunc2/class-capture4/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture4/main.mcl new file mode 100644 index 00000000..ca67d3cf --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture4/main.mcl @@ -0,0 +1,7 @@ +$x1 = "t1" +class foo { + test $x1 {} + test $x2 {} +} +include foo +$x2 = "t2" diff --git a/lang/interpret_test/TestAstFunc2/class-capture5.output b/lang/interpret_test/TestAstFunc2/class-capture5.output new file mode 100644 index 00000000..6fc5c94b --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture5.output @@ -0,0 +1,2 @@ +Vertex: test[t1: t1] +Vertex: test[t2: t2] diff --git a/lang/interpret_test/TestAstFunc2/class-capture5/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture5/main.mcl new file mode 100644 index 00000000..70f928be --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture5/main.mcl @@ -0,0 +1,7 @@ +$x1 = "bad1" +class foo($x1, $x2) { + test "t1: " + $x2 {} # swapped + test "t2: " + $x1 {} +} +include foo($x2, "t1") +$x2 = "t2" diff --git a/lang/interpret_test/TestAstFunc2/class-capture6.output b/lang/interpret_test/TestAstFunc2/class-capture6.output new file mode 100644 index 00000000..6752e872 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture6.output @@ -0,0 +1,3 @@ +Vertex: test[t0: t0] +Vertex: test[t1: t1] +Vertex: test[t2: t2] diff --git a/lang/interpret_test/TestAstFunc2/class-capture6/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture6/main.mcl new file mode 100644 index 00000000..72ca5da1 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture6/main.mcl @@ -0,0 +1,12 @@ +$x1 = "bad1" +class foo($x1, $x2) { + include bar + test "t1: " + $x1 {} + test "t2: " + $x2 {} + class bar { + test "t0: " + $x0 {} + } +} +include foo("t1", $x2) +$x2 = "t2" +$x0 = "t0" diff --git a/lang/interpret_test/TestAstFunc2/class-capture7.output b/lang/interpret_test/TestAstFunc2/class-capture7.output new file mode 100644 index 00000000..81fe2e67 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture7.output @@ -0,0 +1 @@ +# err: err2: class `bar` does not exist in this scope diff --git a/lang/interpret_test/TestAstFunc2/class-capture7/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture7/main.mcl new file mode 100644 index 00000000..27ede4e7 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture7/main.mcl @@ -0,0 +1,9 @@ +class foo { + test "t1" {} + class bar { # unused definition + test "t0" {} + } +} +include foo +# This sort of thing is not currently supported, and not sure if it ever will. +include bar # nope! diff --git a/lang/interpret_test/TestAstFunc2/class-capture8.output b/lang/interpret_test/TestAstFunc2/class-capture8.output new file mode 100644 index 00000000..7e2b993a --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture8.output @@ -0,0 +1 @@ +Vertex: test[t1] diff --git a/lang/interpret_test/TestAstFunc2/class-capture8/defs.mcl b/lang/interpret_test/TestAstFunc2/class-capture8/defs.mcl new file mode 100644 index 00000000..35569259 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture8/defs.mcl @@ -0,0 +1,4 @@ +class foo { + test $x1 {} # capture the var +} +$x1 = "t1" diff --git a/lang/interpret_test/TestAstFunc2/class-capture8/main.mcl b/lang/interpret_test/TestAstFunc2/class-capture8/main.mcl new file mode 100644 index 00000000..c2343b9e --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-capture8/main.mcl @@ -0,0 +1,4 @@ +$x1 = "bad1" +include defs.foo + +import "defs.mcl" # out of order for fun diff --git a/lang/interpret_test/TestAstFunc2/class-recursion1.output b/lang/interpret_test/TestAstFunc2/class-recursion1.output new file mode 100644 index 00000000..59136c07 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-recursion1.output @@ -0,0 +1 @@ +# err: err2: recursive reference while setting scope: not a dag diff --git a/lang/interpret_test/TestAstFunc2/class-recursion1/main.mcl b/lang/interpret_test/TestAstFunc2/class-recursion1/main.mcl new file mode 100644 index 00000000..1c7e6d2f --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-recursion1/main.mcl @@ -0,0 +1,6 @@ +class c1 { + include c2 +} +class c2 { + include c1 +} diff --git a/lang/interpret_test/TestAstFunc2/class-recursion2.output b/lang/interpret_test/TestAstFunc2/class-recursion2.output new file mode 100644 index 00000000..59136c07 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-recursion2.output @@ -0,0 +1 @@ +# err: err2: recursive reference while setting scope: not a dag diff --git a/lang/interpret_test/TestAstFunc2/class-recursion2/main.mcl b/lang/interpret_test/TestAstFunc2/class-recursion2/main.mcl new file mode 100644 index 00000000..822aa7df --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-recursion2/main.mcl @@ -0,0 +1,9 @@ +class c1($cond) { + test "nope" {} + if $cond { + include c1(false) + } else { + test "done" {} + } +} +include c1(true) diff --git a/lang/interpret_test/TestAstFunc2/class-shadowing1.output b/lang/interpret_test/TestAstFunc2/class-shadowing1.output new file mode 100644 index 00000000..828b0896 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-shadowing1.output @@ -0,0 +1 @@ +Vertex: test[d] diff --git a/lang/interpret_test/TestAstFunc2/class-shadowing1/main.mcl b/lang/interpret_test/TestAstFunc2/class-shadowing1/main.mcl new file mode 100644 index 00000000..822a1925 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-shadowing1/main.mcl @@ -0,0 +1,10 @@ +$msg = "a" +class shadowme($msg) { + $msg = "c" + if true { + $msg = "d" # this is used! + test $msg {} + } +} + +include shadowme("b") diff --git a/lang/interpret_test/TestAstFunc2/class-shadowing2.output b/lang/interpret_test/TestAstFunc2/class-shadowing2.output new file mode 100644 index 00000000..af91b7d8 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-shadowing2.output @@ -0,0 +1 @@ +Vertex: test[c] diff --git a/lang/interpret_test/TestAstFunc2/class-shadowing2/main.mcl b/lang/interpret_test/TestAstFunc2/class-shadowing2/main.mcl new file mode 100644 index 00000000..63e3ad5e --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-shadowing2/main.mcl @@ -0,0 +1,10 @@ +$msg = "a" +class shadowme($msg) { + $msg = "c" + if true { + $msg = "d" + } + test $msg {} +} + +include shadowme("b") diff --git a/lang/interpret_test/TestAstFunc2/class-shadowing3.output b/lang/interpret_test/TestAstFunc2/class-shadowing3.output new file mode 100644 index 00000000..ccfda566 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-shadowing3.output @@ -0,0 +1,2 @@ +Vertex: test[a] +Vertex: test[hello] diff --git a/lang/interpret_test/TestAstFunc2/class-shadowing3/main.mcl b/lang/interpret_test/TestAstFunc2/class-shadowing3/main.mcl new file mode 100644 index 00000000..2e4eda4d --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/class-shadowing3/main.mcl @@ -0,0 +1,17 @@ +$foo = "a" + +class c1($cond) { + $foo = "b" # this var is NOT exported into the parent scope on include + if $cond { + $foo = "c" + } + test "hello" {} +} +include c1(true) + +# If the $foo did get exported from the `c1` scope, then the binding could +# change over time as `$cond` alternated between true and false. This would be +# error prone, and also require a higher-order FRP, which would add complexity +# but little value. + +test $foo {}