blob: 6d267b8d316bc08b98a8cd45eaee1ea96c909e3f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* Unit Test: Parser Limitations for Enhanced Case Statements */
/* Tests: Multi-value patterns with expressions, table access, function calls */
/* ======================================== */
/* MAIN BLOCKER: Multi-value patterns with expressions */
/* ======================================== */
/* Test 1: Basic multi-value with expressions in parentheses */
test_multi_expr : x y ->
when (x % 2) (y % 2) is
0 0 then "both even"
0 1 then "x even, y odd"
1 0 then "x odd, y even"
1 1 then "both odd";
/* Test 2: FizzBuzz-style multi-value patterns */
fizzbuzz_test : n ->
when (n % 3) (n % 5) is
0 0 then "FizzBuzz"
0 _ then "Fizz"
_ 0 then "Buzz"
_ _ then n;
/* Test 3: Complex expressions in multi-value patterns */
complex_multi : x y ->
when ((x + 1) % 2) ((y - 1) % 2) is
0 0 then "both transformed even"
0 1 then "x transformed even, y transformed odd"
1 0 then "x transformed odd, y transformed even"
1 1 then "both transformed odd";
/* Test 4: Function calls in multi-value patterns */
is_even : n -> n % 2 = 0;
is_positive : n -> n > 0;
test_func_multi : x y ->
when (is_even x) (is_positive y) is
true true then "x even and y positive"
true false then "x even and y not positive"
false true then "x odd and y positive"
false false then "x odd and y not positive";
/* ======================================== */
/* SECONDARY LIMITATIONS: Table access and function calls */
/* ======================================== */
/* Test 5: Table access in when expressions */
user : {role: "admin", level: 5};
test_table_access : u ->
when u.role is
"admin" then "admin user"
"user" then "regular user"
_ then "unknown role";
/* Test 6: Function calls in when expressions */
test_func_call : n ->
when (is_even n) is
true then "even number"
false then "odd number";
/* Test 7: Complex function calls in when expressions */
complex_func : n -> (n % 3 = 0) and (n % 5 = 0);
test_complex_func : n ->
when (complex_func n) is
true then "divisible by both 3 and 5"
false then "not divisible by both";
/* ======================================== */
/* CONTROL TESTS: Should work with current parser */
/* ======================================== */
/* Test 8: Simple value matching (control) */
test_simple : n ->
when n is
0 then "zero"
1 then "one"
_ then "other";
/* Test 9: Single complex expressions with parentheses (control) */
test_single_expr : n ->
when (n % 3) is
0 then "divisible by 3"
_ then "not divisible by 3";
/* Test 10: Multiple simple values (control) */
test_multi_simple : x y ->
when x y is
0 0 then "both zero"
0 _ then "x zero"
_ 0 then "y zero"
_ _ then "neither zero";
/* ======================================== */
/* TEST EXECUTION */
/* ======================================== */
/* Execute tests that should work */
result1 : test_simple 5;
result2 : test_single_expr 15;
result3 : test_multi_simple 0 5;
/* These should fail with current parser */
result4 : test_multi_expr 4 6; /* Should return "both even" */
result5 : fizzbuzz_test 15; /* Should return "FizzBuzz" */
result6 : test_table_access user; /* Should return "admin user" */
result7 : test_func_call 4; /* Should return "even number" */
/* Output results */
..out result1;
..out result2;
..out result3;
..out result4;
..out result5;
..out result6;
..out result7;
|