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
|
// Test file for new utility functions
io.out "Testing new Baba Yaga utilities...";
io.out "";
// Test validate namespace
io.out "=== Testing validate.* functions ===";
io.out (validate.notEmpty "hello"); // true
io.out (validate.notEmpty ""); // false
io.out (validate.notEmpty [1, 2, 3]); // true
io.out (validate.notEmpty []); // false
io.out (validate.range 1 10 5); // true
io.out (validate.range 1 10 15); // false
io.out (validate.email "test@example.com"); // true
io.out (validate.email "invalid-email"); // false
io.out (validate.type "Int" 42); // true
io.out (validate.type "String" 42); // false
io.out "";
// Test text namespace
io.out "=== Testing text.* functions ===";
lines : text.lines "hello\nworld\ntest";
io.out lines; // ["hello", "world", "test"]
words : text.words "hello world test";
io.out words; // ["hello", "world", "test"]
io.out (text.padLeft 10 "hi"); // " hi"
io.out (text.padRight 10 "hi"); // "hi "
io.out "";
// Test utility functions
io.out "=== Testing utility functions ===";
numbers : [1, 2, 3, 4, 5, 6];
chunks : chunk numbers 2;
io.out chunks; // [[1, 2], [3, 4], [5, 6]]
rangeList : range 1 5;
io.out rangeList; // [1, 2, 3, 4, 5]
repeated : repeat 3 "hello";
io.out repeated; // ["hello", "hello", "hello"]
io.out "";
// Test sort namespace
io.out "=== Testing sort.by ===";
people : [
{name: "Alice", age: 30},
{name: "Bob", age: 25},
{name: "Charlie", age: 35}
];
sortedByAge : sort.by people (p -> p.age);
io.out sortedByAge;
io.out "";
// Test group namespace
io.out "=== Testing group.by ===";
grouped : group.by people (p -> p.age > 25);
io.out grouped;
io.out "";
// Test random namespace
io.out "=== Testing random.* functions ===";
testList : [1, 2, 3, 4, 5];
choice : random.choice testList;
io.out choice; // random element
shuffled : random.shuffle testList;
io.out shuffled; // shuffled version
randomNum : random.range 1 10;
io.out randomNum; // random number 1-10
io.out "";
// Test debug namespace
io.out "=== Testing debug functions ===";
testFunc : x -> x * 2;
debug.print testFunc;
debug.print people;
debug.print 42;
inspection : debug.inspect testFunc;
io.out inspection;
io.out "";
// Test assert function
io.out "=== Testing assert ===";
assert (2 + 2 = 4) "Math works!";
io.out "Assert passed - math works!";
// This should throw an error if uncommented:
// assert (2 + 2 = 5) "This will fail";
io.out "";
io.out "All utility tests completed successfully!";
|