summaryrefslogtreecommitdiffhomepage
path: root/tests/02_runtime/04_switch_case
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-12-23 20:54:05 +0100
committerJo-Philipp Wich <jo@mein.io>2021-02-17 14:10:51 +0100
commit3756806674da909ec6dc10ad25862b592792604e (patch)
treef2af7e47f8444caaff0a5a33599f381889db24e3 /tests/02_runtime/04_switch_case
parent77580a893283f2bde7ab46496bd3a3d7b2fc6784 (diff)
treewide: rewrite ucode interpreter
Replace the former AST walking interpreter implementation with a single pass bytecode compiler and a corresponding virtual machine. The rewrite lays the groundwork for a couple of improvements with will be subsequently implemented: - Ability to precompile ucode sources into binary byte code - Strippable debug information - Reduced runtime memory usage Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/02_runtime/04_switch_case')
-rw-r--r--tests/02_runtime/04_switch_case48
1 files changed, 37 insertions, 11 deletions
diff --git a/tests/02_runtime/04_switch_case b/tests/02_runtime/04_switch_case
index 0de87dc..4c1fc57 100644
--- a/tests/02_runtime/04_switch_case
+++ b/tests/02_runtime/04_switch_case
@@ -84,7 +84,26 @@ default
-- End --
-4. Ensure that duplicate default cases emit a syntax
+4. Ensure that a single default case matches.
+
+-- Expect stdout --
+default
+default
+-- End --
+
+-- Testcase --
+{%
+ for (n in [1, 3]) {
+ switch (n) {
+ default:
+ print("default\n");
+ }
+ }
+%}
+-- End --
+
+
+5. Ensure that duplicate default cases emit a syntax
error during parsing.
-- Expect stderr --
@@ -95,6 +114,13 @@ In line 6, byte 3:
^-- Near here
+Syntax error: Expecting expression
+In line 8, byte 2:
+
+ ` }`
+ ^-- Near here
+
+
-- End --
-- Testcase --
@@ -110,7 +136,7 @@ In line 6, byte 3:
-- End --
-5. Ensure that case values use strict comparison.
+6. Ensure that case values use strict comparison.
-- Expect stdout --
b
@@ -142,7 +168,7 @@ b
-- End --
-6. Ensure that case values may be complex expressions.
+7. Ensure that case values may be complex expressions.
-- Expect stdout --
2, 3, 1
@@ -159,7 +185,7 @@ b
-- End --
-7. Ensure that empty switch statements are accepted by the
+8. Ensure that empty switch statements are accepted by the
parser and that the test expression is evaluated.
-- Expect stdout --
@@ -179,7 +205,7 @@ true
-- End --
-8. Ensure that `return` breaks out of switch statements.
+9. Ensure that `return` breaks out of switch statements.
-- Expect stdout --
one
@@ -207,7 +233,7 @@ two
-- End --
-9. Ensure that `continue` breaks out of switch statements.
+10. Ensure that `continue` breaks out of switch statements.
-- Expect stdout --
one
@@ -234,7 +260,7 @@ two
-- End --
-10. Ensure that exceptions break out of switch statements.
+11. Ensure that exceptions break out of switch statements.
-- Expect stdout --
one
@@ -242,11 +268,11 @@ one
-- Expect stderr --
Died
-In test(), line 6, byte 7:
- called from anonymous function ([stdin]:17:12)
+In test(), line 6, byte 8:
+ called from anonymous function ([stdin]:17:14)
` die();`
- Near here -----^
+ Near here ------^
-- End --
@@ -273,7 +299,7 @@ In test(), line 6, byte 7:
-- End --
-11. Ensure that consecutive cases values are properly handled.
+12. Ensure that consecutive cases values are properly handled.
-- Expect stdout --
three and four