about summary refs log tree commit diff stats
path: root/js/scripting-lang/tests/integration_02_pattern_matching.txt
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/tests/integration_02_pattern_matching.txt')
-rw-r--r--js/scripting-lang/tests/integration_02_pattern_matching.txt64
1 files changed, 64 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/integration_02_pattern_matching.txt b/js/scripting-lang/tests/integration_02_pattern_matching.txt
new file mode 100644
index 0000000..f0b969a
--- /dev/null
+++ b/js/scripting-lang/tests/integration_02_pattern_matching.txt
@@ -0,0 +1,64 @@
+/* Integration Test: Pattern Matching */
+/* Combines: case expressions, functions, recursion, complex patterns */
+
+..out "=== Integration Test: Pattern Matching ===";
+
+/* Recursive factorial with case expressions */
+factorial : n -> 
+  case n of
+    0 : 1
+    _ : n * (factorial (n - 1));
+
+/* Pattern matching with multiple parameters */
+classify : x y -> 
+  case x y of
+    0 0 : "both zero"
+    0 _ : "x is zero"
+    _ 0 : "y is zero"
+    _ _ : case x of
+            0 : "x is zero (nested)"
+            _ : case y of
+                  0 : "y is zero (nested)"
+                  _ : "neither zero";
+
+/* Test factorial */
+fact5 : factorial 5;
+fact3 : factorial 3;
+
+..assert fact5 = 120;
+..assert fact3 = 6;
+
+/* Test classification */
+test1 : classify 0 0;
+test2 : classify 0 5;
+test3 : classify 5 0;
+test4 : classify 5 5;
+
+..assert test1 = "both zero";
+..assert test2 = "x is zero";
+..assert test3 = "y is zero";
+..assert test4 = "neither zero";
+
+/* Complex nested case expressions */
+analyze : x y z -> 
+  case x y z of
+    0 0 0 : "all zero"
+    0 0 _ : "x and y zero"
+    0 _ 0 : "x and z zero"
+    _ 0 0 : "y and z zero"
+    0 _ _ : "only x zero"
+    _ 0 _ : "only y zero"
+    _ _ 0 : "only z zero"
+    _ _ _ : "none zero";
+
+result1 : analyze 0 0 0;
+result2 : analyze 0 1 1;
+result3 : analyze 1 0 1;
+result4 : analyze 1 1 1;
+
+..assert result1 = "all zero";
+..assert result2 = "only x zero";
+..assert result3 = "only y zero";
+..assert result4 = "none zero";
+
+..out "Pattern matching integration test completed"; 
\ No newline at end of file