about summary refs log tree commit diff stats
path: root/js/baba-yaga/scratch/baba/test_utilities.baba
diff options
context:
space:
mode:
Diffstat (limited to 'js/baba-yaga/scratch/baba/test_utilities.baba')
-rw-r--r--js/baba-yaga/scratch/baba/test_utilities.baba106
1 files changed, 106 insertions, 0 deletions
diff --git a/js/baba-yaga/scratch/baba/test_utilities.baba b/js/baba-yaga/scratch/baba/test_utilities.baba
new file mode 100644
index 0000000..1245e8a
--- /dev/null
+++ b/js/baba-yaga/scratch/baba/test_utilities.baba
@@ -0,0 +1,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!";