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
|
/* Simple Unit Test: Embedded Functions in Tables */
/* ===== EMBEDDED ARROW FUNCTIONS ===== */
/* Table with simple arrow functions */
calculator : {
add: x y -> x + y,
multiply: x y -> x * y,
double: x -> x * 2,
square: x -> x * x
};
/* Test embedded arrow function calls */
add_result : calculator.add 5 3;
multiply_result : calculator.multiply 4 6;
double_result : calculator.double 7;
square_result : calculator.square 5;
..assert add_result = 8;
..assert multiply_result = 24;
..assert double_result = 14;
..assert square_result = 25;
/* Table with more complex arrow functions */
math_ops : {
increment: x -> x + 1,
decrement: x -> x - 1,
negate: x -> -x,
double: x -> x * 2
};
/* Test complex arrow functions */
inc_result : math_ops.increment 10;
dec_result : math_ops.decrement 10;
neg_result : math_ops.negate 5;
math_double : math_ops.double 7;
..assert inc_result = 11;
..assert dec_result = 9;
..assert neg_result = -5;
..assert math_double = 14;
/* ===== EMBEDDED WHEN EXPRESSIONS ===== */
/* Table with embedded when expressions */
classifier : {
classify: x -> when x is
0 then "zero"
1 then "one"
2 then "two"
_ then "other"
};
/* Test embedded when expressions */
zero_class : classifier.classify 0;
one_class : classifier.classify 1;
two_class : classifier.classify 2;
other_class : classifier.classify 42;
..assert zero_class = "zero";
..assert one_class = "one";
..assert two_class = "two";
..assert other_class = "other";
/* ===== MIXED CONTENT TABLES ===== */
/* Table with mixed data and functions */
person : {
name: "Alice",
age: 30,
city: "NYC",
greet: name -> "Hello, " + name
};
/* Test mixed table access */
name : person.name;
age : person.age;
greeting : person.greet "Bob";
..assert name = "Alice";
..assert age = 30;
..assert greeting = "Hello, Bob";
/* ===== EDGE CASES ===== */
/* Table with empty function */
empty_func : {
noop: x -> x
};
/* Test empty function */
noop_result : empty_func.noop 42;
..assert noop_result = 42;
/* Table with function that returns table */
table_returner : {
create_person: name age -> {name: name, age: age}
};
/* Test function that returns table */
new_person : table_returner.create_person "Bob" 25;
..assert new_person.name = "Bob";
..assert new_person.age = 25;
..out "Simple embedded functions test completed successfully";
|