MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

migrate from Ant.println to console.(func)

+1728 -1603
+1 -4
include/modules/io.h
··· 1 1 #ifndef IO_H 2 2 #define IO_H 3 3 4 - #include "ant.h" 5 - 6 - // Ant.println(...) 7 - jsval_t js_println(struct js *js, jsval_t *args, int nargs); 4 + void init_console_module(); 8 5 9 6 #endif
+1 -1
include/runtime.h
··· 9 9 int crypto_initialized; 10 10 }; 11 11 12 - struct ant_runtime *ant_runtime(void); 12 + extern struct ant_runtime *const rt; 13 13 struct ant_runtime *ant_runtime_init(struct js *js); 14 14 15 15 #endif
+53
src/ant.c
··· 9 9 #include <stdio.h> 10 10 #include <stdlib.h> 11 11 #include <string.h> 12 + #include <sys/time.h> 13 + #include <time.h> 12 14 13 15 #include "ant.h" 14 16 #include "config.h" ··· 178 180 static jsval_t builtin_promise_then(struct js *js, jsval_t *args, int nargs); 179 181 static jsval_t builtin_promise_catch(struct js *js, jsval_t *args, int nargs); 180 182 static jsval_t builtin_promise_finally(struct js *js, jsval_t *args, int nargs); 183 + static jsval_t builtin_Date(struct js *js, jsval_t *args, int nargs); 184 + static jsval_t builtin_Date_now(struct js *js, jsval_t *args, int nargs); 181 185 182 186 static void setlwm(struct js *js) { 183 187 jsoff_t n = 0, css = 0; ··· 3673 3677 return regexp_obj; 3674 3678 } 3675 3679 3680 + static jsval_t builtin_Date(struct js *js, jsval_t *args, int nargs) { 3681 + jsval_t date_obj = js->this_val; 3682 + bool use_this = (vtype(date_obj) == T_OBJ); 3683 + 3684 + if (!use_this) { 3685 + date_obj = mkobj(js, 0); 3686 + } 3687 + 3688 + double timestamp_ms; 3689 + 3690 + if (nargs == 0) { 3691 + struct timeval tv; 3692 + gettimeofday(&tv, NULL); 3693 + timestamp_ms = (double)tv.tv_sec * 1000.0 + (double)tv.tv_usec / 1000.0; 3694 + } else if (nargs == 1) { 3695 + if (vtype(args[0]) == T_NUM) { 3696 + timestamp_ms = tod(args[0]); 3697 + } else if (vtype(args[0]) == T_STR) { 3698 + timestamp_ms = 0; 3699 + } else { 3700 + timestamp_ms = 0; 3701 + } 3702 + } else { 3703 + timestamp_ms = 0; 3704 + } 3705 + 3706 + jsval_t time_key = js_mkstr(js, "__time", 6); 3707 + jsval_t time_val = tov(timestamp_ms); 3708 + setprop(js, date_obj, time_key, time_val); 3709 + 3710 + return date_obj; 3711 + } 3712 + 3713 + static jsval_t builtin_Date_now(struct js *js, jsval_t *args, int nargs) { 3714 + (void) args; 3715 + (void) nargs; 3716 + 3717 + struct timeval tv; 3718 + gettimeofday(&tv, NULL); 3719 + double timestamp_ms = (double)tv.tv_sec * 1000.0 + (double)tv.tv_usec / 1000.0; 3720 + 3721 + return tov(timestamp_ms); 3722 + } 3723 + 3676 3724 static jsval_t builtin_object_keys(struct js *js, jsval_t *args, int nargs) { 3677 3725 if (nargs == 0) return mkarr(js); 3678 3726 jsval_t obj = args[0]; ··· 4715 4763 setprop(js, glob, js_mkstr(js, "Array", 5), js_mkfun(builtin_Array)); 4716 4764 setprop(js, glob, js_mkstr(js, "Error", 5), js_mkfun(builtin_Error)); 4717 4765 setprop(js, glob, js_mkstr(js, "RegExp", 6), js_mkfun(builtin_RegExp)); 4766 + 4767 + jsval_t date_ctor_obj = mkobj(js, 0); 4768 + setprop(js, date_ctor_obj, js_mkstr(js, "__native_func", 13), js_mkfun(builtin_Date)); 4769 + setprop(js, date_ctor_obj, js_mkstr(js, "now", 3), js_mkfun(builtin_Date_now)); 4770 + setprop(js, glob, js_mkstr(js, "Date", 4), mkval(T_FUNC, vdata(date_ctor_obj))); 4718 4771 4719 4772 jsval_t p_proto = js_mkobj(js); 4720 4773 setprop(js, p_proto, js_mkstr(js, "then", 4), js_mkfun(builtin_promise_then));
+2 -2
src/main.c
··· 239 239 240 240 struct ant_runtime *rt = ant_runtime_init(js); 241 241 242 + init_console_module(); 242 243 init_crypto_module(js, rt->ant_obj); 243 244 init_timer_module(js, rt->ant_obj); 244 245 245 246 js_set(js, rt->ant_obj, "serve", js_mkfun(js_serve)); 246 - js_set(js, rt->ant_obj, "println", js_mkfun(js_println)); 247 247 js_set(js, rt->ant_obj, "require", js_mkfun(js_require)); 248 248 js_set(js, rt->ant_obj, "signal", js_mkfun(js_signal)); 249 - 249 + 250 250 jsval_t exports_obj = js_mkobj(js); 251 251 js_set(js, rt->ant_obj, "exports", exports_obj); 252 252
+35 -4
src/modules/io.c
··· 7 7 #include "runtime.h" 8 8 #include "modules/io.h" 9 9 10 - jsval_t js_println(struct js *js, jsval_t *args, int nargs) { 10 + #define ANSI_RED "\x1b[31m" 11 + #define ANSI_YELLOW "\x1b[33m" 12 + #define ANSI_RESET "\x1b[0m" 13 + 14 + static void console_print(struct js *js, jsval_t *args, int nargs, const char *color, FILE *stream) { 15 + if (color) fprintf(stream, "%s", color); 16 + 11 17 for (int i = 0; i < nargs; i++) { 12 18 const char *space = i == 0 ? "" : " "; 13 19 14 20 if (js_type(args[i]) == JS_STR) { 15 21 char *str = js_getstr(js, args[i], NULL); 16 - printf("%s%s", space, str); 22 + fprintf(stream, "%s%s", space, str); 17 23 } else { 18 - printf("%s%s", space, js_str(js, args[i])); 24 + fprintf(stream, "%s%s", space, js_str(js, args[i])); 19 25 } 20 26 } 21 27 22 - putchar('\n'); 28 + if (color) fprintf(stream, "%s", ANSI_RESET); 29 + fputc('\n', stream); 30 + } 31 + 32 + static jsval_t js_console_log(struct js *js, jsval_t *args, int nargs) { 33 + console_print(js, args, nargs, NULL, stdout); 34 + return js_mkundef(); 35 + } 36 + 37 + static jsval_t js_console_error(struct js *js, jsval_t *args, int nargs) { 38 + console_print(js, args, nargs, ANSI_RED, stderr); 23 39 return js_mkundef(); 40 + } 41 + 42 + static jsval_t js_console_warn(struct js *js, jsval_t *args, int nargs) { 43 + console_print(js, args, nargs, ANSI_YELLOW, stderr); 44 + return js_mkundef(); 45 + } 46 + 47 + void init_console_module() { 48 + struct js *js = rt->js; 49 + jsval_t console_obj = js_mkobj(js); 50 + 51 + js_set(js, js_glob(js), "console", console_obj); 52 + js_set(js, console_obj, "log", js_mkfun(js_console_log)); 53 + js_set(js, console_obj, "error", js_mkfun(js_console_error)); 54 + js_set(js, console_obj, "warn", js_mkfun(js_console_warn)); 24 55 }
+1 -7
src/runtime.c
··· 4 4 5 5 static struct ant_runtime runtime = {0}; 6 6 7 - struct ant_runtime *ant_runtime(void) { 8 - if (runtime.js == NULL) { 9 - fprintf(stderr, "Ant runtime not initialized!\n"); 10 - abort(); 11 - } 12 - return &runtime; 13 - } 7 + struct ant_runtime *const rt = &runtime; 14 8 15 9 struct ant_runtime *ant_runtime_init(struct js *js) { 16 10 runtime.js = js;
+1 -1
tests/analyze_closure.cjs
··· 9 9 } 10 10 11 11 let fn = outer(); 12 - Ant.println("Result: " + fn()); 12 + console.log("Result: " + fn());
+93 -93
tests/array_methods.cjs
··· 1 1 // Test Array methods functionality 2 2 3 - Ant.println("=== Array Methods Tests ===\n"); 3 + console.log("=== Array Methods Tests ===\n"); 4 4 5 5 // Test 1: push and pop (existing) 6 - Ant.println("Test 1: push() and pop()"); 6 + console.log("Test 1: push() and pop()"); 7 7 let arr1 = [1, 2, 3]; 8 - Ant.println(" Initial:", arr1); 8 + console.log(" Initial:", arr1); 9 9 arr1.push(4); 10 - Ant.println(" After push(4):", arr1); 10 + console.log(" After push(4):", arr1); 11 11 arr1.push(5, 6); 12 - Ant.println(" After push(5, 6):", arr1); 12 + console.log(" After push(5, 6):", arr1); 13 13 let popped = arr1.pop(); 14 - Ant.println(" Popped value:", popped); 15 - Ant.println(" After pop():", arr1); 14 + console.log(" Popped value:", popped); 15 + console.log(" After pop():", arr1); 16 16 17 17 // Test 2: slice 18 - Ant.println("\nTest 2: slice()"); 18 + console.log("\nTest 2: slice()"); 19 19 let arr2 = [10, 20, 30, 40, 50]; 20 - Ant.println(" Original:", arr2); 21 - Ant.println(" slice(1, 3):", arr2.slice(1, 3)); 22 - Ant.println(" slice(2):", arr2.slice(2)); 23 - Ant.println(" slice(-2):", arr2.slice(-2)); 24 - Ant.println(" slice(0, -2):", arr2.slice(0, -2)); 25 - Ant.println(" slice(-4, -1):", arr2.slice(-4, -1)); 26 - Ant.println(" Original unchanged:", arr2); 20 + console.log(" Original:", arr2); 21 + console.log(" slice(1, 3):", arr2.slice(1, 3)); 22 + console.log(" slice(2):", arr2.slice(2)); 23 + console.log(" slice(-2):", arr2.slice(-2)); 24 + console.log(" slice(0, -2):", arr2.slice(0, -2)); 25 + console.log(" slice(-4, -1):", arr2.slice(-4, -1)); 26 + console.log(" Original unchanged:", arr2); 27 27 28 28 // Test 3: join 29 - Ant.println("\nTest 3: join()"); 29 + console.log("\nTest 3: join()"); 30 30 let arr3 = ["apple", "banana", "cherry"]; 31 - Ant.println(" Array:", arr3); 32 - Ant.println(" join(', '):", arr3.join(", ")); 33 - Ant.println(" join(' - '):", arr3.join(" - ")); 34 - Ant.println(" join(''):", arr3.join("")); 35 - Ant.println(" join():", arr3.join()); 31 + console.log(" Array:", arr3); 32 + console.log(" join(', '):", arr3.join(", ")); 33 + console.log(" join(' - '):", arr3.join(" - ")); 34 + console.log(" join(''):", arr3.join("")); 35 + console.log(" join():", arr3.join()); 36 36 37 37 let numbers = [1, 2, 3, 4, 5]; 38 - Ant.println(" Numbers:", numbers); 39 - Ant.println(" join('-'):", numbers.join("-")); 38 + console.log(" Numbers:", numbers); 39 + console.log(" join('-'):", numbers.join("-")); 40 40 41 41 // Test 4: includes 42 - Ant.println("\nTest 4: includes()"); 42 + console.log("\nTest 4: includes()"); 43 43 let arr4 = [1, 2, 3, 4, 5]; 44 - Ant.println(" Array:", arr4); 45 - Ant.println(" includes(3):", arr4.includes(3)); 46 - Ant.println(" includes(6):", arr4.includes(6)); 47 - Ant.println(" includes(1):", arr4.includes(1)); 48 - Ant.println(" includes(5):", arr4.includes(5)); 49 - Ant.println(" includes(0):", arr4.includes(0)); 44 + console.log(" Array:", arr4); 45 + console.log(" includes(3):", arr4.includes(3)); 46 + console.log(" includes(6):", arr4.includes(6)); 47 + console.log(" includes(1):", arr4.includes(1)); 48 + console.log(" includes(5):", arr4.includes(5)); 49 + console.log(" includes(0):", arr4.includes(0)); 50 50 51 51 // Test 5: includes with different types 52 - Ant.println("\nTest 5: includes() with different types"); 52 + console.log("\nTest 5: includes() with different types"); 53 53 let mixed = [1, "hello", true, false, 42]; 54 - Ant.println(" Array:", mixed); 55 - Ant.println(" includes(1):", mixed.includes(1)); 56 - Ant.println(" includes('hello'):", mixed.includes("hello")); 57 - Ant.println(" includes('Hello'):", mixed.includes("Hello")); 58 - Ant.println(" includes(true):", mixed.includes(true)); 59 - Ant.println(" includes(false):", mixed.includes(false)); 60 - Ant.println(" includes(42):", mixed.includes(42)); 61 - Ant.println(" includes(0):", mixed.includes(0)); 54 + console.log(" Array:", mixed); 55 + console.log(" includes(1):", mixed.includes(1)); 56 + console.log(" includes('hello'):", mixed.includes("hello")); 57 + console.log(" includes('Hello'):", mixed.includes("Hello")); 58 + console.log(" includes(true):", mixed.includes(true)); 59 + console.log(" includes(false):", mixed.includes(false)); 60 + console.log(" includes(42):", mixed.includes(42)); 61 + console.log(" includes(0):", mixed.includes(0)); 62 62 63 63 // Test 6: Combining methods 64 - Ant.println("\nTest 6: Combining array methods"); 64 + console.log("\nTest 6: Combining array methods"); 65 65 let data = [10, 20, 30, 40, 50, 60, 70]; 66 - Ant.println(" Original:", data); 66 + console.log(" Original:", data); 67 67 let subset = data.slice(2, 5); 68 - Ant.println(" slice(2, 5):", subset); 69 - Ant.println(" Joined:", subset.join(" -> ")); 70 - Ant.println(" includes(40):", subset.includes(40)); 71 - Ant.println(" includes(10):", subset.includes(10)); 68 + console.log(" slice(2, 5):", subset); 69 + console.log(" Joined:", subset.join(" -> ")); 70 + console.log(" includes(40):", subset.includes(40)); 71 + console.log(" includes(10):", subset.includes(10)); 72 72 73 73 // Test 7: Building CSV 74 - Ant.println("\nTest 7: Building CSV"); 74 + console.log("\nTest 7: Building CSV"); 75 75 let headers = ["Name", "Age", "City"]; 76 76 let row1 = ["Alice", "25", "NYC"]; 77 77 let row2 = ["Bob", "30", "LA"]; 78 - Ant.println(" " + headers.join(",")); 79 - Ant.println(" " + row1.join(",")); 80 - Ant.println(" " + row2.join(",")); 78 + console.log(" " + headers.join(",")); 79 + console.log(" " + row1.join(",")); 80 + console.log(" " + row2.join(",")); 81 81 82 82 // Test 8: Array manipulation 83 - Ant.println("\nTest 8: Array manipulation"); 83 + console.log("\nTest 8: Array manipulation"); 84 84 let queue = []; 85 - Ant.println(" Initial queue:", queue); 85 + console.log(" Initial queue:", queue); 86 86 queue.push("task1"); 87 87 queue.push("task2"); 88 88 queue.push("task3"); 89 - Ant.println(" After adding tasks:", queue); 89 + console.log(" After adding tasks:", queue); 90 90 let first = queue.slice(0, 1); 91 - Ant.println(" First task:", first); 91 + console.log(" First task:", first); 92 92 let remaining = queue.slice(1); 93 - Ant.println(" Remaining:", remaining); 93 + console.log(" Remaining:", remaining); 94 94 95 95 // Test 9: Finding elements 96 - Ant.println("\nTest 9: Finding elements"); 96 + console.log("\nTest 9: Finding elements"); 97 97 let items = ["apple", "banana", "cherry", "date"]; 98 - Ant.println(" Items:", items); 98 + console.log(" Items:", items); 99 99 if (items.includes("banana")) { 100 - Ant.println(" Found 'banana' in the list"); 100 + console.log(" Found 'banana' in the list"); 101 101 } 102 102 if (!items.includes("grape")) { 103 - Ant.println(" 'grape' not found in the list"); 103 + console.log(" 'grape' not found in the list"); 104 104 } 105 105 106 106 // Test 10: Slice for copy 107 - Ant.println("\nTest 10: Copying array with slice"); 107 + console.log("\nTest 10: Copying array with slice"); 108 108 let original = [1, 2, 3, 4, 5]; 109 109 let copy = original.slice(); 110 - Ant.println(" Original:", original); 111 - Ant.println(" Copy:", copy); 110 + console.log(" Original:", original); 111 + console.log(" Copy:", copy); 112 112 copy.push(6); 113 - Ant.println(" After push to copy:", copy); 114 - Ant.println(" Original unchanged:", original); 113 + console.log(" After push to copy:", copy); 114 + console.log(" Original unchanged:", original); 115 115 116 116 // Test 11: Working with ranges 117 - Ant.println("\nTest 11: Working with ranges"); 117 + console.log("\nTest 11: Working with ranges"); 118 118 let range = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 119 - Ant.println(" Full range:", range); 120 - Ant.println(" First 3:", range.slice(0, 3)); 121 - Ant.println(" Last 3:", range.slice(-3)); 122 - Ant.println(" Middle:", range.slice(3, 7)); 119 + console.log(" Full range:", range); 120 + console.log(" First 3:", range.slice(0, 3)); 121 + console.log(" Last 3:", range.slice(-3)); 122 + console.log(" Middle:", range.slice(3, 7)); 123 123 124 124 // Test 12: Edge cases 125 - Ant.println("\nTest 12: Edge cases"); 125 + console.log("\nTest 12: Edge cases"); 126 126 let empty = []; 127 - Ant.println(" Empty array:", empty); 128 - Ant.println(" slice():", empty.slice()); 129 - Ant.println(" join(','):", "'" + empty.join(",") + "'"); 130 - Ant.println(" includes(1):", empty.includes(1)); 127 + console.log(" Empty array:", empty); 128 + console.log(" slice():", empty.slice()); 129 + console.log(" join(','):", "'" + empty.join(",") + "'"); 130 + console.log(" includes(1):", empty.includes(1)); 131 131 let popped_empty = empty.pop(); 132 - Ant.println(" pop() on empty:", popped_empty); 132 + console.log(" pop() on empty:", popped_empty); 133 133 134 134 let single = [42]; 135 - Ant.println(" Single element [42]:"); 136 - Ant.println(" slice():", single.slice()); 137 - Ant.println(" join():", single.join(",")); 138 - Ant.println(" includes(42):", single.includes(42)); 139 - Ant.println(" includes(0):", single.includes(0)); 135 + console.log(" Single element [42]:"); 136 + console.log(" slice():", single.slice()); 137 + console.log(" join():", single.join(",")); 138 + console.log(" includes(42):", single.includes(42)); 139 + console.log(" includes(0):", single.includes(0)); 140 140 141 141 // Test 13: Practical example - path segments 142 - Ant.println("\nTest 13: Path processing"); 142 + console.log("\nTest 13: Path processing"); 143 143 let pathSegments = ["home", "user", "documents", "file.txt"]; 144 - Ant.println(" Segments:", pathSegments); 144 + console.log(" Segments:", pathSegments); 145 145 let path = "/" + pathSegments.join("/"); 146 - Ant.println(" Path:", path); 146 + console.log(" Path:", path); 147 147 let filename = pathSegments.slice(-1); 148 - Ant.println(" Filename:", filename); 148 + console.log(" Filename:", filename); 149 149 let directory = pathSegments.slice(0, -1); 150 - Ant.println(" Directory parts:", directory); 150 + console.log(" Directory parts:", directory); 151 151 152 152 // Test 14: Data filtering (manual) 153 - Ant.println("\nTest 14: Manual filtering"); 153 + console.log("\nTest 14: Manual filtering"); 154 154 let scores = [85, 92, 78, 95, 88, 73, 91]; 155 - Ant.println(" All scores:", scores); 155 + console.log(" All scores:", scores); 156 156 let highScores = []; 157 157 for (let i = 0; i < scores.length; i++) { 158 158 if (scores[i] >= 90) { 159 159 highScores.push(scores[i]); 160 160 } 161 161 } 162 - Ant.println(" High scores (>= 90):", highScores); 163 - Ant.println(" Joined:", highScores.join(", ")); 162 + console.log(" High scores (>= 90):", highScores); 163 + console.log(" Joined:", highScores.join(", ")); 164 164 165 165 // Test 15: Checking membership 166 - Ant.println("\nTest 15: Membership checking"); 166 + console.log("\nTest 15: Membership checking"); 167 167 let allowedUsers = ["admin", "user1", "user2", "guest"]; 168 168 let username = "user1"; 169 - Ant.println(" Allowed users:", allowedUsers); 170 - Ant.println(" Check '" + username + "':", allowedUsers.includes(username)); 169 + console.log(" Allowed users:", allowedUsers); 170 + console.log(" Check '" + username + "':", allowedUsers.includes(username)); 171 171 username = "hacker"; 172 - Ant.println(" Check '" + username + "':", allowedUsers.includes(username)); 172 + console.log(" Check '" + username + "':", allowedUsers.includes(username)); 173 173 174 - Ant.println("\n=== All tests completed ==="); 174 + console.log("\n=== All tests completed ===");
+34 -34
tests/arrays.cjs
··· 1 1 // Array literal tests 2 2 let arr = [1, 2, 3]; 3 - Ant.println(arr); 3 + console.log(arr); 4 4 5 5 // Array indexing 6 6 let first = arr[0]; 7 7 let second = arr[1]; 8 8 let third = arr[2]; 9 - Ant.println(first); 10 - Ant.println(second); 11 - Ant.println(third); 9 + console.log(first); 10 + console.log(second); 11 + console.log(third); 12 12 13 13 // Array length 14 - Ant.println(arr.length); 14 + console.log(arr.length); 15 15 16 16 // Empty array 17 17 let empty = []; 18 - Ant.println(empty); 19 - Ant.println(empty.length); 18 + console.log(empty); 19 + console.log(empty.length); 20 20 21 21 // Array with mixed types 22 22 let mixed = [1, "hello", true, null]; 23 - Ant.println(mixed); 23 + console.log(mixed); 24 24 25 25 // Array assignment 26 26 arr[0] = 10; 27 - Ant.println(arr); 27 + console.log(arr); 28 28 29 29 // Push method 30 30 arr.push(4); 31 - Ant.println(arr); 32 - Ant.println(arr.length); 31 + console.log(arr); 32 + console.log(arr.length); 33 33 34 34 arr.push(5, 6); 35 - Ant.println(arr); 36 - Ant.println(arr.length); 35 + console.log(arr); 36 + console.log(arr.length); 37 37 38 38 // Pop method 39 39 let popped = arr.pop(); 40 - Ant.println(popped); 41 - Ant.println(arr); 42 - Ant.println(arr.length); 40 + console.log(popped); 41 + console.log(arr); 42 + console.log(arr.length); 43 43 44 44 // Nested arrays 45 45 let nested = [[1, 2], [3, 4]]; 46 - Ant.println(nested); 47 - Ant.println(nested[0]); 48 - Ant.println(nested[0][0]); 49 - Ant.println(nested[1][1]); 46 + console.log(nested); 47 + console.log(nested[0]); 48 + console.log(nested[0][0]); 49 + console.log(nested[1][1]); 50 50 51 51 // Array constructor 52 52 let arr2 = Array(3); 53 - Ant.println(arr2); 54 - Ant.println(arr2.length); 53 + console.log(arr2); 54 + console.log(arr2.length); 55 55 56 56 // Array constructor with elements 57 57 let arr3 = Array(10, 20, 30); 58 - Ant.println(arr3); 59 - Ant.println(arr3.length); 58 + console.log(arr3); 59 + console.log(arr3.length); 60 60 61 61 // Dynamic array creation 62 62 let dynamic = []; 63 63 dynamic[0] = "a"; 64 64 dynamic[1] = "b"; 65 65 dynamic[2] = "c"; 66 - Ant.println(dynamic); 66 + console.log(dynamic); 67 67 68 68 // instanceof Array 69 - Ant.println(arr instanceof Array); 70 - Ant.println(mixed instanceof Array); 71 - Ant.println({} instanceof Array); 72 - Ant.println(5 instanceof Array); 69 + console.log(arr instanceof Array); 70 + console.log(mixed instanceof Array); 71 + console.log({} instanceof Array); 72 + console.log(5 instanceof Array); 73 73 74 74 // Bracket notation with string keys (object-like) 75 75 let obj = [1, 2, 3]; 76 76 obj["foo"] = "bar"; 77 - Ant.println(obj.foo); 77 + console.log(obj.foo); 78 78 79 79 // Array iteration with for loop 80 80 let sum = 0; 81 81 for (let i = 0; i < arr.length; i = i + 1) { 82 82 sum = sum + arr[i]; 83 83 } 84 - Ant.println(sum); 84 + console.log(sum); 85 85 86 86 // Array of arrays 87 87 let matrix = []; 88 88 matrix[0] = [1, 2, 3]; 89 89 matrix[1] = [4, 5, 6]; 90 - Ant.println(matrix); 91 - Ant.println(matrix[0][1]); 92 - Ant.println(matrix[1][2]); 90 + console.log(matrix); 91 + console.log(matrix[0][1]); 92 + console.log(matrix[1][2]);
+21 -21
tests/arrow_functions.cjs
··· 1 1 // Test 1: Basic arrow function with two parameters and expression body 2 2 let add = (a, b) => a + b; 3 3 let result1 = add(5, 3); 4 - Ant.println("Test 1 - add(5, 3):", result1); // Should be 8 4 + console.log("Test 1 - add(5, 3):", result1); // Should be 8 5 5 6 6 // Test 2: Arrow function with single parameter (no parentheses) 7 7 let double = x => x * 2; 8 8 let result2 = double(7); 9 - Ant.println("Test 2 - double(7):", result2); // Should be 14 9 + console.log("Test 2 - double(7):", result2); // Should be 14 10 10 11 11 // Test 3: Arrow function with block body 12 12 let multiply = (a, b) => { ··· 14 14 return result; 15 15 }; 16 16 let result3 = multiply(4, 6); 17 - Ant.println("Test 3 - multiply(4, 6):", result3); // Should be 24 17 + console.log("Test 3 - multiply(4, 6):", result3); // Should be 24 18 18 19 19 // Test 4: Arrow function with no parameters 20 20 let getFortyTwo = () => 42; 21 21 let result4 = getFortyTwo(); 22 - Ant.println("Test 4 - getFortyTwo():", result4); // Should be 42 22 + console.log("Test 4 - getFortyTwo():", result4); // Should be 42 23 23 24 24 // Test 5: Arrow function with single expression 25 25 let square = x => x * x; 26 26 let result5 = square(5); 27 - Ant.println("Test 5 - square(5):", result5); // Should be 25 27 + console.log("Test 5 - square(5):", result5); // Should be 25 28 28 29 29 // Test 6: Nested arrow functions (currying) 30 30 let makeAdder = x => y => x + y; 31 31 let add5 = makeAdder(5); 32 32 let result6 = add5(3); 33 - Ant.println("Test 6 - makeAdder(5)(3):", result6); // Should be 8 33 + console.log("Test 6 - makeAdder(5)(3):", result6); // Should be 8 34 34 35 35 // Test 7: Arrow function with multiple statements in block 36 36 let complexCalc = (a, b) => { ··· 40 40 return result; 41 41 }; 42 42 let result7 = complexCalc(3, 4); 43 - Ant.println("Test 7 - complexCalc(3, 4):", result7); // Should be 19 (7 + 12) 43 + console.log("Test 7 - complexCalc(3, 4):", result7); // Should be 19 (7 + 12) 44 44 45 45 // Test 8: Arrow function with conditional 46 46 let max = (a, b) => { ··· 51 51 } 52 52 }; 53 53 let result8 = max(10, 15); 54 - Ant.println("Test 8 - max(10, 15):", result8); // Should be 15 54 + console.log("Test 8 - max(10, 15):", result8); // Should be 15 55 55 56 56 // Test 9: Arrow function with string concatenation 57 57 let greet = name => "Hello, " + name; 58 58 let result9 = greet("World"); 59 - Ant.println("Test 9 - greet('World'):", result9); // Should be "Hello, World" 59 + console.log("Test 9 - greet('World'):", result9); // Should be "Hello, World" 60 60 61 61 // Test 10: Arrow function with comparison 62 62 let isPositive = x => x > 0; 63 63 let result10a = isPositive(5); 64 - Ant.println("Test 10a - isPositive(5):", result10a); // Should be true 64 + console.log("Test 10a - isPositive(5):", result10a); // Should be true 65 65 let result10b = isPositive(-3); 66 - Ant.println("Test 10b - isPositive(-3):", result10b); // Should be false 66 + console.log("Test 10b - isPositive(-3):", result10b); // Should be false 67 67 68 68 // Test 11: Arrow function in array 69 69 let funcs = []; 70 70 funcs[0] = x => x + 1; 71 71 funcs[1] = x => x * 2; 72 72 let result11a = funcs[0](10); 73 - Ant.println("Test 11a - funcs[0](10):", result11a); // Should be 11 73 + console.log("Test 11a - funcs[0](10):", result11a); // Should be 11 74 74 let result11b = funcs[1](10); 75 - Ant.println("Test 11b - funcs[1](10):", result11b); // Should be 20 75 + console.log("Test 11b - funcs[1](10):", result11b); // Should be 20 76 76 77 77 // Test 12: Arrow function with three parameters 78 78 let sum3 = (a, b, c) => a + b + c; 79 79 let result12 = sum3(1, 2, 3); 80 - Ant.println("Test 12 - sum3(1, 2, 3):", result12); // Should be 6 80 + console.log("Test 12 - sum3(1, 2, 3):", result12); // Should be 6 81 81 82 82 // Test 13: Arrow function assigned to object property 83 83 let calculator = {}; 84 84 calculator.add = (a, b) => a + b; 85 85 calculator.subtract = (a, b) => a - b; 86 86 let result13a = calculator.add(10, 5); 87 - Ant.println("Test 13a - calculator.add(10, 5):", result13a); // Should be 15 87 + console.log("Test 13a - calculator.add(10, 5):", result13a); // Should be 15 88 88 let result13b = calculator.subtract(10, 5); 89 - Ant.println("Test 13b - calculator.subtract(10, 5):", result13b); // Should be 5 89 + console.log("Test 13b - calculator.subtract(10, 5):", result13b); // Should be 5 90 90 91 91 // Test 14: Arrow function returning early 92 92 let checkValue = x => { ··· 99 99 return "positive"; 100 100 }; 101 101 let result14a = checkValue(-5); 102 - Ant.println("Test 14a - checkValue(-5):", result14a); // Should be "negative" 102 + console.log("Test 14a - checkValue(-5):", result14a); // Should be "negative" 103 103 let result14b = checkValue(0); 104 - Ant.println("Test 14b - checkValue(0):", result14b); // Should be "zero" 104 + console.log("Test 14b - checkValue(0):", result14b); // Should be "zero" 105 105 let result14c = checkValue(5); 106 - Ant.println("Test 14c - checkValue(5):", result14c); // Should be "positive" 106 + console.log("Test 14c - checkValue(5):", result14c); // Should be "positive" 107 107 108 108 // Test 15: Arrow function with implicit undefined return 109 109 let noReturn = x => { 110 110 let temp = x + 1; 111 111 }; 112 112 let result15 = noReturn(5); 113 - Ant.println("Test 15 - noReturn(5):", result15); // Should be undefined 113 + console.log("Test 15 - noReturn(5):", result15); // Should be undefined 114 114 115 - Ant.println("\nAll arrow function tests completed!"); 115 + console.log("\nAll arrow function tests completed!");
+29 -29
tests/class.cjs
··· 1 1 // Test class keyword 2 2 3 - Ant.println("=== Testing class keyword ==="); 3 + console.log("=== Testing class keyword ==="); 4 4 5 5 // Test 1: Simple class with constructor 6 6 class Person { ··· 11 11 } 12 12 13 13 let person1 = new Person("Alice", 30); 14 - Ant.println(person1.name); // "Alice" 15 - Ant.println(person1.age); // 30 14 + console.log(person1.name); // "Alice" 15 + console.log(person1.age); // 30 16 16 17 17 // Test 2: Class with methods 18 18 class Calculator { ··· 36 36 } 37 37 38 38 let calc = new Calculator(10); 39 - Ant.println(calc.value); // 10 40 - Ant.println(calc.add(5)); // 15 41 - Ant.println(calc.subtract(3)); // 12 42 - Ant.println(calc.getValue()); // 12 39 + console.log(calc.value); // 10 40 + console.log(calc.add(5)); // 15 41 + console.log(calc.subtract(3)); // 12 42 + console.log(calc.getValue()); // 12 43 43 44 44 // Test 3: Class without explicit constructor 45 45 class Point { ··· 55 55 56 56 let p = new Point(); 57 57 p.setCoords(3, 4); 58 - Ant.println(p.x); // 3 59 - Ant.println(p.y); // 4 60 - Ant.println(p.getDistance()); // 25 58 + console.log(p.x); // 3 59 + console.log(p.y); // 4 60 + console.log(p.getDistance()); // 25 61 61 62 62 // Test 4: Multiple instances 63 63 class Counter { ··· 73 73 74 74 let counter1 = new Counter(0); 75 75 let counter2 = new Counter(10); 76 - Ant.println(counter1.increment()); // 1 77 - Ant.println(counter1.increment()); // 2 78 - Ant.println(counter2.increment()); // 11 79 - Ant.println(counter2.increment()); // 12 76 + console.log(counter1.increment()); // 1 77 + console.log(counter1.increment()); // 2 78 + console.log(counter2.increment()); // 11 79 + console.log(counter2.increment()); // 12 80 80 81 81 // Test 5: Class instances are objects 82 82 let person2 = new Person("Bob", 25); 83 - Ant.println(typeof person2); // object 84 - Ant.println(person2 instanceof Object); // true 83 + console.log(typeof person2); // object 84 + console.log(person2 instanceof Object); // true 85 85 86 86 // Test 6: Modify instance properties 87 87 class Rectangle { ··· 96 96 } 97 97 98 98 let rect = new Rectangle(5, 10); 99 - Ant.println(rect.area()); // 50 99 + console.log(rect.area()); // 50 100 100 rect.width = 8; 101 - Ant.println(rect.area()); // 80 101 + console.log(rect.area()); // 80 102 102 103 103 // Test 7: Delete class instance properties 104 104 let person3 = new Person("Charlie", 35); 105 - Ant.println(person3.name); // "Charlie" 105 + console.log(person3.name); // "Charlie" 106 106 delete person3.name; 107 - Ant.println(person3.name); // undefined 108 - Ant.println(person3.age); // 35 107 + console.log(person3.name); // undefined 108 + console.log(person3.age); // 35 109 109 110 110 // Test 8: Class with property management 111 111 class Store { ··· 128 128 } 129 129 130 130 let store = new Store(); 131 - Ant.println(store.getItemCount()); // 0 131 + console.log(store.getItemCount()); // 0 132 132 store.addItem("apple", 5); 133 133 store.addItem("banana", 3); 134 - Ant.println(store.getItemCount()); // 2 134 + console.log(store.getItemCount()); // 2 135 135 store.removeItem("apple"); 136 - Ant.println(store.getItemCount()); // 1 136 + console.log(store.getItemCount()); // 1 137 137 138 138 // Test 9: Method chaining 139 139 class ChainableCounter { ··· 158 158 159 159 let chain = new ChainableCounter(5); 160 160 let result = chain.add(3).multiply(2).get(); 161 - Ant.println(result); // 16 161 + console.log(result); // 16 162 162 163 163 // Test 10: Class with boolean properties 164 164 class Feature { ··· 181 181 } 182 182 183 183 let feature = new Feature("DarkMode"); 184 - Ant.println(feature.isEnabled()); // false 184 + console.log(feature.isEnabled()); // false 185 185 feature.enable(); 186 - Ant.println(feature.isEnabled()); // true 186 + console.log(feature.isEnabled()); // true 187 187 feature.disable(); 188 - Ant.println(feature.isEnabled()); // false 188 + console.log(feature.isEnabled()); // false 189 189 190 - Ant.println("=== Class tests completed ==="); 190 + console.log("=== Class tests completed ===");
+23 -23
tests/delete.cjs
··· 1 1 // Test delete keyword 2 2 3 - Ant.println("=== Testing delete operator ==="); 3 + console.log("=== Testing delete operator ==="); 4 4 5 5 // Test 1: Delete object property 6 6 let obj = { a: 1, b: 2, c: 3 }; 7 - Ant.println(obj.a); // 1 7 + console.log(obj.a); // 1 8 8 delete obj.a; 9 - Ant.println(obj.a); // undefined 9 + console.log(obj.a); // undefined 10 10 11 11 // Test 2: Delete from nested object 12 12 let nested = { ··· 14 14 inner: "value" 15 15 } 16 16 }; 17 - Ant.println(nested.outer.inner); // "value" 17 + console.log(nested.outer.inner); // "value" 18 18 delete nested.outer.inner; 19 - Ant.println(nested.outer.inner); // undefined 19 + console.log(nested.outer.inner); // undefined 20 20 21 21 // Test 3: Delete array element 22 22 let arr = [1, 2, 3, 4, 5]; 23 - Ant.println(arr.length); // 5 23 + console.log(arr.length); // 5 24 24 delete arr[2]; 25 - Ant.println(arr[2]); // undefined 26 - Ant.println(arr.length); // 5 (length doesn't change) 25 + console.log(arr[2]); // undefined 26 + console.log(arr.length); // 5 (length doesn't change) 27 27 28 28 // Test 4: Delete returns true 29 29 let test_obj = { x: 10 }; 30 30 let result = delete test_obj.x; 31 - Ant.println(result); // true 31 + console.log(result); // true 32 32 33 33 // Test 5: Delete non-existent property 34 34 let obj2 = { a: 1 }; 35 35 let result2 = delete obj2.b; // Property doesn't exist 36 - Ant.println(result2); // true 36 + console.log(result2); // true 37 37 38 38 // Test 6: Delete from variable (should return true but not delete var) 39 39 // Note: In this implementation, deleting a variable reference returns true 40 40 // but doesn't actually remove the variable from scope 41 41 let myVar = 42; 42 42 let result3 = delete myVar; 43 - Ant.println(result3); // true 44 - // Ant.println(myVar); // Would still be 42 if properly implemented 43 + console.log(result3); // true 44 + // console.log(myVar); // Would still be 42 if properly implemented 45 45 46 46 // Test 7: Cannot delete const property 47 47 const obj3 = { a: 1 }; ··· 53 53 dynamicObj.prop2 = "second"; 54 54 dynamicObj.prop3 = "third"; 55 55 56 - Ant.println(dynamicObj.prop1); // "first" 57 - Ant.println(dynamicObj.prop2); // "second" 56 + console.log(dynamicObj.prop1); // "first" 57 + console.log(dynamicObj.prop2); // "second" 58 58 59 59 delete dynamicObj.prop2; 60 - Ant.println(dynamicObj.prop1); // "first" 61 - Ant.println(dynamicObj.prop2); // undefined 62 - Ant.println(dynamicObj.prop3); // "third" 60 + console.log(dynamicObj.prop1); // "first" 61 + console.log(dynamicObj.prop2); // undefined 62 + console.log(dynamicObj.prop3); // "third" 63 63 64 64 // Test 9: Delete and re-add property 65 65 let reusableObj = { key: "value1" }; 66 - Ant.println(reusableObj.key); // "value1" 66 + console.log(reusableObj.key); // "value1" 67 67 delete reusableObj.key; 68 - Ant.println(reusableObj.key); // undefined 68 + console.log(reusableObj.key); // undefined 69 69 reusableObj.key = "value2"; 70 - Ant.println(reusableObj.key); // "value2" 70 + console.log(reusableObj.key); // "value2" 71 71 72 72 // Test 10: Delete in complex object structure 73 73 let complex = { ··· 77 77 } 78 78 } 79 79 }; 80 - Ant.println(complex.level1.level2.level3); // "deep" 80 + console.log(complex.level1.level2.level3); // "deep" 81 81 delete complex.level1.level2.level3; 82 - Ant.println(complex.level1.level2.level3); // undefined 82 + console.log(complex.level1.level2.level3); // undefined 83 83 84 - Ant.println("=== Delete tests completed ==="); 84 + console.log("=== Delete tests completed ===");
+51 -51
tests/dynamic_object_assignment.cjs
··· 1 1 // Test dynamic object property assignment 2 2 3 - Ant.println("=== Dynamic Object Assignment Tests ===\n"); 3 + console.log("=== Dynamic Object Assignment Tests ===\n"); 4 4 5 5 // Test 1: Basic dynamic property assignment using bracket notation 6 - Ant.println("Test 1: Basic bracket notation assignment"); 6 + console.log("Test 1: Basic bracket notation assignment"); 7 7 let obj1 = {}; 8 8 obj1["name"] = "Alice"; 9 9 obj1["age"] = 30; 10 10 obj1["active"] = true; 11 - Ant.println(" obj1.name:", obj1["name"]); 12 - Ant.println(" obj1.age:", obj1["age"]); 13 - Ant.println(" obj1.active:", obj1["active"]); 11 + console.log(" obj1.name:", obj1["name"]); 12 + console.log(" obj1.age:", obj1["age"]); 13 + console.log(" obj1.active:", obj1["active"]); 14 14 15 15 // Test 2: Dynamic property assignment with variable keys 16 - Ant.println("\nTest 2: Variable keys"); 16 + console.log("\nTest 2: Variable keys"); 17 17 let obj2 = {}; 18 18 let key1 = "firstName"; 19 19 let key2 = "lastName"; ··· 21 21 obj2[key1] = "Bob"; 22 22 obj2[key2] = "Smith"; 23 23 obj2[key3] = "bob@example.com"; 24 - Ant.println(" obj2[key1]:", obj2[key1]); 25 - Ant.println(" obj2[key2]:", obj2[key2]); 26 - Ant.println(" obj2[key3]:", obj2[key3]); 24 + console.log(" obj2[key1]:", obj2[key1]); 25 + console.log(" obj2[key2]:", obj2[key2]); 26 + console.log(" obj2[key3]:", obj2[key3]); 27 27 28 28 // Test 3: Numeric keys (array-like object) 29 - Ant.println("\nTest 3: Numeric keys"); 29 + console.log("\nTest 3: Numeric keys"); 30 30 let obj3 = {}; 31 31 obj3[0] = "first"; 32 32 obj3[1] = "second"; 33 33 obj3[2] = "third"; 34 - Ant.println(" obj3[0]:", obj3[0]); 35 - Ant.println(" obj3[1]:", obj3[1]); 36 - Ant.println(" obj3[2]:", obj3[2]); 34 + console.log(" obj3[0]:", obj3[0]); 35 + console.log(" obj3[1]:", obj3[1]); 36 + console.log(" obj3[2]:", obj3[2]); 37 37 38 38 // Test 4: Dynamic property assignment in loop 39 - Ant.println("\nTest 4: Loop assignment"); 39 + console.log("\nTest 4: Loop assignment"); 40 40 let obj4 = {}; 41 41 for (let i = 0; i < 5; i++) { 42 42 obj4[i] = i * 10; 43 43 } 44 - Ant.println(" obj4[0]:", obj4[0]); 45 - Ant.println(" obj4[2]:", obj4[2]); 46 - Ant.println(" obj4[4]:", obj4[4]); 44 + console.log(" obj4[0]:", obj4[0]); 45 + console.log(" obj4[2]:", obj4[2]); 46 + console.log(" obj4[4]:", obj4[4]); 47 47 48 48 // Test 5: Mix of dot notation and bracket notation 49 - Ant.println("\nTest 5: Mixed notation"); 49 + console.log("\nTest 5: Mixed notation"); 50 50 let obj5 = {}; 51 51 obj5.static = "dot notation"; 52 52 obj5["dynamic"] = "bracket notation"; 53 53 let propName = "computed"; 54 54 obj5[propName] = "variable key"; 55 - Ant.println(" obj5.static:", obj5.static); 56 - Ant.println(" obj5['dynamic']:", obj5["dynamic"]); 57 - Ant.println(" obj5[propName]:", obj5[propName]); 55 + console.log(" obj5.static:", obj5.static); 56 + console.log(" obj5['dynamic']:", obj5["dynamic"]); 57 + console.log(" obj5[propName]:", obj5[propName]); 58 58 59 59 // Test 6: Overwriting existing properties 60 - Ant.println("\nTest 6: Overwrite properties"); 60 + console.log("\nTest 6: Overwrite properties"); 61 61 let obj6 = { name: "Original" }; 62 - Ant.println(" Before:", obj6.name); 62 + console.log(" Before:", obj6.name); 63 63 obj6["name"] = "Updated"; 64 - Ant.println(" After:", obj6["name"]); 64 + console.log(" After:", obj6["name"]); 65 65 66 66 // Test 7: Dynamic keys with string concatenation 67 - Ant.println("\nTest 7: Concatenated keys"); 67 + console.log("\nTest 7: Concatenated keys"); 68 68 let obj7 = {}; 69 69 let prefix = "prop"; 70 70 obj7[prefix + "1"] = "value1"; 71 71 obj7[prefix + "2"] = "value2"; 72 72 obj7[prefix + "3"] = "value3"; 73 - Ant.println(" obj7['prop1']:", obj7["prop1"]); 74 - Ant.println(" obj7['prop2']:", obj7["prop2"]); 75 - Ant.println(" obj7['prop3']:", obj7["prop3"]); 73 + console.log(" obj7['prop1']:", obj7["prop1"]); 74 + console.log(" obj7['prop2']:", obj7["prop2"]); 75 + console.log(" obj7['prop3']:", obj7["prop3"]); 76 76 77 77 // Test 8: Building object dynamically from arrays 78 - Ant.println("\nTest 8: Build from arrays"); 78 + console.log("\nTest 8: Build from arrays"); 79 79 let keys = ["x", "y", "z"]; 80 80 let values = [100, 200, 300]; 81 81 let obj8 = {}; 82 82 for (let i = 0; i < keys.length; i++) { 83 83 obj8[keys[i]] = values[i]; 84 84 } 85 - Ant.println(" obj8.x:", obj8["x"]); 86 - Ant.println(" obj8.y:", obj8["y"]); 87 - Ant.println(" obj8.z:", obj8["z"]); 85 + console.log(" obj8.x:", obj8["x"]); 86 + console.log(" obj8.y:", obj8["y"]); 87 + console.log(" obj8.z:", obj8["z"]); 88 88 89 89 // Test 9: Nested dynamic assignment 90 - Ant.println("\nTest 9: Nested objects"); 90 + console.log("\nTest 9: Nested objects"); 91 91 let obj9 = {}; 92 92 obj9["user"] = {}; 93 93 obj9["user"]["name"] = "Charlie"; 94 94 obj9["user"]["age"] = 25; 95 - Ant.println(" obj9.user.name:", obj9["user"]["name"]); 96 - Ant.println(" obj9.user.age:", obj9["user"]["age"]); 95 + console.log(" obj9.user.name:", obj9["user"]["name"]); 96 + console.log(" obj9.user.age:", obj9["user"]["age"]); 97 97 98 98 // Test 10: Reading undefined dynamic properties 99 - Ant.println("\nTest 10: Undefined properties"); 99 + console.log("\nTest 10: Undefined properties"); 100 100 let obj10 = { a: 1 }; 101 - Ant.println(" obj10['a']:", obj10["a"]); 102 - Ant.println(" obj10['b'] (undefined):", obj10["b"]); 101 + console.log(" obj10['a']:", obj10["a"]); 102 + console.log(" obj10['b'] (undefined):", obj10["b"]); 103 103 104 104 // Test 10a: Dynamic access with literal strings 105 - Ant.println("\nTest 10a: Literal string keys"); 105 + console.log("\nTest 10a: Literal string keys"); 106 106 let cat = { meow: "purr", sound: "meow meow", age: 3 }; 107 - Ant.println(" cat['meow']:", cat["meow"]); 108 - Ant.println(" cat['sound']:", cat["sound"]); 109 - Ant.println(" cat['age']:", cat["age"]); 107 + console.log(" cat['meow']:", cat["meow"]); 108 + console.log(" cat['sound']:", cat["sound"]); 109 + console.log(" cat['age']:", cat["age"]); 110 110 let key = "meow"; 111 - Ant.println(" cat[key] where key='meow':", cat[key]); 111 + console.log(" cat[key] where key='meow':", cat[key]); 112 112 113 113 // Test 11: Dynamic property assignment with expressions 114 - Ant.println("\nTest 11: Expression keys"); 114 + console.log("\nTest 11: Expression keys"); 115 115 let obj11 = {}; 116 116 obj11[1 + 1] = "two"; 117 117 obj11[2 + 2] = "four"; 118 - Ant.println(" obj11[2]:", obj11[2]); 119 - Ant.println(" obj11[4]:", obj11[4]); 118 + console.log(" obj11[2]:", obj11[2]); 119 + console.log(" obj11[4]:", obj11[4]); 120 120 121 121 // Test 12: Creating a map-like structure 122 - Ant.println("\nTest 12: Map-like usage"); 122 + console.log("\nTest 12: Map-like usage"); 123 123 let map = {}; 124 124 map["key1"] = { value: 10, type: "number" }; 125 125 map["key2"] = { value: "hello", type: "string" }; 126 126 map["key3"] = { value: true, type: "boolean" }; 127 - Ant.println(" map['key1'].value:", map["key1"]["value"]); 128 - Ant.println(" map['key2'].value:", map["key2"]["value"]); 129 - Ant.println(" map['key3'].value:", map["key3"]["value"]); 127 + console.log(" map['key1'].value:", map["key1"]["value"]); 128 + console.log(" map['key2'].value:", map["key2"]["value"]); 129 + console.log(" map['key3'].value:", map["key3"]["value"]); 130 130 131 - Ant.println("\n=== All tests completed ==="); 131 + console.log("\n=== All tests completed ===");
+54 -54
tests/equality_operators.cjs
··· 1 1 // Test equality operators == and != 2 2 // Also tests strict equality === and !== 3 3 4 - Ant.println("=== Equality Operators Test ===\n"); 4 + console.log("=== Equality Operators Test ===\n"); 5 5 6 6 // Test 1: Basic equality with numbers 7 - Ant.println("Test 1: Number equality"); 7 + console.log("Test 1: Number equality"); 8 8 let a = 5; 9 9 let b = 5; 10 10 let c = 10; 11 11 12 - Ant.println(" 5 == 5:", a == b); 13 - Ant.println(" 5 === 5:", a === b); 14 - Ant.println(" 5 != 10:", a != c); 15 - Ant.println(" 5 !== 10:", a !== c); 16 - Ant.println(" 5 == 10:", a == c); 17 - Ant.println(" 5 != 5:", a != b); 12 + console.log(" 5 == 5:", a == b); 13 + console.log(" 5 === 5:", a === b); 14 + console.log(" 5 != 10:", a != c); 15 + console.log(" 5 !== 10:", a !== c); 16 + console.log(" 5 == 10:", a == c); 17 + console.log(" 5 != 5:", a != b); 18 18 19 19 // Test 2: String equality 20 - Ant.println("\nTest 2: String equality"); 20 + console.log("\nTest 2: String equality"); 21 21 let s1 = "hello"; 22 22 let s2 = "hello"; 23 23 let s3 = "world"; 24 24 25 - Ant.println(" 'hello' == 'hello':", s1 == s2); 26 - Ant.println(" 'hello' === 'hello':", s1 === s2); 27 - Ant.println(" 'hello' != 'world':", s1 != s3); 28 - Ant.println(" 'hello' !== 'world':", s1 !== s3); 29 - Ant.println(" 'hello' == 'world':", s1 == s3); 25 + console.log(" 'hello' == 'hello':", s1 == s2); 26 + console.log(" 'hello' === 'hello':", s1 === s2); 27 + console.log(" 'hello' != 'world':", s1 != s3); 28 + console.log(" 'hello' !== 'world':", s1 !== s3); 29 + console.log(" 'hello' == 'world':", s1 == s3); 30 30 31 31 // Test 3: Boolean equality 32 - Ant.println("\nTest 3: Boolean equality"); 32 + console.log("\nTest 3: Boolean equality"); 33 33 let t1 = true; 34 34 let t2 = true; 35 35 let f1 = false; 36 36 37 - Ant.println(" true == true:", t1 == t2); 38 - Ant.println(" true === true:", t1 === t2); 39 - Ant.println(" true != false:", t1 != f1); 40 - Ant.println(" true !== false:", t1 !== f1); 41 - Ant.println(" false == false:", f1 == false); 37 + console.log(" true == true:", t1 == t2); 38 + console.log(" true === true:", t1 === t2); 39 + console.log(" true != false:", t1 != f1); 40 + console.log(" true !== false:", t1 !== f1); 41 + console.log(" false == false:", f1 == false); 42 42 43 43 // Test 4: Undefined and null 44 - Ant.println("\nTest 4: Undefined and null"); 44 + console.log("\nTest 4: Undefined and null"); 45 45 let u = undefined; 46 46 let n = null; 47 47 48 - Ant.println(" undefined == undefined:", u == undefined); 49 - Ant.println(" undefined === undefined:", u === undefined); 50 - Ant.println(" null == null:", n == null); 51 - Ant.println(" null === null:", n === null); 52 - Ant.println(" undefined != null:", u != n); 53 - Ant.println(" undefined !== null:", u !== n); 48 + console.log(" undefined == undefined:", u == undefined); 49 + console.log(" undefined === undefined:", u === undefined); 50 + console.log(" null == null:", n == null); 51 + console.log(" null === null:", n === null); 52 + console.log(" undefined != null:", u != n); 53 + console.log(" undefined !== null:", u !== n); 54 54 55 55 // Test 5: Mixed type comparisons 56 - Ant.println("\nTest 5: Type comparisons"); 56 + console.log("\nTest 5: Type comparisons"); 57 57 let num = 5; 58 58 let str = "5"; 59 59 let bool = true; 60 60 61 - Ant.println(" 5 != '5':", num != str); 62 - Ant.println(" 5 !== '5':", num !== str); 63 - Ant.println(" true != 1:", bool != 1); 64 - Ant.println(" true !== 1:", bool !== 1); 61 + console.log(" 5 != '5':", num != str); 62 + console.log(" 5 !== '5':", num !== str); 63 + console.log(" true != 1:", bool != 1); 64 + console.log(" true !== 1:", bool !== 1); 65 65 66 66 // Test 6: In conditional expressions 67 - Ant.println("\nTest 6: Conditional expressions"); 67 + console.log("\nTest 6: Conditional expressions"); 68 68 if (5 == 5) { 69 - Ant.println(" 5 == 5 in if statement: passed"); 69 + console.log(" 5 == 5 in if statement: passed"); 70 70 } 71 71 72 72 if (5 != 10) { 73 - Ant.println(" 5 != 10 in if statement: passed"); 73 + console.log(" 5 != 10 in if statement: passed"); 74 74 } 75 75 76 76 if (undefined == undefined) { 77 - Ant.println(" undefined == undefined in if statement: passed"); 77 + console.log(" undefined == undefined in if statement: passed"); 78 78 } 79 79 80 80 if (null != undefined) { 81 - Ant.println(" null != undefined in if statement: passed"); 81 + console.log(" null != undefined in if statement: passed"); 82 82 } 83 83 84 84 // Test 7: Loop conditions 85 - Ant.println("\nTest 7: Loop with equality"); 85 + console.log("\nTest 7: Loop with equality"); 86 86 let count = 0; 87 87 for (let i = 0; i != 5; i = i + 1) { 88 88 count = count + 1; 89 89 } 90 - Ant.println(" Loop with != condition, count:", count); 90 + console.log(" Loop with != condition, count:", count); 91 91 92 92 // Test 8: Ternary with equality 93 - Ant.println("\nTest 8: Ternary operator"); 93 + console.log("\nTest 8: Ternary operator"); 94 94 let result1 = (5 == 5) ? "equal" : "not equal"; 95 - Ant.println(" 5 == 5 ? 'equal' : 'not equal' =>", result1); 95 + console.log(" 5 == 5 ? 'equal' : 'not equal' =>", result1); 96 96 97 97 let result2 = (5 != 10) ? "not equal" : "equal"; 98 - Ant.println(" 5 != 10 ? 'not equal' : 'equal' =>", result2); 98 + console.log(" 5 != 10 ? 'not equal' : 'equal' =>", result2); 99 99 100 100 // Test 9: Object equality (by reference) 101 - Ant.println("\nTest 9: Object equality"); 101 + console.log("\nTest 9: Object equality"); 102 102 let obj1 = { x: 1 }; 103 103 let obj2 = { x: 1 }; 104 104 let obj3 = obj1; 105 105 106 - Ant.println(" obj1 == obj2 (different refs):", obj1 == obj2); 107 - Ant.println(" obj1 === obj2 (different refs):", obj1 === obj2); 108 - Ant.println(" obj1 == obj3 (same ref):", obj1 == obj3); 109 - Ant.println(" obj1 === obj3 (same ref):", obj1 === obj3); 110 - Ant.println(" obj1 != obj2:", obj1 != obj2); 106 + console.log(" obj1 == obj2 (different refs):", obj1 == obj2); 107 + console.log(" obj1 === obj2 (different refs):", obj1 === obj2); 108 + console.log(" obj1 == obj3 (same ref):", obj1 == obj3); 109 + console.log(" obj1 === obj3 (same ref):", obj1 === obj3); 110 + console.log(" obj1 != obj2:", obj1 != obj2); 111 111 112 112 // Test 10: Array equality 113 - Ant.println("\nTest 10: Array equality"); 113 + console.log("\nTest 10: Array equality"); 114 114 let arr1 = [1, 2, 3]; 115 115 let arr2 = [1, 2, 3]; 116 116 let arr3 = arr1; 117 117 118 - Ant.println(" arr1 == arr2 (different refs):", arr1 == arr2); 119 - Ant.println(" arr1 === arr2 (different refs):", arr1 === arr2); 120 - Ant.println(" arr1 == arr3 (same ref):", arr1 == arr3); 121 - Ant.println(" arr1 === arr3 (same ref):", arr1 === arr3); 118 + console.log(" arr1 == arr2 (different refs):", arr1 == arr2); 119 + console.log(" arr1 === arr2 (different refs):", arr1 === arr2); 120 + console.log(" arr1 == arr3 (same ref):", arr1 == arr3); 121 + console.log(" arr1 === arr3 (same ref):", arr1 === arr3); 122 122 123 - Ant.println("\n=== All tests completed ==="); 123 + console.log("\n=== All tests completed ===");
+9 -9
tests/example.cjs
··· 4 4 const value = math.mul(2, 3); 5 5 const result = math.add(value, 3); 6 6 7 - Ant.println(this); 8 - Ant.println(); 7 + console.log(this); 8 + console.log(); 9 9 10 10 function main() { 11 - Ant.println(result); 12 - Ant.println(math.PI); 13 - Ant.println(stuff.test()); 11 + console.log(result); 12 + console.log(math.PI); 13 + console.log(stuff.test()); 14 14 15 - Ant.println(Ant.__dirname); 16 - Ant.println(typeof result); 15 + console.log(Ant.__dirname); 16 + console.log(typeof result); 17 17 18 - Ant.println(value instanceof Number); 19 - Ant.println(String(123)); 18 + console.log(value instanceof Number); 19 + console.log(String(123)); 20 20 } 21 21 22 22 void main();
+49 -49
tests/for_loops.cjs
··· 1 1 // Test for loop functionality 2 2 3 - Ant.println("=== For Loop Tests ===\n"); 3 + console.log("=== For Loop Tests ===\n"); 4 4 5 5 // Test 1: Basic for loop 6 - Ant.println("Test 1: Basic for loop"); 6 + console.log("Test 1: Basic for loop"); 7 7 let sum1 = 0; 8 8 for (let i = 0; i < 5; i = i + 1) { 9 9 sum1 = sum1 + i; 10 10 } 11 - Ant.println(" Sum of 0-4:", sum1); 11 + console.log(" Sum of 0-4:", sum1); 12 12 13 13 // Test 2: For loop with const inside 14 - Ant.println("\nTest 2: For loop with const declaration"); 14 + console.log("\nTest 2: For loop with const declaration"); 15 15 let sum2 = 0; 16 16 for (let i = 0; i < 3; i = i + 1) { 17 17 const doubled = i * 2; 18 18 sum2 = sum2 + doubled; 19 - Ant.println(" i:", i, "doubled:", doubled); 19 + console.log(" i:", i, "doubled:", doubled); 20 20 } 21 - Ant.println(" Total sum:", sum2); 21 + console.log(" Total sum:", sum2); 22 22 23 23 // Test 3: Nested for loops 24 - Ant.println("\nTest 3: Nested for loops"); 24 + console.log("\nTest 3: Nested for loops"); 25 25 let product = 1; 26 26 for (let i = 1; i <= 3; i = i + 1) { 27 27 for (let j = 1; j <= 2; j = j + 1) { 28 28 product = product * (i + j); 29 - Ant.println(" i:", i, "j:", j, "product:", product); 29 + console.log(" i:", i, "j:", j, "product:", product); 30 30 } 31 31 } 32 - Ant.println(" Final product:", product); 32 + console.log(" Final product:", product); 33 33 34 34 // Test 4: Return from for loop in function 35 - Ant.println("\nTest 4: Return from for loop"); 35 + console.log("\nTest 4: Return from for loop"); 36 36 function findFirst(arr, target) { 37 37 for (let i = 0; i < arr.length; i = i + 1) { 38 38 if (arr[i] === target) { ··· 43 43 } 44 44 45 45 const numbers = [10, 20, 30, 40, 50]; 46 - Ant.println(" Array:", numbers); 47 - Ant.println(" Index of 30:", findFirst(numbers, 30)); 48 - Ant.println(" Index of 99:", findFirst(numbers, 99)); 46 + console.log(" Array:", numbers); 47 + console.log(" Index of 30:", findFirst(numbers, 30)); 48 + console.log(" Index of 99:", findFirst(numbers, 99)); 49 49 50 50 // Test 5: Break in for loop 51 - Ant.println("\nTest 5: Break in for loop"); 51 + console.log("\nTest 5: Break in for loop"); 52 52 let breakSum = 0; 53 53 for (let i = 0; i < 10; i = i + 1) { 54 54 if (i === 5) { 55 - Ant.println(" Breaking at i =", i); 55 + console.log(" Breaking at i =", i); 56 56 break; 57 57 } 58 58 breakSum = breakSum + i; 59 59 } 60 - Ant.println(" Sum before break:", breakSum); 60 + console.log(" Sum before break:", breakSum); 61 61 62 62 // Test 6: Continue in for loop 63 - Ant.println("\nTest 6: Continue in for loop"); 63 + console.log("\nTest 6: Continue in for loop"); 64 64 let evenSum = 0; 65 65 for (let i = 0; i < 10; i = i + 1) { 66 66 if (i % 2 === 1) { ··· 68 68 } 69 69 evenSum = evenSum + i; 70 70 } 71 - Ant.println(" Sum of even numbers 0-9:", evenSum); 71 + console.log(" Sum of even numbers 0-9:", evenSum); 72 72 73 73 // Test 7: For loop with empty initialization 74 - Ant.println("\nTest 7: For loop with external initialization"); 74 + console.log("\nTest 7: For loop with external initialization"); 75 75 let k = 0; 76 76 let count = 0; 77 77 for (; k < 5; k = k + 1) { 78 78 count = count + 1; 79 79 } 80 - Ant.println(" Count:", count, "k:", k); 80 + console.log(" Count:", count, "k:", k); 81 81 82 82 // Test 8: For loop with empty condition (infinite loop with break) 83 - Ant.println("\nTest 8: For loop with break condition"); 83 + console.log("\nTest 8: For loop with break condition"); 84 84 let limit = 0; 85 85 for (let i = 0; ; i = i + 1) { 86 86 limit = i; ··· 88 88 break; 89 89 } 90 90 } 91 - Ant.println(" Stopped at:", limit); 91 + console.log(" Stopped at:", limit); 92 92 93 93 // Test 9: For loop with empty increment 94 - Ant.println("\nTest 9: For loop with manual increment"); 94 + console.log("\nTest 9: For loop with manual increment"); 95 95 let manual = 0; 96 96 for (let i = 0; i < 5; ) { 97 97 manual = manual + i; 98 98 i = i + 2; 99 99 } 100 - Ant.println(" Manual increment sum:", manual); 100 + console.log(" Manual increment sum:", manual); 101 101 102 102 // Test 10: For loop with multiple variables 103 - Ant.println("\nTest 10: For loop counting down"); 103 + console.log("\nTest 10: For loop counting down"); 104 104 let countdown = 0; 105 105 for (let i = 5; i > 0; i = i - 1) { 106 106 countdown = countdown + i; 107 107 } 108 - Ant.println(" Countdown sum:", countdown); 108 + console.log(" Countdown sum:", countdown); 109 109 110 110 // Test 11: For loop modifying array 111 - Ant.println("\nTest 11: For loop modifying array"); 111 + console.log("\nTest 11: For loop modifying array"); 112 112 const arr = [1, 2, 3, 4, 5]; 113 113 for (let i = 0; i < arr.length; i = i + 1) { 114 114 arr[i] = arr[i] * 2; 115 115 } 116 - Ant.println(" Doubled array:", arr); 116 + console.log(" Doubled array:", arr); 117 117 118 118 // Test 12: For loop with object properties 119 - Ant.println("\nTest 12: For loop with object"); 119 + console.log("\nTest 12: For loop with object"); 120 120 const obj = { a: 1, b: 2, c: 3 }; 121 121 const keys = Object.keys(obj); 122 122 let objSum = 0; 123 123 for (let i = 0; i < keys.length; i = i + 1) { 124 124 const key = keys[i]; 125 125 objSum = objSum + obj[key]; 126 - Ant.println(" key:", key, "value:", obj[key]); 126 + console.log(" key:", key, "value:", obj[key]); 127 127 } 128 - Ant.println(" Object sum:", objSum); 128 + console.log(" Object sum:", objSum); 129 129 130 130 // Test 13: For loop with string iteration 131 - Ant.println("\nTest 13: For loop iterating string"); 131 + console.log("\nTest 13: For loop iterating string"); 132 132 const str = "hello"; 133 133 let chars = ""; 134 134 for (let i = 0; i < str.length; i = i + 1) { 135 135 chars = chars + str[i] + " "; 136 136 } 137 - Ant.println(" Characters:", chars); 137 + console.log(" Characters:", chars); 138 138 139 139 // Test 14: For loop with early return in nested function 140 - Ant.println("\nTest 14: Early return in nested loops"); 140 + console.log("\nTest 14: Early return in nested loops"); 141 141 function findPair(arr, target) { 142 142 for (let i = 0; i < arr.length; i = i + 1) { 143 143 for (let j = i + 1; j < arr.length; j = j + 1) { ··· 152 152 const testArr = [1, 2, 3, 4, 5]; 153 153 const result = findPair(testArr, 7); 154 154 if (result) { 155 - Ant.println(" Found pair at indices", result.i, "and", result.j); 156 - Ant.println(" Values:", testArr[result.i], "+", testArr[result.j], "=", result.sum); 155 + console.log(" Found pair at indices", result.i, "and", result.j); 156 + console.log(" Values:", testArr[result.i], "+", testArr[result.j], "=", result.sum); 157 157 } 158 158 159 159 // Test 15: For loop scope isolation 160 - Ant.println("\nTest 15: For loop scope isolation"); 160 + console.log("\nTest 15: For loop scope isolation"); 161 161 const results = []; 162 162 for (let i = 0; i < 3; i = i + 1) { 163 163 const value = i * 10; 164 164 results.push(value); 165 165 } 166 - Ant.println(" Results array:", results); 166 + console.log(" Results array:", results); 167 167 168 168 // Test 16: Complex condition in for loop 169 - Ant.println("\nTest 16: Complex condition"); 169 + console.log("\nTest 16: Complex condition"); 170 170 let complexSum = 0; 171 171 for (let i = 0; i < 20 && complexSum < 50; i = i + 1) { 172 172 complexSum = complexSum + i; 173 173 } 174 - Ant.println(" Sum stopped at:", complexSum); 174 + console.log(" Sum stopped at:", complexSum); 175 175 176 176 // Test 17: For loop with function calls 177 - Ant.println("\nTest 17: For loop with function calls"); 177 + console.log("\nTest 17: For loop with function calls"); 178 178 function square(n) { 179 179 return n * n; 180 180 } ··· 183 183 for (let i = 1; i <= 4; i = i + 1) { 184 184 squareSum = squareSum + square(i); 185 185 } 186 - Ant.println(" Sum of squares 1-4:", squareSum); 186 + console.log(" Sum of squares 1-4:", squareSum); 187 187 188 188 // Test 18: Return object from loop 189 - Ant.println("\nTest 18: Return object from loop"); 189 + console.log("\nTest 18: Return object from loop"); 190 190 function findObject(arr, id) { 191 191 for (let i = 0; i < arr.length; i = i + 1) { 192 192 if (arr[i].id === id) { ··· 203 203 ]; 204 204 205 205 const found = findObject(items, 2); 206 - Ant.println(" Found item:", found ? found.name : "null"); 206 + console.log(" Found item:", found ? found.name : "null"); 207 207 208 208 // Test 19: For loop with undefined check 209 - Ant.println("\nTest 19: For loop with undefined check"); 209 + console.log("\nTest 19: For loop with undefined check"); 210 210 const sparse = [1, 2, undefined, 4, 5]; 211 211 let definedCount = 0; 212 212 for (let i = 0; i < sparse.length; i = i + 1) { ··· 214 214 definedCount = definedCount + 1; 215 215 } 216 216 } 217 - Ant.println(" Defined elements:", definedCount); 217 + console.log(" Defined elements:", definedCount); 218 218 219 219 // Test 20: Performance test 220 - Ant.println("\nTest 20: Large loop"); 220 + console.log("\nTest 20: Large loop"); 221 221 let largeSum = 0; 222 222 for (let i = 0; i < 1000; i = i + 1) { 223 223 largeSum = largeSum + i; 224 224 } 225 - Ant.println(" Sum of 0-999:", largeSum); 225 + console.log(" Sum of 0-999:", largeSum); 226 226 227 - Ant.println("\n=== All tests completed ==="); 227 + console.log("\n=== All tests completed ===");
+5 -5
tests/function_name_demo.cjs
··· 8 8 return x + y; 9 9 } 10 10 11 - Ant.println("Function names:"); 12 - Ant.println("myFunction.name = " + myFunction.name); 13 - Ant.println("anotherFunction.name = " + anotherFunction.name); 11 + console.log("Function names:"); 12 + console.log("myFunction.name = " + myFunction.name); 13 + console.log("anotherFunction.name = " + anotherFunction.name); 14 14 15 15 // Anonymous function has empty name 16 16 let anon = function() { return 42; }; 17 - Ant.println("anon.name = '" + anon.name + "' (empty for anonymous functions)"); 17 + console.log("anon.name = '" + anon.name + "' (empty for anonymous functions)"); 18 18 19 19 // Named function expression 20 20 let named = function namedFunc() { return 100; }; 21 - Ant.println("named.name = " + named.name); 21 + console.log("named.name = " + named.name);
+23 -23
tests/function_objects.cjs
··· 10 10 greet.description = "A greeting function"; 11 11 12 12 // Accessing function properties 13 - Ant.println("Function name: " + greet.name); 14 - Ant.println("Description: " + greet.description); 13 + console.log("Function name: " + greet.name); 14 + console.log("Description: " + greet.description); 15 15 16 16 // The __code property contains the function's bytecode/implementation 17 - Ant.println("\n--- Function __code property ---"); 18 - Ant.println("greet.__code: " + greet.__code); 19 - Ant.println("Type of __code: " + typeof greet.__code); 17 + console.log("\n--- Function __code property ---"); 18 + console.log("greet.__code: " + greet.__code); 19 + console.log("Type of __code: " + typeof greet.__code); 20 20 21 21 // We can call the function normally 22 22 let result = greet("World"); 23 - Ant.println("\nCalling greet('World'): " + result); 23 + console.log("\nCalling greet('World'): " + result); 24 24 25 25 // Demonstrate with a more complex function 26 26 function fibonacci(n) { ··· 33 33 fibonacci.purpose = "Calculate Fibonacci numbers"; 34 34 fibonacci.complexity = "O(2^n) - exponential"; 35 35 36 - Ant.println("\n--- Another function example ---"); 37 - Ant.println("Function: " + fibonacci.name); 38 - Ant.println("Purpose: " + fibonacci.purpose); 39 - Ant.println("Complexity: " + fibonacci.complexity); 40 - Ant.println("fibonacci.__code: " + fibonacci.__code); 36 + console.log("\n--- Another function example ---"); 37 + console.log("Function: " + fibonacci.name); 38 + console.log("Purpose: " + fibonacci.purpose); 39 + console.log("Complexity: " + fibonacci.complexity); 40 + console.log("fibonacci.__code: " + fibonacci.__code); 41 41 42 42 // Call it 43 - Ant.println("fibonacci(7) = " + fibonacci(7)); 43 + console.log("fibonacci(7) = " + fibonacci(7)); 44 44 45 45 // Functions can be stored in objects 46 46 let mathOps = { ··· 48 48 multiply: function(a, b) { return a * b; } 49 49 }; 50 50 51 - Ant.println("\n--- Functions as object properties ---"); 52 - Ant.println("mathOps.add: " + mathOps.add); 53 - Ant.println("mathOps.add.__code: " + mathOps.add.__code); 54 - Ant.println("mathOps.add(5, 3) = " + mathOps.add(5, 3)); 51 + console.log("\n--- Functions as object properties ---"); 52 + console.log("mathOps.add: " + mathOps.add); 53 + console.log("mathOps.add.__code: " + mathOps.add.__code); 54 + console.log("mathOps.add(5, 3) = " + mathOps.add(5, 3)); 55 55 56 56 // Functions can be assigned to variables 57 57 let myFunc = greet; 58 58 myFunc.newProperty = "Added to the reference"; 59 59 60 - Ant.println("\n--- Function assignment ---"); 61 - Ant.println("myFunc === greet: " + (myFunc === greet)); 62 - Ant.println("myFunc.__code: " + myFunc.__code); 63 - Ant.println("myFunc('Alice'): " + myFunc('Alice')); 60 + console.log("\n--- Function assignment ---"); 61 + console.log("myFunc === greet: " + (myFunc === greet)); 62 + console.log("myFunc.__code: " + myFunc.__code); 63 + console.log("myFunc('Alice'): " + myFunc('Alice')); 64 64 65 65 // Anonymous function 66 66 let anon = function(x) { return x * 2; }; 67 - Ant.println("\n--- Anonymous function ---"); 68 - Ant.println("anon.__code: " + anon.__code); 69 - Ant.println("anon(21) = " + anon(21)); 67 + console.log("\n--- Anonymous function ---"); 68 + console.log("anon.__code: " + anon.__code); 69 + console.log("anon(21) = " + anon(21));
+12 -12
tests/iife.cjs
··· 2 2 3 3 // Basic IIFE with no parameters 4 4 let result1 = (() => 43)(); 5 - Ant.println("Basic IIFE:", result1); // Should be 43 5 + console.log("Basic IIFE:", result1); // Should be 43 6 6 7 7 // IIFE with expression body 8 8 let result2 = (() => 10 + 5)(); 9 - Ant.println("Expression IIFE:", result2); // Should be 15 9 + console.log("Expression IIFE:", result2); // Should be 15 10 10 11 11 // IIFE with block body 12 12 let result3 = (() => { return 99; })(); 13 - Ant.println("Block IIFE:", result3); // Should be 99 13 + console.log("Block IIFE:", result3); // Should be 99 14 14 15 15 // IIFE with parameters 16 16 let result4 = ((x) => x * 2)(21); 17 - Ant.println("IIFE with param:", result4); // Should be 42 17 + console.log("IIFE with param:", result4); // Should be 42 18 18 19 19 // IIFE with multiple parameters 20 20 let result5 = ((a, b) => a + b)(30, 12); 21 - Ant.println("IIFE with multiple params:", result5); // Should be 42 21 + console.log("IIFE with multiple params:", result5); // Should be 42 22 22 23 23 // Nested IIFE 24 24 let result6 = (() => (() => 7)())(); 25 - Ant.println("Nested IIFE:", result6); // Should be 7 25 + console.log("Nested IIFE:", result6); // Should be 7 26 26 27 27 // IIFE returning object (like module pattern) 28 28 let counter = (() => { ··· 33 33 }; 34 34 })(); 35 35 36 - Ant.println("Counter initial:", counter.get()); // Should be 0 37 - Ant.println("Counter after increment:", counter.increment()); // Should be 1 38 - Ant.println("Counter after increment:", counter.increment()); // Should be 2 39 - Ant.println("Counter value:", counter.get()); // Should be 2 36 + console.log("Counter initial:", counter.get()); // Should be 0 37 + console.log("Counter after increment:", counter.increment()); // Should be 1 38 + console.log("Counter after increment:", counter.increment()); // Should be 2 39 + console.log("Counter value:", counter.get()); // Should be 2 40 40 41 41 // Complex expression in IIFE 42 42 let result7 = ((x, y) => x * 2 + y * 3)(5, 10); 43 - Ant.println("Complex expression:", result7); // Should be 40 43 + console.log("Complex expression:", result7); // Should be 40 44 44 45 - Ant.println("\nAll arrow function IIFE tests completed!"); 45 + console.log("\nAll arrow function IIFE tests completed!");
+44 -44
tests/instanceof.cjs
··· 6 6 let bool = true; 7 7 let obj = {}; 8 8 9 - Ant.println(str instanceof String); // true 10 - Ant.println(num instanceof Number); // true 11 - Ant.println(bool instanceof Boolean); // true 12 - Ant.println(obj instanceof Object); // true 9 + console.log(str instanceof String); // true 10 + console.log(num instanceof Number); // true 11 + console.log(bool instanceof Boolean); // true 12 + console.log(obj instanceof Object); // true 13 13 14 14 // Test instanceof with wrong types 15 - Ant.println(str instanceof Number); // false 16 - Ant.println(num instanceof String); // false 17 - Ant.println(bool instanceof Object); // false 18 - Ant.println(obj instanceof Function); // false 15 + console.log(str instanceof Number); // false 16 + console.log(num instanceof String); // false 17 + console.log(bool instanceof Object); // false 18 + console.log(obj instanceof Function); // false 19 19 20 20 // Test instanceof with functions 21 21 function myFunc() { ··· 26 26 return "hello"; 27 27 }; 28 28 29 - Ant.println(myFunc instanceof Function); // true 30 - Ant.println(funcExpr instanceof Function); // true 31 - Ant.println(myFunc instanceof Object); // false 29 + console.log(myFunc instanceof Function); // true 30 + console.log(funcExpr instanceof Function); // true 31 + console.log(myFunc instanceof Object); // false 32 32 33 33 // Test String() constructor 34 - Ant.println(String(42)); // "42" 35 - Ant.println(String(true)); // "true" 36 - Ant.println(String(false)); // "false" 37 - Ant.println(String(null)); // "null" 38 - Ant.println(String({})); // [object Object] or similar 34 + console.log(String(42)); // "42" 35 + console.log(String(true)); // "true" 36 + console.log(String(false)); // "false" 37 + console.log(String(null)); // "null" 38 + console.log(String({})); // [object Object] or similar 39 39 40 40 let converted = String(123); 41 - Ant.println(converted instanceof String); // true 42 - Ant.println(typeof converted); // string 41 + console.log(converted instanceof String); // true 42 + console.log(typeof converted); // string 43 43 44 44 // Test Number() constructor 45 - Ant.println(Number("123")); // 123 46 - Ant.println(Number("3.14")); // 3.14 47 - Ant.println(Number(true)); // 1 48 - Ant.println(Number(false)); // 0 49 - Ant.println(Number(null)); // 0 45 + console.log(Number("123")); // 123 46 + console.log(Number("3.14")); // 3.14 47 + console.log(Number(true)); // 1 48 + console.log(Number(false)); // 0 49 + console.log(Number(null)); // 0 50 50 51 51 let numConverted = Number("456"); 52 - Ant.println(numConverted instanceof Number); // true 53 - Ant.println(typeof numConverted); // number 52 + console.log(numConverted instanceof Number); // true 53 + console.log(typeof numConverted); // number 54 54 55 55 // Test Boolean() constructor 56 - Ant.println(Boolean(1)); // true 57 - Ant.println(Boolean(0)); // false 58 - Ant.println(Boolean("hello")); // true 59 - Ant.println(Boolean("")); // false 60 - Ant.println(Boolean(null)); // false 61 - Ant.println(Boolean({})); // true 56 + console.log(Boolean(1)); // true 57 + console.log(Boolean(0)); // false 58 + console.log(Boolean("hello")); // true 59 + console.log(Boolean("")); // false 60 + console.log(Boolean(null)); // false 61 + console.log(Boolean({})); // true 62 62 63 63 let boolConverted = Boolean("test"); 64 - Ant.println(boolConverted instanceof Boolean); // true 65 - Ant.println(typeof boolConverted); // boolean 64 + console.log(boolConverted instanceof Boolean); // true 65 + console.log(typeof boolConverted); // boolean 66 66 67 67 // Test Object() constructor 68 68 let emptyObj = Object(); 69 - Ant.println(typeof emptyObj); // object 70 - Ant.println(emptyObj instanceof Object); // true 69 + console.log(typeof emptyObj); // object 70 + console.log(emptyObj instanceof Object); // true 71 71 72 72 // Compare with typeof 73 - Ant.println(typeof str); // string 74 - Ant.println(typeof num); // number 75 - Ant.println(typeof bool); // boolean 76 - Ant.println(typeof obj); // object 77 - Ant.println(typeof myFunc); // function 73 + console.log(typeof str); // string 74 + console.log(typeof num); // number 75 + console.log(typeof bool); // boolean 76 + console.log(typeof obj); // object 77 + console.log(typeof myFunc); // function 78 78 79 79 // Mixed operations 80 80 let x = Number("10"); 81 81 let y = Number("20"); 82 82 let result = x + y; 83 - Ant.println(result); // 30 84 - Ant.println(result instanceof Number); // true 83 + console.log(result); // 30 84 + console.log(result instanceof Number); // true 85 85 86 86 let greeting = String("Hello ") + String("World"); 87 - Ant.println(greeting); // Hello World 88 - Ant.println(greeting instanceof String); // true 87 + console.log(greeting); // Hello World 88 + console.log(greeting instanceof String); // true
+2 -2
tests/multi_server.cjs
··· 14 14 }; 15 15 } 16 16 17 - Ant.println("Starting multiple HTTP servers..."); 17 + console.log("Starting multiple HTTP servers..."); 18 18 19 19 // Note: Currently Ant.serve() is blocking, so you can only run one server 20 20 // In the future, we could make it non-blocking to support truly concurrent servers 21 - Ant.println("Starting server on port 8000..."); 21 + console.log("Starting server on port 8000..."); 22 22 Ant.serve(8000, handler8000);
+1 -1
tests/nanoid.cjs
··· 11 11 return id; 12 12 } 13 13 14 - Ant.println(nanoid(21)); 14 + console.log(nanoid(21));
+58 -58
tests/object_in_if.cjs
··· 1 1 // Test objects in if statements 2 2 // Tests property access and truthiness evaluation 3 3 4 - Ant.println("=== Object in If Statements Test ===\n"); 4 + console.log("=== Object in If Statements Test ===\n"); 5 5 6 6 // Test 1: Basic object property truthiness 7 - Ant.println("Test 1: Object property truthiness"); 7 + console.log("Test 1: Object property truthiness"); 8 8 let thing = { 9 9 hasThing: true, 10 10 hasOther: false, ··· 13 13 }; 14 14 15 15 if (thing.hasThing) { 16 - Ant.println(" thing.hasThing is truthy: PASS"); 16 + console.log(" thing.hasThing is truthy: PASS"); 17 17 } 18 18 19 19 if (!thing.hasOther) { 20 - Ant.println(" !thing.hasOther is falsy: PASS"); 20 + console.log(" !thing.hasOther is falsy: PASS"); 21 21 } 22 22 23 23 if (thing.count) { 24 - Ant.println(" thing.count (5) is truthy: PASS"); 24 + console.log(" thing.count (5) is truthy: PASS"); 25 25 } 26 26 27 27 if (thing.name) { 28 - Ant.println(" thing.name ('test') is truthy: PASS"); 28 + console.log(" thing.name ('test') is truthy: PASS"); 29 29 } 30 30 31 31 // Test 2: Undefined and null properties 32 - Ant.println("\nTest 2: Undefined and null properties"); 32 + console.log("\nTest 2: Undefined and null properties"); 33 33 let obj = { 34 34 defined: "value", 35 35 nullValue: null, ··· 39 39 }; 40 40 41 41 if (!obj.nonExistent) { 42 - Ant.println(" !obj.nonExistent (undefined): PASS"); 42 + console.log(" !obj.nonExistent (undefined): PASS"); 43 43 } 44 44 45 45 if (!obj.nullValue) { 46 - Ant.println(" !obj.nullValue (null): PASS"); 46 + console.log(" !obj.nullValue (null): PASS"); 47 47 } 48 48 49 49 if (!obj.undefinedValue) { 50 - Ant.println(" !obj.undefinedValue (undefined): PASS"); 50 + console.log(" !obj.undefinedValue (undefined): PASS"); 51 51 } 52 52 53 53 if (!obj.zeroValue) { 54 - Ant.println(" !obj.zeroValue (0): PASS"); 54 + console.log(" !obj.zeroValue (0): PASS"); 55 55 } 56 56 57 57 if (!obj.emptyString) { 58 - Ant.println(" !obj.emptyString (''): PASS"); 58 + console.log(" !obj.emptyString (''): PASS"); 59 59 } 60 60 61 61 if (obj.defined) { 62 - Ant.println(" obj.defined ('value'): PASS"); 62 + console.log(" obj.defined ('value'): PASS"); 63 63 } 64 64 65 65 // Test 3: Nested object properties 66 - Ant.println("\nTest 3: Nested object properties"); 66 + console.log("\nTest 3: Nested object properties"); 67 67 let config = { 68 68 settings: { 69 69 enabled: true, ··· 75 75 }; 76 76 77 77 if (config.settings) { 78 - Ant.println(" config.settings exists: PASS"); 78 + console.log(" config.settings exists: PASS"); 79 79 } 80 80 81 81 if (config.settings.enabled) { 82 - Ant.println(" config.settings.enabled is true: PASS"); 82 + console.log(" config.settings.enabled is true: PASS"); 83 83 } 84 84 85 85 if (!config.settings.disabled) { 86 - Ant.println(" !config.settings.disabled is false: PASS"); 86 + console.log(" !config.settings.disabled is false: PASS"); 87 87 } 88 88 89 89 if (config.settings.nested) { 90 - Ant.println(" config.settings.nested exists: PASS"); 90 + console.log(" config.settings.nested exists: PASS"); 91 91 } 92 92 93 93 if (config.settings.nested.deep) { 94 - Ant.println(" config.settings.nested.deep has value: PASS"); 94 + console.log(" config.settings.nested.deep has value: PASS"); 95 95 } 96 96 97 97 // Test 4: Function properties 98 - Ant.println("\nTest 4: Function properties"); 98 + console.log("\nTest 4: Function properties"); 99 99 let api = { 100 100 hasMethod: function() { 101 101 return "called"; ··· 104 104 }; 105 105 106 106 if (api.hasMethod) { 107 - Ant.println(" api.hasMethod exists:", api.hasMethod()); 107 + console.log(" api.hasMethod exists:", api.hasMethod()); 108 108 } 109 109 110 110 if (!api.noMethod) { 111 - Ant.println(" !api.noMethod is null: PASS"); 111 + console.log(" !api.noMethod is null: PASS"); 112 112 } 113 113 114 114 // Test 5: Array properties 115 - Ant.println("\nTest 5: Array properties"); 115 + console.log("\nTest 5: Array properties"); 116 116 let data = { 117 117 items: [1, 2, 3], 118 118 emptyItems: [], ··· 120 120 }; 121 121 122 122 if (data.items) { 123 - Ant.println(" data.items exists, length:", data.items.length); 123 + console.log(" data.items exists, length:", data.items.length); 124 124 } 125 125 126 126 if (data.emptyItems) { 127 - Ant.println(" data.emptyItems exists but empty, length:", data.emptyItems.length); 127 + console.log(" data.emptyItems exists but empty, length:", data.emptyItems.length); 128 128 } 129 129 130 130 if (!data.noItems) { 131 - Ant.println(" !data.noItems is null: PASS"); 131 + console.log(" !data.noItems is null: PASS"); 132 132 } 133 133 134 134 // Test 6: Conditional checks with property access 135 - Ant.println("\nTest 6: Conditional property checks"); 135 + console.log("\nTest 6: Conditional property checks"); 136 136 let user = { 137 137 name: "John", 138 138 age: 30, ··· 140 140 }; 141 141 142 142 if (user.name && user.age) { 143 - Ant.println(" user.name && user.age both exist: PASS"); 143 + console.log(" user.name && user.age both exist: PASS"); 144 144 } 145 145 146 146 if (user.active && user.name) { 147 - Ant.println(" user.active && user.name both truthy: PASS"); 147 + console.log(" user.active && user.name both truthy: PASS"); 148 148 } 149 149 150 150 if (!user.deleted || user.active) { 151 - Ant.println(" !user.deleted || user.active: PASS"); 151 + console.log(" !user.deleted || user.active: PASS"); 152 152 } 153 153 154 154 // Test 7: Return based on object property 155 - Ant.println("\nTest 7: Return based on property"); 155 + console.log("\nTest 7: Return based on property"); 156 156 function checkUser(user) { 157 157 if (!user) return { error: "no user" }; 158 158 if (!user.name) return { error: "no name" }; 159 159 return { success: true, name: user.name }; 160 160 } 161 161 162 - Ant.println(" With null:", checkUser(null)); 163 - Ant.println(" With no name:", checkUser({ age: 25 })); 164 - Ant.println(" With name:", checkUser({ name: "Alice" })); 162 + console.log(" With null:", checkUser(null)); 163 + console.log(" With no name:", checkUser({ age: 25 })); 164 + console.log(" With name:", checkUser({ name: "Alice" })); 165 165 166 166 // Test 8: Object itself as condition 167 - Ant.println("\nTest 8: Object as condition"); 167 + console.log("\nTest 8: Object as condition"); 168 168 let obj1 = { value: 1 }; 169 169 let obj2 = null; 170 170 let obj3 = undefined; 171 171 172 172 if (obj1) { 173 - Ant.println(" obj1 (object) is truthy: PASS"); 173 + console.log(" obj1 (object) is truthy: PASS"); 174 174 } 175 175 176 176 if (!obj2) { 177 - Ant.println(" !obj2 (null) is falsy: PASS"); 177 + console.log(" !obj2 (null) is falsy: PASS"); 178 178 } 179 179 180 180 if (!obj3) { 181 - Ant.println(" !obj3 (undefined) is falsy: PASS"); 181 + console.log(" !obj3 (undefined) is falsy: PASS"); 182 182 } 183 183 184 184 // Test 9: Boolean properties in complex conditions 185 - Ant.println("\nTest 9: Complex boolean property checks"); 185 + console.log("\nTest 9: Complex boolean property checks"); 186 186 let feature = { 187 187 enabled: true, 188 188 experimental: false, ··· 191 191 }; 192 192 193 193 if (feature.enabled && feature.beta) { 194 - Ant.println(" enabled && beta: PASS"); 194 + console.log(" enabled && beta: PASS"); 195 195 } 196 196 197 197 if (feature.enabled && !feature.stable) { 198 - Ant.println(" enabled && !stable: PASS"); 198 + console.log(" enabled && !stable: PASS"); 199 199 } 200 200 201 201 if (!feature.experimental && !feature.stable) { 202 - Ant.println(" !experimental && !stable: PASS"); 202 + console.log(" !experimental && !stable: PASS"); 203 203 } 204 204 205 205 // Test 10: Property chain with guard 206 - Ant.println("\nTest 10: Safe property access"); 206 + console.log("\nTest 10: Safe property access"); 207 207 function getValue(obj) { 208 208 if (!obj) return "no object"; 209 209 if (!obj.data) return "no data"; ··· 211 211 return obj.data.value; 212 212 } 213 213 214 - Ant.println(" With null:", getValue(null)); 215 - Ant.println(" With no data:", getValue({})); 216 - Ant.println(" With no value:", getValue({ data: {} })); 217 - Ant.println(" With value:", getValue({ data: { value: "found" } })); 214 + console.log(" With null:", getValue(null)); 215 + console.log(" With no data:", getValue({})); 216 + console.log(" With no value:", getValue({ data: {} })); 217 + console.log(" With value:", getValue({ data: { value: "found" } })); 218 218 219 219 // Test 11: Optional chaining with undefined/null values 220 - Ant.println("\nTest 11: Optional chaining (?.)"); 220 + console.log("\nTest 11: Optional chaining (?.)"); 221 221 const value = undefined; 222 222 const nullValue = null; 223 223 const obj11 = { nested: { deep: "value" } }; 224 224 225 - Ant.println(" value?.thing (undefined):", value?.thing); 226 - Ant.println(" nullValue?.thing (null):", nullValue?.thing); 227 - Ant.println(" obj11?.nested?.deep:", obj11?.nested?.deep); 228 - Ant.println(" obj11?.missing?.deep:", obj11?.missing?.deep); 225 + console.log(" value?.thing (undefined):", value?.thing); 226 + console.log(" nullValue?.thing (null):", nullValue?.thing); 227 + console.log(" obj11?.nested?.deep:", obj11?.nested?.deep); 228 + console.log(" obj11?.missing?.deep:", obj11?.missing?.deep); 229 229 230 230 if (value?.thing) { 231 - Ant.println(" FAIL: value?.thing should be undefined"); 231 + console.log(" FAIL: value?.thing should be undefined"); 232 232 } else { 233 - Ant.println(" value?.thing is falsy: PASS"); 233 + console.log(" value?.thing is falsy: PASS"); 234 234 } 235 235 236 236 if (!nullValue?.thing) { 237 - Ant.println(" !nullValue?.thing is falsy: PASS"); 237 + console.log(" !nullValue?.thing is falsy: PASS"); 238 238 } 239 239 240 240 if (obj11?.nested?.deep) { 241 - Ant.println(" obj11?.nested?.deep exists: PASS"); 241 + console.log(" obj11?.nested?.deep exists: PASS"); 242 242 } 243 243 244 244 if (!obj11?.missing?.deep) { 245 - Ant.println(" !obj11?.missing?.deep is falsy: PASS"); 245 + console.log(" !obj11?.missing?.deep is falsy: PASS"); 246 246 } 247 247 248 - Ant.println("\n=== All tests completed ==="); 248 + console.log("\n=== All tests completed ===");
+29 -29
tests/object_keys.cjs
··· 1 1 // Test Object.keys() functionality 2 2 3 - Ant.println("=== Object.keys() Tests ===\n"); 3 + console.log("=== Object.keys() Tests ===\n"); 4 4 5 5 // Test 1: Basic object with string keys 6 - Ant.println("Test 1: Basic object"); 6 + console.log("Test 1: Basic object"); 7 7 let obj1 = { a: 1, b: 2, c: 3 }; 8 8 let keys1 = Object.keys(obj1); 9 - Ant.println(" Keys length:", keys1.length); 9 + console.log(" Keys length:", keys1.length); 10 10 for (let i = 0; i < keys1.length; i++) { 11 - Ant.println(" " + keys1[i] + ": " + obj1[keys1[i]]); 11 + console.log(" " + keys1[i] + ": " + obj1[keys1[i]]); 12 12 } 13 13 14 14 // Test 2: Empty object 15 - Ant.println("\nTest 2: Empty object"); 15 + console.log("\nTest 2: Empty object"); 16 16 let obj2 = {}; 17 17 let keys2 = Object.keys(obj2); 18 - Ant.println(" Keys length:", keys2.length); 18 + console.log(" Keys length:", keys2.length); 19 19 20 20 // Test 3: Object with various property types 21 - Ant.println("\nTest 3: Object with various properties"); 21 + console.log("\nTest 3: Object with various properties"); 22 22 let obj3 = { 23 23 name: "John", 24 24 age: 30, 25 25 active: true 26 26 }; 27 27 let keys3 = Object.keys(obj3); 28 - Ant.println(" Keys found:"); 28 + console.log(" Keys found:"); 29 29 for (let i = 0; i < keys3.length; i++) { 30 - Ant.println(" " + keys3[i]); 30 + console.log(" " + keys3[i]); 31 31 } 32 32 33 33 // Test 4: Iterating using Object.keys 34 - Ant.println("\nTest 4: Iterate using Object.keys"); 34 + console.log("\nTest 4: Iterate using Object.keys"); 35 35 let person = { 36 36 firstName: "Alice", 37 37 lastName: "Smith", 38 38 age: 25 39 39 }; 40 40 let personKeys = Object.keys(person); 41 - Ant.println(" Person properties:"); 41 + console.log(" Person properties:"); 42 42 for (let i = 0; i < personKeys.length; i++) { 43 43 let key = personKeys[i]; 44 - Ant.println(" " + key + " = " + person[key]); 44 + console.log(" " + key + " = " + person[key]); 45 45 } 46 46 47 47 // Test 5: Object.keys with array 48 - Ant.println("\nTest 5: Object.keys with array"); 48 + console.log("\nTest 5: Object.keys with array"); 49 49 let arr = ["a", "b", "c"]; 50 50 let arrKeys = Object.keys(arr); 51 - Ant.println(" Array keys length:", arrKeys.length); 52 - Ant.println(" Array keys:"); 51 + console.log(" Array keys length:", arrKeys.length); 52 + console.log(" Array keys:"); 53 53 for (let i = 0; i < arrKeys.length; i++) { 54 - Ant.println(" " + arrKeys[i]); 54 + console.log(" " + arrKeys[i]); 55 55 } 56 56 57 57 // Test 6: Nested object iteration 58 - Ant.println("\nTest 6: Nested object"); 58 + console.log("\nTest 6: Nested object"); 59 59 let nested = { 60 60 user: { 61 61 name: "Bob", ··· 67 67 } 68 68 }; 69 69 let nestedKeys = Object.keys(nested); 70 - Ant.println(" Top-level keys:"); 70 + console.log(" Top-level keys:"); 71 71 for (let i = 0; i < nestedKeys.length; i++) { 72 - Ant.println(" " + nestedKeys[i]); 72 + console.log(" " + nestedKeys[i]); 73 73 } 74 74 75 75 // Test 7: Using Object.keys for validation 76 - Ant.println("\nTest 7: Key validation"); 76 + console.log("\nTest 7: Key validation"); 77 77 let config = { 78 78 host: "localhost", 79 79 port: 8080, ··· 81 81 }; 82 82 let requiredKeys = ["host", "port"]; 83 83 let configKeys = Object.keys(config); 84 - Ant.println(" Config has " + configKeys.length + " keys"); 85 - Ant.println(" Required keys present:"); 84 + console.log(" Config has " + configKeys.length + " keys"); 85 + console.log(" Required keys present:"); 86 86 for (let i = 0; i < requiredKeys.length; i++) { 87 87 let hasKey = false; 88 88 for (let j = 0; j < configKeys.length; j++) { ··· 90 90 hasKey = true; 91 91 } 92 92 } 93 - Ant.println(" " + requiredKeys[i] + ": " + (hasKey ? "yes" : "no")); 93 + console.log(" " + requiredKeys[i] + ": " + (hasKey ? "yes" : "no")); 94 94 } 95 95 96 96 // Test 8: Copy object using Object.keys 97 - Ant.println("\nTest 8: Copy object"); 97 + console.log("\nTest 8: Copy object"); 98 98 let original = { x: 10, y: 20, z: 30 }; 99 99 let copy = {}; 100 100 let originalKeys = Object.keys(original); ··· 103 103 copy[key] = original[key]; 104 104 } 105 105 let copyKeys = Object.keys(copy); 106 - Ant.println(" Original keys:", originalKeys.length); 107 - Ant.println(" Copy keys:", copyKeys.length); 108 - Ant.println(" Copy values:"); 106 + console.log(" Original keys:", originalKeys.length); 107 + console.log(" Copy keys:", copyKeys.length); 108 + console.log(" Copy values:"); 109 109 for (let i = 0; i < copyKeys.length; i++) { 110 - Ant.println(" " + copyKeys[i] + " = " + copy[copyKeys[i]]); 110 + console.log(" " + copyKeys[i] + " = " + copy[copyKeys[i]]); 111 111 } 112 112 113 - Ant.println("\n=== All tests completed ==="); 113 + console.log("\n=== All tests completed ===");
+38 -38
tests/radix3.cjs
··· 235 235 line = line + " :" + node.paramName; 236 236 } 237 237 238 - Ant.println(line); 238 + console.log(line); 239 239 240 240 let childPrefix = prefix + (isLast ? " " : "โ”‚ "); 241 241 ··· 250 250 // Print param child 251 251 if (node.paramChild !== undefined) { 252 252 let isLastChild = node.wildcardChild === undefined; 253 - Ant.println(childPrefix + (isLastChild ? "โ””โ”€ " : "โ”œโ”€ ") + ":" + node.paramChild.paramName); 253 + console.log(childPrefix + (isLastChild ? "โ””โ”€ " : "โ”œโ”€ ") + ":" + node.paramChild.paramName); 254 254 this.printNode(node.paramChild, childPrefix + (isLastChild ? " " : "โ”‚ "), true); 255 255 } 256 256 257 257 // Print wildcard child 258 258 if (node.wildcardChild !== undefined) { 259 - Ant.println(childPrefix + "โ””โ”€ *" + node.wildcardChild.paramName); 259 + console.log(childPrefix + "โ””โ”€ *" + node.wildcardChild.paramName); 260 260 this.printNode(node.wildcardChild, childPrefix + " ", true); 261 261 } 262 262 } ··· 266 266 // Tests 267 267 // ============================================================================ 268 268 269 - Ant.println("=== Radix3 Router Tests ===\n"); 269 + console.log("=== Radix3 Router Tests ===\n"); 270 270 271 271 let router = new Radix3(); 272 272 ··· 285 285 router.insert("/files/*path", function(p) { return "File: " + p.path; }); 286 286 router.insert("/docs/*rest", function(p) { return "Docs: " + p.rest; }); 287 287 288 - Ant.println("Tree structure:"); 289 - Ant.println("==============="); 288 + console.log("Tree structure:"); 289 + console.log("==============="); 290 290 router.printTree(); 291 - Ant.println(""); 291 + console.log(""); 292 292 293 293 // Run tests 294 - Ant.println("Lookup tests:"); 295 - Ant.println("============="); 294 + console.log("Lookup tests:"); 295 + console.log("============="); 296 296 297 - Ant.println("1. /"); 298 - Ant.println(" =>", router.lookup("/")); 297 + console.log("1. /"); 298 + console.log(" =>", router.lookup("/")); 299 299 300 - Ant.println("\n2. /user"); 301 - Ant.println(" =>", router.lookup("/user")); 300 + console.log("\n2. /user"); 301 + console.log(" =>", router.lookup("/user")); 302 302 303 - Ant.println("\n3. /users"); 304 - Ant.println(" =>", router.lookup("/users")); 303 + console.log("\n3. /users"); 304 + console.log(" =>", router.lookup("/users")); 305 305 306 - Ant.println("\n4. /users/list"); 307 - Ant.println(" =>", router.lookup("/users/list")); 306 + console.log("\n4. /users/list"); 307 + console.log(" =>", router.lookup("/users/list")); 308 308 309 - Ant.println("\n5. /users/123"); 310 - Ant.println(" =>", router.lookup("/users/123")); 309 + console.log("\n5. /users/123"); 310 + console.log(" =>", router.lookup("/users/123")); 311 311 312 - Ant.println("\n6. /users/456/posts"); 313 - Ant.println(" =>", router.lookup("/users/456/posts")); 312 + console.log("\n6. /users/456/posts"); 313 + console.log(" =>", router.lookup("/users/456/posts")); 314 314 315 - Ant.println("\n7. /search"); 316 - Ant.println(" =>", router.lookup("/search")); 315 + console.log("\n7. /search"); 316 + console.log(" =>", router.lookup("/search")); 317 317 318 - Ant.println("\n8. /static/home"); 319 - Ant.println(" =>", router.lookup("/static/home")); 318 + console.log("\n8. /static/home"); 319 + console.log(" =>", router.lookup("/static/home")); 320 320 321 - Ant.println("\n9. /static/about"); 322 - Ant.println(" =>", router.lookup("/static/about")); 321 + console.log("\n9. /static/about"); 322 + console.log(" =>", router.lookup("/static/about")); 323 323 324 - Ant.println("\n10. /api/v1/users"); 325 - Ant.println(" =>", router.lookup("/api/v1/users")); 324 + console.log("\n10. /api/v1/users"); 325 + console.log(" =>", router.lookup("/api/v1/users")); 326 326 327 - Ant.println("\n11. /api/v2/users"); 328 - Ant.println(" =>", router.lookup("/api/v2/users")); 327 + console.log("\n11. /api/v2/users"); 328 + console.log(" =>", router.lookup("/api/v2/users")); 329 329 330 - Ant.println("\n12. /files/images/photo.jpg"); 331 - Ant.println(" =>", router.lookup("/files/images/photo.jpg")); 330 + console.log("\n12. /files/images/photo.jpg"); 331 + console.log(" =>", router.lookup("/files/images/photo.jpg")); 332 332 333 - Ant.println("\n13. /docs/api/reference/auth"); 334 - Ant.println(" =>", router.lookup("/docs/api/reference/auth")); 333 + console.log("\n13. /docs/api/reference/auth"); 334 + console.log(" =>", router.lookup("/docs/api/reference/auth")); 335 335 336 - Ant.println("\n14. /notfound (404)"); 337 - Ant.println(" =>", router.lookup("/notfound")); 336 + console.log("\n14. /notfound (404)"); 337 + console.log(" =>", router.lookup("/notfound")); 338 338 339 - Ant.println("\n=== All Tests Complete ==="); 339 + console.log("\n=== All Tests Complete ===");
+77 -77
tests/replace_template.cjs
··· 1 1 // Test String.replace() and String.template() functionality 2 2 3 - Ant.println("=== String.replace() and String.template() Tests ===\n"); 3 + console.log("=== String.replace() and String.template() Tests ===\n"); 4 4 5 5 // Test 1: Basic replace 6 - Ant.println("Test 1: Basic replace"); 6 + console.log("Test 1: Basic replace"); 7 7 let str1 = "hello world"; 8 - Ant.println(" Original:", str1); 9 - Ant.println(" replace('world', 'there'):", str1.replace("world", "there")); 10 - Ant.println(" replace('hello', 'goodbye'):", str1.replace("hello", "goodbye")); 11 - Ant.println(" Original unchanged:", str1); 8 + console.log(" Original:", str1); 9 + console.log(" replace('world', 'there'):", str1.replace("world", "there")); 10 + console.log(" replace('hello', 'goodbye'):", str1.replace("hello", "goodbye")); 11 + console.log(" Original unchanged:", str1); 12 12 13 13 // Test 2: Replace only first occurrence 14 - Ant.println("\nTest 2: Replace first occurrence only"); 14 + console.log("\nTest 2: Replace first occurrence only"); 15 15 let str2 = "the cat and the dog"; 16 - Ant.println(" Original:", str2); 17 - Ant.println(" replace('the', 'a'):", str2.replace("the", "a")); 16 + console.log(" Original:", str2); 17 + console.log(" replace('the', 'a'):", str2.replace("the", "a")); 18 18 let str3 = "hello hello hello"; 19 - Ant.println(" '" + str3 + "'.replace('hello', 'hi'):", str3.replace("hello", "hi")); 19 + console.log(" '" + str3 + "'.replace('hello', 'hi'):", str3.replace("hello", "hi")); 20 20 21 21 // Test 3: Replace not found 22 - Ant.println("\nTest 3: Replace when not found"); 22 + console.log("\nTest 3: Replace when not found"); 23 23 let str4 = "JavaScript"; 24 - Ant.println(" '" + str4 + "'.replace('Python', 'Ruby'):", str4.replace("Python", "Ruby")); 25 - Ant.println(" '" + str4 + "'.replace('java', 'JAVA'):", str4.replace("java", "JAVA")); 24 + console.log(" '" + str4 + "'.replace('Python', 'Ruby'):", str4.replace("Python", "Ruby")); 25 + console.log(" '" + str4 + "'.replace('java', 'JAVA'):", str4.replace("java", "JAVA")); 26 26 27 27 // Test 4: Replace with empty string 28 - Ant.println("\nTest 4: Replace with empty string"); 28 + console.log("\nTest 4: Replace with empty string"); 29 29 let str5 = "remove this word"; 30 - Ant.println(" '" + str5 + "'.replace('this ', ''):", str5.replace("this ", "")); 30 + console.log(" '" + str5 + "'.replace('this ', ''):", str5.replace("this ", "")); 31 31 let str6 = "prefixValue"; 32 - Ant.println(" '" + str6 + "'.replace('prefix', ''):", str6.replace("prefix", "")); 32 + console.log(" '" + str6 + "'.replace('prefix', ''):", str6.replace("prefix", "")); 33 33 34 34 // Test 5: Replace single character 35 - Ant.println("\nTest 5: Replace single character"); 35 + console.log("\nTest 5: Replace single character"); 36 36 let str7 = "hello"; 37 - Ant.println(" '" + str7 + "'.replace('l', 'L'):", str7.replace("l", "L")); 38 - Ant.println(" '" + str7 + "'.replace('h', 'H'):", str7.replace("h", "H")); 39 - Ant.println(" '" + str7 + "'.replace('o', 'O'):", str7.replace("o", "O")); 37 + console.log(" '" + str7 + "'.replace('l', 'L'):", str7.replace("l", "L")); 38 + console.log(" '" + str7 + "'.replace('h', 'H'):", str7.replace("h", "H")); 39 + console.log(" '" + str7 + "'.replace('o', 'O'):", str7.replace("o", "O")); 40 40 41 41 // Test 6: Replace in paths and URLs 42 - Ant.println("\nTest 6: Replace in paths/URLs"); 42 + console.log("\nTest 6: Replace in paths/URLs"); 43 43 let path = "/api/v1/users"; 44 - Ant.println(" Path:", path); 45 - Ant.println(" replace('/api/', '/api/v2/'):", path.replace("/api/", "/api/v2/")); 44 + console.log(" Path:", path); 45 + console.log(" replace('/api/', '/api/v2/'):", path.replace("/api/", "/api/v2/")); 46 46 let url = "http://example.com"; 47 - Ant.println(" URL:", url); 48 - Ant.println(" replace('http://', 'https://'):", url.replace("http://", "https://")); 47 + console.log(" URL:", url); 48 + console.log(" replace('http://', 'https://'):", url.replace("http://", "https://")); 49 49 50 50 // Test 7: Basic template 51 - Ant.println("\nTest 7: Basic template()"); 51 + console.log("\nTest 7: Basic template()"); 52 52 let tpl1 = "Hello, {{name}}!"; 53 53 let data1 = { name: "Alice" }; 54 - Ant.println(" Template:", tpl1); 55 - Ant.println(" Data: {name: 'Alice'}"); 56 - Ant.println(" Result:", tpl1.template(data1)); 54 + console.log(" Template:", tpl1); 55 + console.log(" Data: {name: 'Alice'}"); 56 + console.log(" Result:", tpl1.template(data1)); 57 57 58 58 // Test 8: Multiple placeholders 59 - Ant.println("\nTest 8: Multiple placeholders"); 59 + console.log("\nTest 8: Multiple placeholders"); 60 60 let tpl2 = "User {{name}} is {{age}} years old and lives in {{city}}"; 61 61 let data2 = { name: "Bob", age: 30, city: "NYC" }; 62 - Ant.println(" Template:", tpl2); 63 - Ant.println(" Result:", tpl2.template(data2)); 62 + console.log(" Template:", tpl2); 63 + console.log(" Result:", tpl2.template(data2)); 64 64 65 65 // Test 9: Number and boolean values 66 - Ant.println("\nTest 9: Different value types"); 66 + console.log("\nTest 9: Different value types"); 67 67 let tpl3 = "Status: {{active}}, Count: {{count}}, Rate: {{rate}}"; 68 68 let data3 = { active: true, count: 42, rate: 3.14 }; 69 - Ant.println(" Template:", tpl3); 70 - Ant.println(" Result:", tpl3.template(data3)); 69 + console.log(" Template:", tpl3); 70 + console.log(" Result:", tpl3.template(data3)); 71 71 72 72 // Test 10: Missing keys 73 - Ant.println("\nTest 10: Missing keys in data"); 73 + console.log("\nTest 10: Missing keys in data"); 74 74 let tpl4 = "Hello {{first}} {{middle}} {{last}}"; 75 75 let data4 = { first: "John", last: "Doe" }; 76 - Ant.println(" Template:", tpl4); 77 - Ant.println(" Data: {first: 'John', last: 'Doe'}"); 78 - Ant.println(" Result:", tpl4.template(data4)); 79 - Ant.println(" (missing {{middle}} becomes empty)"); 76 + console.log(" Template:", tpl4); 77 + console.log(" Data: {first: 'John', last: 'Doe'}"); 78 + console.log(" Result:", tpl4.template(data4)); 79 + console.log(" (missing {{middle}} becomes empty)"); 80 80 81 81 // Test 11: URL building 82 - Ant.println("\nTest 11: URL building"); 82 + console.log("\nTest 11: URL building"); 83 83 let urlTpl = "https://api.example.com/{{version}}/{{resource}}/{{id}}"; 84 84 let urlData = { version: "v2", resource: "users", id: 123 }; 85 - Ant.println(" Template:", urlTpl); 86 - Ant.println(" Result:", urlTpl.template(urlData)); 85 + console.log(" Template:", urlTpl); 86 + console.log(" Result:", urlTpl.template(urlData)); 87 87 88 88 // Test 12: Configuration 89 - Ant.println("\nTest 12: Configuration messages"); 89 + console.log("\nTest 12: Configuration messages"); 90 90 let configTpl = "Server running on {{host}}:{{port}} in {{mode}} mode"; 91 91 let configData = { host: "localhost", port: 3000, mode: "development" }; 92 - Ant.println(" Template:", configTpl); 93 - Ant.println(" Result:", configTpl.template(configData)); 92 + console.log(" Template:", configTpl); 93 + console.log(" Result:", configTpl.template(configData)); 94 94 95 95 // Test 13: Query template 96 - Ant.println("\nTest 13: Query template"); 96 + console.log("\nTest 13: Query template"); 97 97 let queryTpl = "SELECT * FROM {{table}} WHERE {{field}} = {{value}}"; 98 98 let queryData = { table: "users", field: "id", value: 42 }; 99 - Ant.println(" Template:", queryTpl); 100 - Ant.println(" Result:", queryTpl.template(queryData)); 99 + console.log(" Template:", queryTpl); 100 + console.log(" Result:", queryTpl.template(queryData)); 101 101 102 102 // Test 14: No placeholders 103 - Ant.println("\nTest 14: Template with no placeholders"); 103 + console.log("\nTest 14: Template with no placeholders"); 104 104 let tpl6 = "This is just plain text"; 105 105 let data6 = { name: "unused" }; 106 - Ant.println(" Template:", tpl6); 107 - Ant.println(" Result:", tpl6.template(data6)); 106 + console.log(" Template:", tpl6); 107 + console.log(" Result:", tpl6.template(data6)); 108 108 109 109 // Test 15: All placeholder 110 - Ant.println("\nTest 15: Template is all placeholder"); 110 + console.log("\nTest 15: Template is all placeholder"); 111 111 let tpl7 = "{{value}}"; 112 112 let data7 = { value: "replaced" }; 113 - Ant.println(" Template: '{{value}}'"); 114 - Ant.println(" Result:", tpl7.template(data7)); 113 + console.log(" Template: '{{value}}'"); 114 + console.log(" Result:", tpl7.template(data7)); 115 115 116 116 // Test 16: Combining replace and template 117 - Ant.println("\nTest 16: Combining replace() and template()"); 117 + console.log("\nTest 16: Combining replace() and template()"); 118 118 let message = "Hello {{USER}}, welcome!"; 119 - Ant.println(" Original:", message); 119 + console.log(" Original:", message); 120 120 let normalized = message.replace("{{USER}}", "{{user}}"); 121 - Ant.println(" After replace:", normalized); 121 + console.log(" After replace:", normalized); 122 122 let final = normalized.template({ user: "Charlie" }); 123 - Ant.println(" After template:", final); 123 + console.log(" After template:", final); 124 124 125 125 // Test 17: Replace after template 126 - Ant.println("\nTest 17: Replace after template"); 126 + console.log("\nTest 17: Replace after template"); 127 127 let greetTpl = "Hello, {{name}}!"; 128 128 let greetData = { name: "World" }; 129 129 let greeting = greetTpl.template(greetData); 130 - Ant.println(" After template:", greeting); 130 + console.log(" After template:", greeting); 131 131 let changed = greeting.replace("World", "Universe"); 132 - Ant.println(" After replace:", changed); 132 + console.log(" After replace:", changed); 133 133 134 134 // Test 18: Validation messages 135 - Ant.println("\nTest 18: Validation messages"); 135 + console.log("\nTest 18: Validation messages"); 136 136 let errorTpl = "Field '{{field}}' must be at least {{min}} characters"; 137 137 let errorData = { field: "password", min: 8 }; 138 - Ant.println(" Error template:", errorTpl); 139 - Ant.println(" Result:", errorTpl.template(errorData)); 138 + console.log(" Error template:", errorTpl); 139 + console.log(" Result:", errorTpl.template(errorData)); 140 140 141 141 let successTpl = "{{count}} items processed successfully"; 142 142 let successData = { count: 150 }; 143 - Ant.println(" Success template:", successTpl); 144 - Ant.println(" Result:", successTpl.template(successData)); 143 + console.log(" Success template:", successTpl); 144 + console.log(" Result:", successTpl.template(successData)); 145 145 146 146 // Test 19: Adjacent placeholders 147 - Ant.println("\nTest 19: Adjacent placeholders"); 147 + console.log("\nTest 19: Adjacent placeholders"); 148 148 let adjacent = "{{first}}{{second}}{{third}}"; 149 149 let adjData = { first: "A", second: "B", third: "C" }; 150 - Ant.println(" Template:", adjacent); 151 - Ant.println(" Result:", adjacent.template(adjData)); 150 + console.log(" Template:", adjacent); 151 + console.log(" Result:", adjacent.template(adjData)); 152 152 153 153 // Test 20: Whitespace in placeholder names 154 - Ant.println("\nTest 20: Whitespace in placeholder names"); 154 + console.log("\nTest 20: Whitespace in placeholder names"); 155 155 let wsTpl = "Hello {{userName}} from {{homeCity}}"; 156 156 let wsData = { userName: "Eve", homeCity: "Boston" }; 157 - Ant.println(" Template:", wsTpl); 158 - Ant.println(" Result:", wsTpl.template(wsData)); 157 + console.log(" Template:", wsTpl); 158 + console.log(" Result:", wsTpl.template(wsData)); 159 159 160 160 // Test 21: Edge cases - empty strings 161 - Ant.println("\nTest 21: Edge cases - empty strings"); 161 + console.log("\nTest 21: Edge cases - empty strings"); 162 162 let empty = ""; 163 - Ant.println(" Empty string replace('x', 'y'):", "'" + empty.replace("x", "y") + "'"); 164 - Ant.println(" Empty string template({}):", "'" + empty.template({}) + "'"); 163 + console.log(" Empty string replace('x', 'y'):", "'" + empty.replace("x", "y") + "'"); 164 + console.log(" Empty string template({}):", "'" + empty.template({}) + "'"); 165 165 166 - Ant.println("\n=== All tests completed ==="); 166 + console.log("\n=== All tests completed ===");
+3 -3
tests/server/radix3.cjs
··· 202 202 line = `${line} :${node.paramName}`; 203 203 } 204 204 205 - Ant.println(line); 205 + console.log(line); 206 206 207 207 const childPrefix = `${prefix}${isLast ? ' ' : 'โ”‚ '}`; 208 208 ··· 213 213 214 214 if (node.paramChild !== undefined) { 215 215 const isLastChild = node.wildcardChild === undefined; 216 - Ant.println(`${childPrefix}${isLastChild ? 'โ””โ”€ ' : 'โ”œโ”€ '}:${node.paramChild.paramName}`); 216 + console.log(`${childPrefix}${isLastChild ? 'โ””โ”€ ' : 'โ”œโ”€ '}:${node.paramChild.paramName}`); 217 217 this.printNode(node.paramChild, `${childPrefix}${isLastChild ? ' ' : 'โ”‚ '}`, true); 218 218 } 219 219 220 220 if (node.wildcardChild !== undefined) { 221 - Ant.println(`${childPrefix}โ””โ”€ *${node.wildcardChild.paramName}`); 221 + console.log(`${childPrefix}โ””โ”€ *${node.wildcardChild.paramName}`); 222 222 this.printNode(node.wildcardChild, `${childPrefix} `, true); 223 223 } 224 224 }
+3 -3
tests/server/server.cjs
··· 46 46 }); 47 47 48 48 router.printTree(); 49 - Ant.println(''); 49 + console.log(''); 50 50 51 51 async function handleRequest(req, res) { 52 - Ant.println('request:', req.method, req.uri); 52 + console.log('request:', req.method, req.uri); 53 53 const result = router.lookup(req.uri); 54 54 55 55 if (result?.handler) { ··· 60 60 res.body('not found: ' + req.uri, 404); 61 61 } 62 62 63 - Ant.println('started on http://localhost:8000'); 63 + console.log('started on http://localhost:8000'); 64 64 Ant.serve(8000, handleRequest);
+2 -2
tests/server_example.cjs
··· 2 2 3 3 // Define a request handler 4 4 function handleRequest(req, res) { 5 - Ant.println("Received request:", req.method, req.uri); 5 + console.log("Received request:", req.method, req.uri); 6 6 7 7 // Return a response object 8 8 return { ··· 12 12 } 13 13 14 14 // Start the server on port 8000 15 - Ant.println("Starting HTTP server..."); 15 + console.log("Starting HTTP server..."); 16 16 Ant.serve(8000, handleRequest);
+2 -2
tests/server_routes.cjs
··· 1 1 // Example HTTP server with basic routing 2 2 3 3 function handleRequest(req, res) { 4 - Ant.println("Request:", req.method, req.uri); 4 + console.log("Request:", req.method, req.uri); 5 5 6 6 // Simple routing based on URI 7 7 if (req.uri === "/") { ··· 39 39 }; 40 40 } 41 41 42 - Ant.println("Starting HTTP server on port 8000..."); 42 + console.log("Starting HTTP server on port 8000..."); 43 43 Ant.serve(8000, handleRequest);
+9 -9
tests/signals.cjs
··· 1 1 let counter = 0; 2 2 3 3 Ant.signal('sigint', function (signum) { 4 - Ant.println('\nReceived SIGINT (signal', signum, ')'); 5 - Ant.println('Counter reached:', counter); 6 - Ant.println('Shutting down gracefully...'); 4 + console.log('\nReceived SIGINT (signal', signum, ')'); 5 + console.log('Counter reached:', counter); 6 + console.log('Shutting down gracefully...'); 7 7 }); 8 8 9 9 Ant.signal('sigterm', function (signum) { 10 - Ant.println('\nReceived SIGTERM (signal', signum, ')'); 11 - Ant.println('Counter reached:', counter); 12 - Ant.println('Terminating...'); 10 + console.log('\nReceived SIGTERM (signal', signum, ')'); 11 + console.log('Counter reached:', counter); 12 + console.log('Terminating...'); 13 13 }); 14 14 15 - Ant.println('Starting counter...'); 16 - Ant.println('Press Ctrl+C to trigger graceful shutdown'); 15 + console.log('Starting counter...'); 16 + console.log('Press Ctrl+C to trigger graceful shutdown'); 17 17 18 18 for (;;) { 19 19 counter++; 20 20 if (counter % 1000000 === 0) { 21 - Ant.println('Counter:', counter); 21 + console.log('Counter:', counter); 22 22 } 23 23 }
+51 -51
tests/string_indexing.cjs
··· 1 1 // Test string indexing feature 2 2 3 - Ant.println("=== String Indexing Test ===\n"); 3 + console.log("=== String Indexing Test ===\n"); 4 4 5 5 // Test 1: Basic string indexing 6 - Ant.println("Test 1: Basic indexing"); 6 + console.log("Test 1: Basic indexing"); 7 7 let str = "hello"; 8 - Ant.println(" str = 'hello'"); 9 - Ant.println(" str[0]:", str[0]); 10 - Ant.println(" str[1]:", str[1]); 11 - Ant.println(" str[2]:", str[2]); 12 - Ant.println(" str[3]:", str[3]); 13 - Ant.println(" str[4]:", str[4]); 8 + console.log(" str = 'hello'"); 9 + console.log(" str[0]:", str[0]); 10 + console.log(" str[1]:", str[1]); 11 + console.log(" str[2]:", str[2]); 12 + console.log(" str[3]:", str[3]); 13 + console.log(" str[4]:", str[4]); 14 14 15 15 // Test 2: Last character access 16 - Ant.println("\nTest 2: Last character"); 16 + console.log("\nTest 2: Last character"); 17 17 let path = "hello/world"; 18 - Ant.println(" path = 'hello/world'"); 19 - Ant.println(" path.length:", path.length); 18 + console.log(" path = 'hello/world'"); 19 + console.log(" path.length:", path.length); 20 20 let lastIdx = path.length - 1; 21 - Ant.println(" path[path.length - 1]:", path[lastIdx]); 21 + console.log(" path[path.length - 1]:", path[lastIdx]); 22 22 23 23 // Test 3: Direct expression in brackets 24 - Ant.println("\nTest 3: Expression in brackets"); 25 - Ant.println(" path[path.length - 1]:", path[path.length - 1]); 26 - Ant.println(" path[5]:", path[5]); 27 - Ant.println(" path[0]:", path[0]); 24 + console.log("\nTest 3: Expression in brackets"); 25 + console.log(" path[path.length - 1]:", path[path.length - 1]); 26 + console.log(" path[5]:", path[5]); 27 + console.log(" path[0]:", path[0]); 28 28 29 29 // Test 4: Out of bounds access 30 - Ant.println("\nTest 4: Out of bounds"); 31 - Ant.println(" str[100] (should be undefined):", str[100]); 32 - Ant.println(" str[-1] (should be undefined):", str[-1]); 30 + console.log("\nTest 4: Out of bounds"); 31 + console.log(" str[100] (should be undefined):", str[100]); 32 + console.log(" str[-1] (should be undefined):", str[-1]); 33 33 34 34 // Test 5: Looping through string characters 35 - Ant.println("\nTest 5: Loop through string"); 35 + console.log("\nTest 5: Loop through string"); 36 36 let word = "test"; 37 - Ant.println(" word = 'test'"); 37 + console.log(" word = 'test'"); 38 38 for (let i = 0; i < word.length; i = i + 1) { 39 - Ant.println(" word[" + i + "]:", word[i]); 39 + console.log(" word[" + i + "]:", word[i]); 40 40 } 41 41 42 42 // Test 6: String comparison with indexing 43 - Ant.println("\nTest 6: Character comparison"); 43 + console.log("\nTest 6: Character comparison"); 44 44 let s1 = "abc"; 45 45 let s2 = "xyz"; 46 - Ant.println(" s1 = 'abc', s2 = 'xyz'"); 47 - Ant.println(" s1[0] == s2[0]:", s1[0] == s2[0]); 48 - Ant.println(" s1[0] != s2[0]:", s1[0] != s2[0]); 46 + console.log(" s1 = 'abc', s2 = 'xyz'"); 47 + console.log(" s1[0] == s2[0]:", s1[0] == s2[0]); 48 + console.log(" s1[0] != s2[0]:", s1[0] != s2[0]); 49 49 50 50 // Test 7: Building strings from characters 51 - Ant.println("\nTest 7: String building"); 51 + console.log("\nTest 7: String building"); 52 52 let original = "hello"; 53 53 let reversed = ""; 54 54 for (let i = original.length - 1; i >= 0; i = i - 1) { 55 55 reversed = reversed + original[i]; 56 56 } 57 - Ant.println(" original:", original); 58 - Ant.println(" reversed:", reversed); 57 + console.log(" original:", original); 58 + console.log(" reversed:", reversed); 59 59 60 60 // Test 8: First and last character check 61 - Ant.println("\nTest 8: First and last character"); 61 + console.log("\nTest 8: First and last character"); 62 62 let url = "/api/users/"; 63 - Ant.println(" url = '/api/users/'"); 64 - Ant.println(" First char (url[0]):", url[0]); 65 - Ant.println(" Last char (url[url.length - 1]):", url[url.length - 1]); 66 - Ant.println(" Starts with '/':", url[0] === "/"); 67 - Ant.println(" Ends with '/':", url[url.length - 1] === "/"); 63 + console.log(" url = '/api/users/'"); 64 + console.log(" First char (url[0]):", url[0]); 65 + console.log(" Last char (url[url.length - 1]):", url[url.length - 1]); 66 + console.log(" Starts with '/':", url[0] === "/"); 67 + console.log(" Ends with '/':", url[url.length - 1] === "/"); 68 68 69 69 // Test 9: Middle character access 70 - Ant.println("\nTest 9: Middle character"); 70 + console.log("\nTest 9: Middle character"); 71 71 let text = "abcdefgh"; 72 72 let mid = text.length / 2; 73 - Ant.println(" text = 'abcdefgh'"); 74 - Ant.println(" Middle index:", mid); 75 - Ant.println(" text[mid]:", text[mid]); 73 + console.log(" text = 'abcdefgh'"); 74 + console.log(" Middle index:", mid); 75 + console.log(" text[mid]:", text[mid]); 76 76 77 77 // Test 10: Empty string 78 - Ant.println("\nTest 10: Empty string"); 78 + console.log("\nTest 10: Empty string"); 79 79 let empty = ""; 80 - Ant.println(" empty.length:", empty.length); 81 - Ant.println(" empty[0] (should be undefined):", empty[0]); 80 + console.log(" empty.length:", empty.length); 81 + console.log(" empty[0] (should be undefined):", empty[0]); 82 82 83 83 // Test 11: Single character string 84 - Ant.println("\nTest 11: Single character"); 84 + console.log("\nTest 11: Single character"); 85 85 let single = "x"; 86 - Ant.println(" single = 'x'"); 87 - Ant.println(" single[0]:", single[0]); 88 - Ant.println(" single[1] (should be undefined):", single[1]); 86 + console.log(" single = 'x'"); 87 + console.log(" single[0]:", single[0]); 88 + console.log(" single[1] (should be undefined):", single[1]); 89 89 90 90 // Test 12: Path manipulation example 91 - Ant.println("\nTest 12: Path manipulation"); 91 + console.log("\nTest 12: Path manipulation"); 92 92 let filePath = "/home/user/file.txt"; 93 - Ant.println(" filePath = '/home/user/file.txt'"); 93 + console.log(" filePath = '/home/user/file.txt'"); 94 94 let hasTrailingSlash = filePath[filePath.length - 1] === "/"; 95 - Ant.println(" Has trailing slash:", hasTrailingSlash); 95 + console.log(" Has trailing slash:", hasTrailingSlash); 96 96 let hasLeadingSlash = filePath[0] === "/"; 97 - Ant.println(" Has leading slash:", hasLeadingSlash); 97 + console.log(" Has leading slash:", hasLeadingSlash); 98 98 99 - Ant.println("\n=== All tests completed ==="); 99 + console.log("\n=== All tests completed ===");
+72 -72
tests/string_methods.cjs
··· 1 1 // Test String methods functionality 2 2 3 - Ant.println("=== String Methods Tests ===\n"); 3 + console.log("=== String Methods Tests ===\n"); 4 4 5 5 // Test 1: indexOf 6 - Ant.println("Test 1: indexOf()"); 6 + console.log("Test 1: indexOf()"); 7 7 let str1 = "hello world"; 8 - Ant.println(" '" + str1 + "'.indexOf('world'):", str1.indexOf("world")); 9 - Ant.println(" '" + str1 + "'.indexOf('o'):", str1.indexOf("o")); 10 - Ant.println(" '" + str1 + "'.indexOf('xyz'):", str1.indexOf("xyz")); 11 - Ant.println(" '" + str1 + "'.indexOf(''):", str1.indexOf("")); 8 + console.log(" '" + str1 + "'.indexOf('world'):", str1.indexOf("world")); 9 + console.log(" '" + str1 + "'.indexOf('o'):", str1.indexOf("o")); 10 + console.log(" '" + str1 + "'.indexOf('xyz'):", str1.indexOf("xyz")); 11 + console.log(" '" + str1 + "'.indexOf(''):", str1.indexOf("")); 12 12 13 13 // Test 2: substring 14 - Ant.println("\nTest 2: substring()"); 14 + console.log("\nTest 2: substring()"); 15 15 let str2 = "JavaScript"; 16 - Ant.println(" '" + str2 + "'.substring(0, 4):", str2.substring(0, 4)); 17 - Ant.println(" '" + str2 + "'.substring(4):", str2.substring(4)); 18 - Ant.println(" '" + str2 + "'.substring(4, 10):", str2.substring(4, 10)); 19 - Ant.println(" '" + str2 + "'.substring(10, 4):", str2.substring(10, 4)); // Should swap 16 + console.log(" '" + str2 + "'.substring(0, 4):", str2.substring(0, 4)); 17 + console.log(" '" + str2 + "'.substring(4):", str2.substring(4)); 18 + console.log(" '" + str2 + "'.substring(4, 10):", str2.substring(4, 10)); 19 + console.log(" '" + str2 + "'.substring(10, 4):", str2.substring(10, 4)); // Should swap 20 20 21 21 // Test 3: slice 22 - Ant.println("\nTest 3: slice()"); 22 + console.log("\nTest 3: slice()"); 23 23 let str3 = "The quick brown fox"; 24 - Ant.println(" '" + str3 + "'.slice(0, 3):", str3.slice(0, 3)); 25 - Ant.println(" '" + str3 + "'.slice(4, 9):", str3.slice(4, 9)); 26 - Ant.println(" '" + str3 + "'.slice(10):", str3.slice(10)); 27 - Ant.println(" '" + str3 + "'.slice(-3):", str3.slice(-3)); 28 - Ant.println(" '" + str3 + "'.slice(0, -4):", str3.slice(0, -4)); 29 - Ant.println(" '" + str3 + "'.slice(-9, -4):", str3.slice(-9, -4)); 24 + console.log(" '" + str3 + "'.slice(0, 3):", str3.slice(0, 3)); 25 + console.log(" '" + str3 + "'.slice(4, 9):", str3.slice(4, 9)); 26 + console.log(" '" + str3 + "'.slice(10):", str3.slice(10)); 27 + console.log(" '" + str3 + "'.slice(-3):", str3.slice(-3)); 28 + console.log(" '" + str3 + "'.slice(0, -4):", str3.slice(0, -4)); 29 + console.log(" '" + str3 + "'.slice(-9, -4):", str3.slice(-9, -4)); 30 30 31 31 // Test 4: split 32 - Ant.println("\nTest 4: split()"); 32 + console.log("\nTest 4: split()"); 33 33 let str4 = "apple,banana,cherry"; 34 34 let parts = str4.split(","); 35 - Ant.println(" '" + str4 + "'.split(','):"); 35 + console.log(" '" + str4 + "'.split(','):"); 36 36 for (let i = 0; i < parts.length; i++) { 37 - Ant.println(" [" + i + "]: " + parts[i]); 37 + console.log(" [" + i + "]: " + parts[i]); 38 38 } 39 39 40 40 let str5 = "hello"; 41 41 let chars = str5.split(""); 42 - Ant.println(" '" + str5 + "'.split(''):"); 42 + console.log(" '" + str5 + "'.split(''):"); 43 43 for (let i = 0; i < chars.length; i++) { 44 - Ant.println(" [" + i + "]: " + chars[i]); 44 + console.log(" [" + i + "]: " + chars[i]); 45 45 } 46 46 47 47 // Test 5: includes 48 - Ant.println("\nTest 5: includes()"); 48 + console.log("\nTest 5: includes()"); 49 49 let str6 = "The quick brown fox jumps over the lazy dog"; 50 - Ant.println(" '" + str6 + "'"); 51 - Ant.println(" includes('quick'):", str6.includes("quick")); 52 - Ant.println(" includes('cat'):", str6.includes("cat")); 53 - Ant.println(" includes('fox'):", str6.includes("fox")); 54 - Ant.println(" includes(''):", str6.includes("")); 55 - Ant.println(" includes('QUICK'):", str6.includes("QUICK")); 50 + console.log(" '" + str6 + "'"); 51 + console.log(" includes('quick'):", str6.includes("quick")); 52 + console.log(" includes('cat'):", str6.includes("cat")); 53 + console.log(" includes('fox'):", str6.includes("fox")); 54 + console.log(" includes(''):", str6.includes("")); 55 + console.log(" includes('QUICK'):", str6.includes("QUICK")); 56 56 57 57 // Test 6: startsWith 58 - Ant.println("\nTest 6: startsWith()"); 58 + console.log("\nTest 6: startsWith()"); 59 59 let str7 = "Hello, World!"; 60 - Ant.println(" '" + str7 + "'"); 61 - Ant.println(" startsWith('Hello'):", str7.startsWith("Hello")); 62 - Ant.println(" startsWith('World'):", str7.startsWith("World")); 63 - Ant.println(" startsWith('H'):", str7.startsWith("H")); 64 - Ant.println(" startsWith(''):", str7.startsWith("")); 60 + console.log(" '" + str7 + "'"); 61 + console.log(" startsWith('Hello'):", str7.startsWith("Hello")); 62 + console.log(" startsWith('World'):", str7.startsWith("World")); 63 + console.log(" startsWith('H'):", str7.startsWith("H")); 64 + console.log(" startsWith(''):", str7.startsWith("")); 65 65 66 66 // Test 7: endsWith 67 - Ant.println("\nTest 7: endsWith()"); 67 + console.log("\nTest 7: endsWith()"); 68 68 let str8 = "index.html"; 69 - Ant.println(" '" + str8 + "'"); 70 - Ant.println(" endsWith('.html'):", str8.endsWith(".html")); 71 - Ant.println(" endsWith('.js'):", str8.endsWith(".js")); 72 - Ant.println(" endsWith('html'):", str8.endsWith("html")); 73 - Ant.println(" endsWith(''):", str8.endsWith("")); 69 + console.log(" '" + str8 + "'"); 70 + console.log(" endsWith('.html'):", str8.endsWith(".html")); 71 + console.log(" endsWith('.js'):", str8.endsWith(".js")); 72 + console.log(" endsWith('html'):", str8.endsWith("html")); 73 + console.log(" endsWith(''):", str8.endsWith("")); 74 74 75 75 // Test 8: Combining methods 76 - Ant.println("\nTest 8: Combining methods"); 76 + console.log("\nTest 8: Combining methods"); 77 77 let path = "/api/users/123/profile"; 78 - Ant.println(" Path:", path); 78 + console.log(" Path:", path); 79 79 let segments = path.split("/"); 80 - Ant.println(" Segments:"); 80 + console.log(" Segments:"); 81 81 for (let i = 0; i < segments.length; i++) { 82 82 if (segments[i] !== "") { 83 - Ant.println(" " + segments[i]); 83 + console.log(" " + segments[i]); 84 84 } 85 85 } 86 86 87 87 // Test 9: URL parsing example 88 - Ant.println("\nTest 9: URL parsing"); 88 + console.log("\nTest 9: URL parsing"); 89 89 let url = "https://example.com/path/to/resource"; 90 90 if (url.startsWith("https://")) { 91 - Ant.println(" URL uses HTTPS"); 91 + console.log(" URL uses HTTPS"); 92 92 let domain = url.slice(8); 93 93 let domainEnd = domain.indexOf("/"); 94 94 if (domainEnd !== -1) { 95 95 let hostname = domain.substring(0, domainEnd); 96 - Ant.println(" Hostname:", hostname); 96 + console.log(" Hostname:", hostname); 97 97 let pathname = domain.slice(domainEnd); 98 - Ant.println(" Pathname:", pathname); 98 + console.log(" Pathname:", pathname); 99 99 } 100 100 } 101 101 102 102 // Test 10: String validation 103 - Ant.println("\nTest 10: String validation"); 103 + console.log("\nTest 10: String validation"); 104 104 let email = "user@example.com"; 105 - Ant.println(" Email:", email); 106 - Ant.println(" Contains '@':", email.includes("@")); 105 + console.log(" Email:", email); 106 + console.log(" Contains '@':", email.includes("@")); 107 107 let atIndex = email.indexOf("@"); 108 108 if (atIndex !== -1) { 109 109 let username = email.substring(0, atIndex); 110 110 let domain = email.substring(atIndex + 1); 111 - Ant.println(" Username:", username); 112 - Ant.println(" Domain:", domain); 113 - Ant.println(" Domain ends with '.com':", domain.endsWith(".com")); 111 + console.log(" Username:", username); 112 + console.log(" Domain:", domain); 113 + console.log(" Domain ends with '.com':", domain.endsWith(".com")); 114 114 } 115 115 116 116 // Test 11: Edge cases 117 - Ant.println("\nTest 11: Edge cases"); 117 + console.log("\nTest 11: Edge cases"); 118 118 let empty = ""; 119 - Ant.println(" Empty string:"); 120 - Ant.println(" length:", empty.length); 121 - Ant.println(" indexOf('x'):", empty.indexOf("x")); 122 - Ant.println(" slice(0, 5):", "'" + empty.slice(0, 5) + "'"); 123 - Ant.println(" includes(''):", empty.includes("")); 124 - Ant.println(" startsWith(''):", empty.startsWith("")); 125 - Ant.println(" endsWith(''):", empty.endsWith("")); 119 + console.log(" Empty string:"); 120 + console.log(" length:", empty.length); 121 + console.log(" indexOf('x'):", empty.indexOf("x")); 122 + console.log(" slice(0, 5):", "'" + empty.slice(0, 5) + "'"); 123 + console.log(" includes(''):", empty.includes("")); 124 + console.log(" startsWith(''):", empty.startsWith("")); 125 + console.log(" endsWith(''):", empty.endsWith("")); 126 126 127 127 let single = "a"; 128 - Ant.println(" Single char 'a':"); 129 - Ant.println(" slice(-1):", single.slice(-1)); 130 - Ant.println(" substring(0, 1):", single.substring(0, 1)); 128 + console.log(" Single char 'a':"); 129 + console.log(" slice(-1):", single.slice(-1)); 130 + console.log(" substring(0, 1):", single.substring(0, 1)); 131 131 132 132 // Test 12: Practical example - template processing 133 - Ant.println("\nTest 12: Template processing"); 133 + console.log("\nTest 12: Template processing"); 134 134 let template = "Hello, {{name}}! You have {{count}} messages."; 135 - Ant.println(" Template:", template); 135 + console.log(" Template:", template); 136 136 if (template.includes("{{") && template.includes("}}")) { 137 - Ant.println(" Template contains placeholders"); 137 + console.log(" Template contains placeholders"); 138 138 let start = template.indexOf("{{"); 139 139 let end = template.indexOf("}}"); 140 140 if (start !== -1 && end !== -1) { 141 141 let placeholder = template.substring(start + 2, end); 142 - Ant.println(" First placeholder:", placeholder); 142 + console.log(" First placeholder:", placeholder); 143 143 } 144 144 } 145 145 146 - Ant.println("\n=== All tests completed ==="); 146 + console.log("\n=== All tests completed ===");
+77 -77
tests/tagged_templates.cjs
··· 1 1 // Comprehensive Tagged Template Literal Tests 2 - Ant.println("=== Tagged Template Literal Tests ===\n"); 2 + console.log("=== Tagged Template Literal Tests ===\n"); 3 3 4 4 // Test 1: Basic tagged template with one substitution 5 - Ant.println("Test 1: Basic tagged template"); 5 + console.log("Test 1: Basic tagged template"); 6 6 function tag1(strings, ...values) { 7 - Ant.println(" โœ“ strings.length:", strings.length); 8 - Ant.println(" โœ“ strings[0]:", strings[0]); 9 - Ant.println(" โœ“ strings[1]:", strings[1]); 10 - Ant.println(" โœ“ values.length:", values.length); 11 - Ant.println(" โœ“ values[0]:", values[0]); 7 + console.log(" โœ“ strings.length:", strings.length); 8 + console.log(" โœ“ strings[0]:", strings[0]); 9 + console.log(" โœ“ strings[1]:", strings[1]); 10 + console.log(" โœ“ values.length:", values.length); 11 + console.log(" โœ“ values[0]:", values[0]); 12 12 return "result1"; 13 13 } 14 14 15 15 let name = "World"; 16 16 let result1 = tag1`Hello ${name}!`; 17 - Ant.println(" โœ“ Result:", result1); 18 - Ant.println(""); 17 + console.log(" โœ“ Result:", result1); 18 + console.log(""); 19 19 20 20 // Test 2: Building a string from parts 21 - Ant.println("Test 2: Building a string from tagged template"); 21 + console.log("Test 2: Building a string from tagged template"); 22 22 function build(strings, ...values) { 23 23 let result = ""; 24 24 for (let i = 0; i < strings.length; i++) { ··· 31 31 } 32 32 33 33 let greeting = build`Hello ${name}!`; 34 - Ant.println(" โœ“ Result:", greeting); 35 - Ant.println(""); 34 + console.log(" โœ“ Result:", greeting); 35 + console.log(""); 36 36 37 37 // Test 3: Multiple substitutions 38 - Ant.println("Test 3: Multiple substitutions"); 38 + console.log("Test 3: Multiple substitutions"); 39 39 function multi(strings, ...values) { 40 - Ant.println(" โœ“ values.length:", values.length); 41 - Ant.println(" โœ“ First value:", values[0]); 42 - Ant.println(" โœ“ Second value:", values[1]); 40 + console.log(" โœ“ values.length:", values.length); 41 + console.log(" โœ“ First value:", values[0]); 42 + console.log(" โœ“ Second value:", values[1]); 43 43 return values[0] + values[1]; 44 44 } 45 45 46 46 let a = 10; 47 47 let b = 20; 48 48 let sum = multi`Adding ${a} and ${b}`; 49 - Ant.println(" โœ“ Sum:", sum); 50 - Ant.println(""); 49 + console.log(" โœ“ Sum:", sum); 50 + console.log(""); 51 51 52 52 // Test 4: No substitutions 53 - Ant.println("Test 4: No substitutions"); 53 + console.log("Test 4: No substitutions"); 54 54 function noSub(strings) { 55 - Ant.println(" โœ“ strings.length:", strings.length); 56 - Ant.println(" โœ“ strings[0]:", strings[0]); 55 + console.log(" โœ“ strings.length:", strings.length); 56 + console.log(" โœ“ strings[0]:", strings[0]); 57 57 return "no-substitutions"; 58 58 } 59 59 60 60 let result4 = noSub`Just a plain string`; 61 - Ant.println(" โœ“ Result:", result4); 62 - Ant.println(""); 61 + console.log(" โœ“ Result:", result4); 62 + console.log(""); 63 63 64 64 // Test 5: Expression in substitution 65 - Ant.println("Test 5: Expression in substitution"); 65 + console.log("Test 5: Expression in substitution"); 66 66 function expr(strings, ...values) { 67 67 return values[0] * 2; 68 68 } 69 69 70 70 let x = 5; 71 71 let doubled = expr`Double ${x + 3}`; 72 - Ant.println(" โœ“ Result:", doubled); 73 - Ant.println(""); 72 + console.log(" โœ“ Result:", doubled); 73 + console.log(""); 74 74 75 75 // Test 6: Conditional in substitution 76 - Ant.println("Test 6: Conditional in substitution"); 76 + console.log("Test 6: Conditional in substitution"); 77 77 function cond(strings, ...values) { 78 78 return values[0]; 79 79 } 80 80 81 81 let score = 85; 82 82 let grade = cond`Grade: ${score > 80 ? "A" : "B"}`; 83 - Ant.println(" โœ“ Result:", grade); 84 - Ant.println(""); 83 + console.log(" โœ“ Result:", grade); 84 + console.log(""); 85 85 86 86 // Test 7: Object property access 87 - Ant.println("Test 7: Object property access"); 87 + console.log("Test 7: Object property access"); 88 88 function objAccess(strings, ...values) { 89 89 return values[0]; 90 90 } 91 91 92 92 let person = { name: "Alice", age: 25 }; 93 93 let info = objAccess`Name: ${person.name}`; 94 - Ant.println(" โœ“ Result:", info); 95 - Ant.println(""); 94 + console.log(" โœ“ Result:", info); 95 + console.log(""); 96 96 97 97 // Test 8: Array indexing 98 - Ant.println("Test 8: Array indexing"); 98 + console.log("Test 8: Array indexing"); 99 99 function arrAccess(strings, ...values) { 100 100 return values[0]; 101 101 } 102 102 103 103 let colors = ["red", "green", "blue"]; 104 104 let color = arrAccess`First color: ${colors[0]}`; 105 - Ant.println(" โœ“ Result:", color); 106 - Ant.println(""); 105 + console.log(" โœ“ Result:", color); 106 + console.log(""); 107 107 108 108 // Test 9: Returning different types 109 - Ant.println("Test 9: Returning different types"); 109 + console.log("Test 9: Returning different types"); 110 110 function retNum(strings) { 111 111 return 42; 112 112 } ··· 117 117 118 118 let num = retNum`test`; 119 119 let bool = retBool`test`; 120 - Ant.println(" โœ“ Number:", num); 121 - Ant.println(" โœ“ Boolean:", bool); 122 - Ant.println(""); 120 + console.log(" โœ“ Number:", num); 121 + console.log(" โœ“ Boolean:", bool); 122 + console.log(""); 123 123 124 124 // Test 10: Using result with string methods 125 - Ant.println("Test 10: Using result with string methods"); 125 + console.log("Test 10: Using result with string methods"); 126 126 function makeString(strings, ...values) { 127 127 return strings[0] + values[0] + strings[1]; 128 128 } 129 129 130 130 let text = makeString`Hello ${name}!`; 131 - Ant.println(" โœ“ Text:", text); 132 - Ant.println(" โœ“ Includes 'World':", text.includes("World")); 133 - Ant.println(" โœ“ Starts with 'Hello':", text.startsWith("Hello")); 134 - Ant.println(""); 131 + console.log(" โœ“ Text:", text); 132 + console.log(" โœ“ Includes 'World':", text.includes("World")); 133 + console.log(" โœ“ Starts with 'Hello':", text.startsWith("Hello")); 134 + console.log(""); 135 135 136 136 // Test 11: Rest params with many values 137 - Ant.println("Test 11: Rest params with many values"); 137 + console.log("Test 11: Rest params with many values"); 138 138 function manyValues(strings, ...values) { 139 - Ant.println(" โœ“ strings.length:", strings.length); 140 - Ant.println(" โœ“ values.length:", values.length); 139 + console.log(" โœ“ strings.length:", strings.length); 140 + console.log(" โœ“ values.length:", values.length); 141 141 let result = ""; 142 142 for (let i = 0; i < strings.length; i++) { 143 143 result = result + strings[i]; ··· 153 153 let v3 = "C"; 154 154 let v4 = "D"; 155 155 let assembled = manyValues`${v1}-${v2}-${v3}-${v4}`; 156 - Ant.println(" โœ“ Result:", assembled); 157 - Ant.println(""); 156 + console.log(" โœ“ Result:", assembled); 157 + console.log(""); 158 158 159 159 // Test 12: Nested function calls 160 - Ant.println("Test 12: Nested expressions"); 160 + console.log("Test 12: Nested expressions"); 161 161 function nested(strings, ...values) { 162 162 return values[0] + values[1]; 163 163 } ··· 167 167 } 168 168 169 169 let nested_result = nested`${double(5)} + ${double(10)}`; 170 - Ant.println(" โœ“ Result:", nested_result); 171 - Ant.println(""); 170 + console.log(" โœ“ Result:", nested_result); 171 + console.log(""); 172 172 173 173 // Test 13: Empty strings between substitutions 174 - Ant.println("Test 13: Adjacent substitutions"); 174 + console.log("Test 13: Adjacent substitutions"); 175 175 function adjacent(strings, ...values) { 176 - Ant.println(" โœ“ strings:", strings); 177 - Ant.println(" โœ“ values:", values); 176 + console.log(" โœ“ strings:", strings); 177 + console.log(" โœ“ values:", values); 178 178 return values[0] + values[1]; 179 179 } 180 180 181 181 let adj = adjacent`${10}${20}`; 182 - Ant.println(" โœ“ Result:", adj); 183 - Ant.println(""); 182 + console.log(" โœ“ Result:", adj); 183 + console.log(""); 184 184 185 185 // Test 14: SQL-style template (common use case) 186 - Ant.println("Test 14: SQL-style builder"); 186 + console.log("Test 14: SQL-style builder"); 187 187 function sql(strings, ...values) { 188 188 let query = ""; 189 189 for (let i = 0; i < strings.length; i++) { ··· 198 198 let userId = 42; 199 199 let userName = "Alice"; 200 200 let sqlResult = sql`SELECT * FROM users WHERE id = ${userId} AND name = ${userName}`; 201 - Ant.println(" โœ“ Query:", sqlResult.query); 202 - Ant.println(" โœ“ Values:", sqlResult.values); 203 - Ant.println(""); 201 + console.log(" โœ“ Query:", sqlResult.query); 202 + console.log(" โœ“ Values:", sqlResult.values); 203 + console.log(""); 204 204 205 205 // Test 15: HTML escaping (another common use case) 206 - Ant.println("Test 15: HTML builder"); 206 + console.log("Test 15: HTML builder"); 207 207 function html(strings, ...values) { 208 208 let result = ""; 209 209 for (let i = 0; i < strings.length; i++) { ··· 219 219 let title = "My Page"; 220 220 let content = "Hello World"; 221 221 let htmlResult = html`<html><head><title>${title}</title></head><body>${content}</body></html>`; 222 - Ant.println(" โœ“ HTML:", htmlResult); 223 - Ant.println(""); 222 + console.log(" โœ“ HTML:", htmlResult); 223 + console.log(""); 224 224 225 225 // Test 16: Using closure instead of this 226 - Ant.println("Test 16: Tag function with closure"); 226 + console.log("Test 16: Tag function with closure"); 227 227 function makeTag(prefix) { 228 228 return function(strings, ...values) { 229 229 return prefix + values[0]; ··· 232 232 233 233 let prefixTag = makeTag(">>>"); 234 234 let prefixed = prefixTag`Value: ${123}`; 235 - Ant.println(" โœ“ Result:", prefixed); 236 - Ant.println(""); 235 + console.log(" โœ“ Result:", prefixed); 236 + console.log(""); 237 237 238 238 // Test 17: Empty template 239 - Ant.println("Test 17: Empty template"); 239 + console.log("Test 17: Empty template"); 240 240 function empty(strings) { 241 241 return strings[0]; 242 242 } 243 243 244 244 let emptyResult = empty``; 245 - Ant.println(" โœ“ Result:", emptyResult); 246 - Ant.println(""); 245 + console.log(" โœ“ Result:", emptyResult); 246 + console.log(""); 247 247 248 248 // Test 18: Only substitutions, no strings 249 - Ant.println("Test 18: Template starting and ending with substitution"); 249 + console.log("Test 18: Template starting and ending with substitution"); 250 250 function allSubs(strings, ...values) { 251 - Ant.println(" โœ“ strings.length:", strings.length); 252 - Ant.println(" โœ“ First string is empty:", strings[0] == ""); 253 - Ant.println(" โœ“ Last string is empty:", strings[strings.length - 1] == ""); 251 + console.log(" โœ“ strings.length:", strings.length); 252 + console.log(" โœ“ First string is empty:", strings[0] == ""); 253 + console.log(" โœ“ Last string is empty:", strings[strings.length - 1] == ""); 254 254 return values.length; 255 255 } 256 256 257 257 let count = allSubs`${1}${2}${3}`; 258 - Ant.println(" โœ“ Count:", count); 259 - Ant.println(""); 258 + console.log(" โœ“ Count:", count); 259 + console.log(""); 260 260 261 - Ant.println("=== All 18 tests completed successfully! ==="); 261 + console.log("=== All 18 tests completed successfully! ===");
+82 -82
tests/template_literals.cjs
··· 14 14 // - Edge cases (empty, null, undefined) 15 15 // - Practical use cases (URLs, receipts, error messages) 16 16 17 - Ant.println("=== Template Literal Tests ===\n"); 17 + console.log("=== Template Literal Tests ===\n"); 18 18 19 19 // Test 1: Basic template literal 20 - Ant.println("Test 1: Basic template literal"); 20 + console.log("Test 1: Basic template literal"); 21 21 let basic = `Hello, World!`; 22 - Ant.println(" Result:", basic); 23 - Ant.println(" Type:", typeof basic); 24 - Ant.println(" Length:", basic.length); 22 + console.log(" Result:", basic); 23 + console.log(" Type:", typeof basic); 24 + console.log(" Length:", basic.length); 25 25 26 26 // Test 2: Single variable interpolation 27 - Ant.println("\nTest 2: Single variable interpolation"); 27 + console.log("\nTest 2: Single variable interpolation"); 28 28 let name = "Alice"; 29 29 let greeting = `Hello, ${name}!`; 30 - Ant.println(" Name:", name); 31 - Ant.println(" Result:", greeting); 30 + console.log(" Name:", name); 31 + console.log(" Result:", greeting); 32 32 33 33 // Test 3: Multiple variable interpolations 34 - Ant.println("\nTest 3: Multiple variable interpolations"); 34 + console.log("\nTest 3: Multiple variable interpolations"); 35 35 let firstName = "John"; 36 36 let lastName = "Doe"; 37 37 let fullName = `${firstName} ${lastName}`; 38 - Ant.println(" First:", firstName); 39 - Ant.println(" Last:", lastName); 40 - Ant.println(" Full:", fullName); 38 + console.log(" First:", firstName); 39 + console.log(" Last:", lastName); 40 + console.log(" Full:", fullName); 41 41 42 42 // Test 4: Numeric expressions 43 - Ant.println("\nTest 4: Numeric expressions"); 43 + console.log("\nTest 4: Numeric expressions"); 44 44 let a = 10; 45 45 let b = 20; 46 46 let sum = `${a} + ${b} = ${a + b}`; 47 47 let product = `${a} * ${b} = ${a * b}`; 48 48 let division = `${b} / ${a} = ${b / a}`; 49 - Ant.println(" Sum:", sum); 50 - Ant.println(" Product:", product); 51 - Ant.println(" Division:", division); 49 + console.log(" Sum:", sum); 50 + console.log(" Product:", product); 51 + console.log(" Division:", division); 52 52 53 53 // Test 5: Complex expressions 54 - Ant.println("\nTest 5: Complex expressions"); 54 + console.log("\nTest 5: Complex expressions"); 55 55 let x = 5; 56 56 let y = 3; 57 57 let complex1 = `(${x} + ${y}) * 2 = ${(x + y) * 2}`; 58 58 let complex2 = `Average of ${x} and ${y} is ${(x + y) / 2}`; 59 - Ant.println(" Complex 1:", complex1); 60 - Ant.println(" Complex 2:", complex2); 59 + console.log(" Complex 1:", complex1); 60 + console.log(" Complex 2:", complex2); 61 61 62 62 // Test 6: Boolean interpolation 63 - Ant.println("\nTest 6: Boolean interpolation"); 63 + console.log("\nTest 6: Boolean interpolation"); 64 64 let isActive = true; 65 65 let isDisabled = false; 66 66 let status1 = `Active: ${isActive}`; 67 67 let status2 = `Disabled: ${isDisabled}`; 68 - Ant.println(" Status 1:", status1); 69 - Ant.println(" Status 2:", status2); 68 + console.log(" Status 1:", status1); 69 + console.log(" Status 2:", status2); 70 70 71 71 // Test 7: Mixed types 72 - Ant.println("\nTest 7: Mixed types"); 72 + console.log("\nTest 7: Mixed types"); 73 73 let count = 42; 74 74 let label = "items"; 75 75 let enabled = true; 76 76 let mixed = `Status: ${enabled}, Count: ${count} ${label}`; 77 - Ant.println(" Result:", mixed); 77 + console.log(" Result:", mixed); 78 78 79 79 // Test 8: Empty template 80 - Ant.println("\nTest 8: Empty template"); 80 + console.log("\nTest 8: Empty template"); 81 81 let empty = ``; 82 - Ant.println(" Result: '" + empty + "'"); 83 - Ant.println(" Length:", empty.length); 82 + console.log(" Result: '" + empty + "'"); 83 + console.log(" Length:", empty.length); 84 84 85 85 // Test 9: Template with only interpolation 86 - Ant.println("\nTest 9: Template with only interpolation"); 86 + console.log("\nTest 9: Template with only interpolation"); 87 87 let value = 123; 88 88 let onlyInterp = `${value}`; 89 - Ant.println(" Value:", value); 90 - Ant.println(" Result:", onlyInterp); 91 - Ant.println(" Type:", typeof onlyInterp); 89 + console.log(" Value:", value); 90 + console.log(" Result:", onlyInterp); 91 + console.log(" Type:", typeof onlyInterp); 92 92 93 93 // Test 10: Consecutive interpolations 94 - Ant.println("\nTest 10: Consecutive interpolations"); 94 + console.log("\nTest 10: Consecutive interpolations"); 95 95 let n1 = 1; 96 96 let n2 = 2; 97 97 let n3 = 3; 98 98 let consecutive = `${n1}${n2}${n3}`; 99 - Ant.println(" Result:", consecutive); 99 + console.log(" Result:", consecutive); 100 100 101 101 // Test 11: String concatenation in interpolation 102 - Ant.println("\nTest 11: String concatenation in interpolation"); 102 + console.log("\nTest 11: String concatenation in interpolation"); 103 103 let part1 = "Hello"; 104 104 let part2 = "World"; 105 105 let concatenated = `${part1 + " " + part2}`; 106 - Ant.println(" Part 1:", part1); 107 - Ant.println(" Part 2:", part2); 108 - Ant.println(" Result:", concatenated); 106 + console.log(" Part 1:", part1); 107 + console.log(" Part 2:", part2); 108 + console.log(" Result:", concatenated); 109 109 110 110 // Test 12: Nested arithmetic 111 - Ant.println("\nTest 12: Nested arithmetic"); 111 + console.log("\nTest 12: Nested arithmetic"); 112 112 let p = 3; 113 113 let q = 4; 114 114 let r = 5; 115 115 let nested = `${p} * ${q} + ${r} = ${p * q + r}`; 116 - Ant.println(" Result:", nested); 116 + console.log(" Result:", nested); 117 117 118 118 // Test 13: Comparison in template 119 - Ant.println("\nTest 13: Comparison in template"); 119 + console.log("\nTest 13: Comparison in template"); 120 120 let age = 20; 121 121 let canVote = `Age ${age}: Can vote = ${age >= 18}`; 122 - Ant.println(" Result:", canVote); 122 + console.log(" Result:", canVote); 123 123 124 124 // Test 14: Object property access 125 - Ant.println("\nTest 14: Object property access"); 125 + console.log("\nTest 14: Object property access"); 126 126 let person = { name: "Bob", age: 25 }; 127 127 let personInfo = `${person.name} is ${person.age} years old`; 128 - Ant.println(" Result:", personInfo); 128 + console.log(" Result:", personInfo); 129 129 130 130 // Test 15: Array indexing 131 - Ant.println("\nTest 15: Array indexing"); 131 + console.log("\nTest 15: Array indexing"); 132 132 let colors = ["red", "green", "blue"]; 133 133 let colorMsg = `First color: ${colors[0]}, Last: ${colors[2]}`; 134 - Ant.println(" Result:", colorMsg); 134 + console.log(" Result:", colorMsg); 135 135 136 136 // Test 16: Multiline template 137 - Ant.println("\nTest 16: Multiline template"); 137 + console.log("\nTest 16: Multiline template"); 138 138 let multiline = `Line 1 139 139 Line 2 140 140 Line 3`; 141 - Ant.println(" Result:", multiline); 142 - Ant.println(" Length:", multiline.length); 141 + console.log(" Result:", multiline); 142 + console.log(" Length:", multiline.length); 143 143 144 144 // Test 17: Escape sequences 145 - Ant.println("\nTest 17: Escape sequences"); 145 + console.log("\nTest 17: Escape sequences"); 146 146 let escaped = `Hello\nWorld\tTab`; 147 - Ant.println(" With escapes:", escaped); 147 + console.log(" With escapes:", escaped); 148 148 let withBackslash = `Path: C:\\Users\\Data`; 149 - Ant.println(" With backslash:", withBackslash); 149 + console.log(" With backslash:", withBackslash); 150 150 151 151 // Test 18: Template in function 152 - Ant.println("\nTest 18: Template in function"); 152 + console.log("\nTest 18: Template in function"); 153 153 function greet(name, time) { 154 154 return `Good ${time}, ${name}!`; 155 155 } 156 156 let morning = greet("Alice", "morning"); 157 157 let evening = greet("Bob", "evening"); 158 - Ant.println(" Morning:", morning); 159 - Ant.println(" Evening:", evening); 158 + console.log(" Morning:", morning); 159 + console.log(" Evening:", evening); 160 160 161 161 // Test 19: Template with function call 162 - Ant.println("\nTest 19: Template with function call"); 162 + console.log("\nTest 19: Template with function call"); 163 163 function double(n) { 164 164 return n * 2; 165 165 } 166 166 let funcResult = `Double of 5 is ${double(5)}`; 167 - Ant.println(" Result:", funcResult); 167 + console.log(" Result:", funcResult); 168 168 169 169 // Test 20: Combining with string methods 170 - Ant.println("\nTest 20: Combining with string methods"); 170 + console.log("\nTest 20: Combining with string methods"); 171 171 let word = "javascript"; 172 172 let upperFirst = word[0]; 173 173 let rest = word.slice(1); 174 174 let capitalized = `${upperFirst}${rest}`; 175 - Ant.println(" Original:", word); 176 - Ant.println(" Capitalized:", capitalized); 177 - Ant.println(" Includes 'script':", capitalized.includes("script")); 175 + console.log(" Original:", word); 176 + console.log(" Capitalized:", capitalized); 177 + console.log(" Includes 'script':", capitalized.includes("script")); 178 178 179 179 // Test 21: Price formatting example 180 - Ant.println("\nTest 21: Price formatting example"); 180 + console.log("\nTest 21: Price formatting example"); 181 181 let price = 19.99; 182 182 let quantity = 3; 183 183 let tax = 0.08; ··· 189 189 Subtotal: $${subtotal} 190 190 Tax (${tax * 100}%): $${subtotal * tax} 191 191 Total: $${total}`; 192 - Ant.println(receipt); 192 + console.log(receipt); 193 193 194 194 // Test 22: URL building 195 - Ant.println("\nTest 22: URL building"); 195 + console.log("\nTest 22: URL building"); 196 196 let protocol = "https"; 197 197 let domain = "example.com"; 198 198 let path = "api/users"; 199 199 let id = 123; 200 200 let url = `${protocol}://${domain}/${path}/${id}`; 201 - Ant.println(" URL:", url); 201 + console.log(" URL:", url); 202 202 203 203 // Test 23: Error message formatting 204 - Ant.println("\nTest 23: Error message formatting"); 204 + console.log("\nTest 23: Error message formatting"); 205 205 let errorCode = 404; 206 206 let resource = "user"; 207 207 let errorMsg = `Error ${errorCode}: ${resource} not found`; 208 - Ant.println(" Error:", errorMsg); 208 + console.log(" Error:", errorMsg); 209 209 210 210 // Test 24: Conditional expression in template 211 - Ant.println("\nTest 24: Conditional expression in template"); 211 + console.log("\nTest 24: Conditional expression in template"); 212 212 let score = 85; 213 213 let grade = `Score: ${score} - ${score >= 90 ? "A" : score >= 80 ? "B" : "C"}`; 214 - Ant.println(" Result:", grade); 214 + console.log(" Result:", grade); 215 215 216 216 // Test 25: Complex data formatting 217 - Ant.println("\nTest 25: Complex data formatting"); 217 + console.log("\nTest 25: Complex data formatting"); 218 218 let user = { 219 219 id: 1001, 220 220 name: "Charlie", ··· 228 228 โ”‚ Email: ${user.email} 229 229 โ”‚ Status: ${user.active ? "Active" : "Inactive"} 230 230 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€`; 231 - Ant.println(userCard); 231 + console.log(userCard); 232 232 233 233 // Test 26: Edge case - very long interpolation 234 - Ant.println("\nTest 26: Edge case - very long interpolation"); 234 + console.log("\nTest 26: Edge case - very long interpolation"); 235 235 let longExpr = `Result: ${1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10}`; 236 - Ant.println(" Result:", longExpr); 236 + console.log(" Result:", longExpr); 237 237 238 238 // Test 27: Template with null and undefined 239 - Ant.println("\nTest 27: Template with null and undefined"); 239 + console.log("\nTest 27: Template with null and undefined"); 240 240 let nullVal = null; 241 241 let undefVal = undefined; 242 242 let nullMsg = `Null value: ${nullVal}`; 243 243 let undefMsg = `Undefined value: ${undefVal}`; 244 - Ant.println(" Null:", nullMsg); 245 - Ant.println(" Undefined:", undefMsg); 244 + console.log(" Null:", nullMsg); 245 + console.log(" Undefined:", undefMsg); 246 246 247 247 // Test 28: String with template-like syntax 248 - Ant.println("\nTest 28: String with template-like syntax"); 248 + console.log("\nTest 28: String with template-like syntax"); 249 249 let innerCalc = 5 + 5; 250 250 let template = `Template with inner calculation: ${innerCalc}`; 251 - Ant.println(" Result:", template); 251 + console.log(" Result:", template); 252 252 253 253 // Test 29: Large numbers 254 - Ant.println("\nTest 29: Large numbers"); 254 + console.log("\nTest 29: Large numbers"); 255 255 let big = 1000000; 256 256 let formatted = `One million = ${big}`; 257 - Ant.println(" Result:", formatted); 257 + console.log(" Result:", formatted); 258 258 259 259 // Test 30: Performance test - multiple templates 260 - Ant.println("\nTest 30: Performance test"); 260 + console.log("\nTest 30: Performance test"); 261 261 for (let i = 0; i < 5; i++) { 262 262 let msg = `Iteration ${i}: ${i * 2}`; 263 - Ant.println(" " + msg); 263 + console.log(" " + msg); 264 264 } 265 265 266 - Ant.println("\n=== All template literal tests completed ==="); 266 + console.log("\n=== All template literal tests completed ===");
+35 -35
tests/test_async.cjs
··· 1 1 // Test async/await functionality 2 - Ant.println('=== Async/Await Tests ==='); 2 + console.log('=== Async/Await Tests ==='); 3 3 4 4 // Test 1: Basic async function 5 - Ant.println('\nTest 1: Basic async function'); 5 + console.log('\nTest 1: Basic async function'); 6 6 async function basicAsync() { 7 7 return 42; 8 8 } 9 9 10 10 basicAsync().then(v => { 11 - Ant.println('Basic async returned: ' + v); 11 + console.log('Basic async returned: ' + v); 12 12 }); 13 13 14 14 // Test 2: Async arrow function 15 - Ant.println('\nTest 2: Async arrow function'); 15 + console.log('\nTest 2: Async arrow function'); 16 16 const arrowAsync = async () => { 17 17 return 'arrow result'; 18 18 }; 19 19 20 20 arrowAsync().then(v => { 21 - Ant.println('Arrow async returned: ' + v); 21 + console.log('Arrow async returned: ' + v); 22 22 }); 23 23 24 24 // Test 3: Async arrow function with single parameter 25 - Ant.println('\nTest 3: Async arrow with param'); 25 + console.log('\nTest 3: Async arrow with param'); 26 26 const singleParamAsync = async x => { 27 27 return x * 2; 28 28 }; 29 29 30 30 singleParamAsync(21).then(v => { 31 - Ant.println('Single param async returned: ' + v); 31 + console.log('Single param async returned: ' + v); 32 32 }); 33 33 34 34 // Test 4: Async arrow function with multiple parameters 35 - Ant.println('\nTest 4: Async arrow with multiple params'); 35 + console.log('\nTest 4: Async arrow with multiple params'); 36 36 const multiParamAsync = async (a, b) => { 37 37 return a + b; 38 38 }; 39 39 40 40 multiParamAsync(10, 32).then(v => { 41 - Ant.println('Multi param async returned: ' + v); 41 + console.log('Multi param async returned: ' + v); 42 42 }); 43 43 44 44 // Test 5: Async function with Promise 45 - Ant.println('\nTest 5: Async function returning Promise'); 45 + console.log('\nTest 5: Async function returning Promise'); 46 46 async function withPromise() { 47 47 return Promise.resolve('promise from async'); 48 48 } 49 49 50 50 withPromise().then(v => { 51 - Ant.println('Async with promise: ' + v); 51 + console.log('Async with promise: ' + v); 52 52 }); 53 53 54 54 // Test 6: Async function with setTimeout 55 - Ant.println('\nTest 6: Async function with setTimeout'); 55 + console.log('\nTest 6: Async function with setTimeout'); 56 56 async function withTimeout() { 57 57 Ant.setTimeout(() => { 58 - Ant.println('Timeout inside async executed'); 58 + console.log('Timeout inside async executed'); 59 59 }, 100); 60 60 return 'timeout scheduled'; 61 61 } 62 62 63 63 withTimeout().then(v => { 64 - Ant.println('Async with timeout returned: ' + v); 64 + console.log('Async with timeout returned: ' + v); 65 65 }); 66 66 67 67 // Test 7: Async function with queueMicrotask 68 - Ant.println('\nTest 7: Async function with queueMicrotask'); 68 + console.log('\nTest 7: Async function with queueMicrotask'); 69 69 async function withMicrotask() { 70 70 Ant.queueMicrotask(() => { 71 - Ant.println('Microtask inside async executed'); 71 + console.log('Microtask inside async executed'); 72 72 }); 73 73 return 'microtask queued'; 74 74 } 75 75 76 76 withMicrotask().then(v => { 77 - Ant.println('Async with microtask returned: ' + v); 77 + console.log('Async with microtask returned: ' + v); 78 78 }); 79 79 80 80 // Test 8: Async functions must return primitives for now (Promise chaining limitation) 81 - Ant.println('\nTest 8: Async returning values'); 81 + console.log('\nTest 8: Async returning values'); 82 82 async function chain1() { 83 83 return 5; 84 84 } 85 85 86 86 chain1().then(v => { 87 - Ant.println('Chained async result: ' + (v * 2)); 87 + console.log('Chained async result: ' + (v * 2)); 88 88 }); 89 89 90 90 // Test 9: Async function as callback 91 - Ant.println('\nTest 9: Async function as callback'); 91 + console.log('\nTest 9: Async function as callback'); 92 92 function executor(fn) { 93 93 fn().then(v => { 94 - Ant.println('Callback async result: ' + v); 94 + console.log('Callback async result: ' + v); 95 95 }); 96 96 } 97 97 ··· 100 100 }); 101 101 102 102 // Test 10: Multiple promise chains 103 - Ant.println('\nTest 10: Multiple promise chains'); 103 + console.log('\nTest 10: Multiple promise chains'); 104 104 Promise.resolve(1) 105 105 .then(v => v + 1) 106 106 .then(v => v + 1) 107 107 .then(v => v + 1) 108 108 .then(v => { 109 - Ant.println('Multiple chains result: ' + v); 109 + console.log('Multiple chains result: ' + v); 110 110 }); 111 111 112 112 // Test 11: Async function expression 113 - Ant.println('\nTest 11: Async function expression'); 113 + console.log('\nTest 11: Async function expression'); 114 114 const asyncExpr = async function() { 115 115 return 'expression'; 116 116 }; 117 117 118 118 asyncExpr().then(v => { 119 - Ant.println('Async expression result: ' + v); 119 + console.log('Async expression result: ' + v); 120 120 }); 121 121 122 122 // Test 12: Async function with conditional 123 - Ant.println('\nTest 12: Async function with conditional'); 123 + console.log('\nTest 12: Async function with conditional'); 124 124 async function conditional(flag) { 125 125 if (flag) { 126 126 return 'true branch'; ··· 129 129 } 130 130 131 131 conditional(true).then(v => { 132 - Ant.println('Conditional async (true): ' + v); 132 + console.log('Conditional async (true): ' + v); 133 133 }); 134 134 135 135 conditional(false).then(v => { 136 - Ant.println('Conditional async (false): ' + v); 136 + console.log('Conditional async (false): ' + v); 137 137 }); 138 138 139 139 // Test 13: Async with Promise.resolve 140 - Ant.println('\nTest 13: Async with Promise.resolve'); 140 + console.log('\nTest 13: Async with Promise.resolve'); 141 141 async function withResolve() { 142 142 return Promise.resolve('resolved value'); 143 143 } 144 144 145 145 withResolve().then(v => { 146 - Ant.println('Async with resolve result: ' + v); 146 + console.log('Async with resolve result: ' + v); 147 147 }); 148 148 149 149 // Test 14: Async with object method 150 - Ant.println('\nTest 14: Async object method'); 150 + console.log('\nTest 14: Async object method'); 151 151 const obj = { 152 152 value: 100, 153 153 asyncMethod: async function() { ··· 156 156 }; 157 157 158 158 obj.asyncMethod().then(v => { 159 - Ant.println('Async object method: ' + v); 159 + console.log('Async object method: ' + v); 160 160 }); 161 161 162 162 // Test 15: Async arrow in object 163 - Ant.println('\nTest 15: Async arrow in object'); 163 + console.log('\nTest 15: Async arrow in object'); 164 164 const obj2 = { 165 165 value: 200, 166 166 asyncArrow: async () => { ··· 169 169 }; 170 170 171 171 obj2.asyncArrow().then(v => { 172 - Ant.println('Async arrow in object: ' + v); 172 + console.log('Async arrow in object: ' + v); 173 173 }); 174 174 175 - Ant.println('\n=== Synchronous code finished ==='); 175 + console.log('\n=== Synchronous code finished ===');
+35 -35
tests/test_async_await_integration.cjs
··· 1 1 // Integration test for async/await functionality 2 - Ant.println('=== Async/Await Integration Tests ==='); 2 + console.log('=== Async/Await Integration Tests ==='); 3 3 4 4 // Test 1: Async function that returns a value, consumed with await 5 - Ant.println('\nTest 1: Async function consumed with await'); 5 + console.log('\nTest 1: Async function consumed with await'); 6 6 async function getData() { 7 7 return 'data from async'; 8 8 } 9 9 10 10 async function consumeData() { 11 11 const data = await getData(); 12 - Ant.println('Consumed: ' + data); 12 + console.log('Consumed: ' + data); 13 13 return data; 14 14 } 15 15 16 - consumeData().then(v => Ant.println('Integration Test 1: ' + v)); 16 + consumeData().then(v => console.log('Integration Test 1: ' + v)); 17 17 18 18 // Test 2: Chain of async/await functions 19 - Ant.println('\nTest 2: Chain of async/await'); 19 + console.log('\nTest 2: Chain of async/await'); 20 20 async function step1() { 21 21 const val = await Promise.resolve(10); 22 22 return val * 2; ··· 32 32 return val * 3; 33 33 } 34 34 35 - step3().then(v => Ant.println('Integration Test 2: ' + v)); 35 + step3().then(v => console.log('Integration Test 2: ' + v)); 36 36 37 37 // Test 3: Await with Promise.resolve and transformation 38 - Ant.println('\nTest 3: Await with transformations'); 38 + console.log('\nTest 3: Await with transformations'); 39 39 async function transform() { 40 40 const a = await Promise.resolve(5); 41 41 const b = await Promise.resolve(10); ··· 43 43 return c * 2; 44 44 } 45 45 46 - transform().then(v => Ant.println('Integration Test 3: ' + v)); 46 + transform().then(v => console.log('Integration Test 3: ' + v)); 47 47 48 48 // Test 4: Async arrow with await 49 - Ant.println('\nTest 4: Async arrow with await'); 49 + console.log('\nTest 4: Async arrow with await'); 50 50 const asyncArrow = async (x) => { 51 51 const doubled = await Promise.resolve(x * 2); 52 52 return doubled + 10; 53 53 }; 54 54 55 - asyncArrow(5).then(v => Ant.println('Integration Test 4: ' + v)); 55 + asyncArrow(5).then(v => console.log('Integration Test 4: ' + v)); 56 56 57 57 // Test 5: Nested async calls with await 58 - Ant.println('\nTest 5: Nested async with await'); 58 + console.log('\nTest 5: Nested async with await'); 59 59 async function inner() { 60 60 return await Promise.resolve('inner value'); 61 61 } ··· 70 70 return 'outer wraps: ' + val; 71 71 } 72 72 73 - outer().then(v => Ant.println('Integration Test 5: ' + v)); 73 + outer().then(v => console.log('Integration Test 5: ' + v)); 74 74 75 75 // Test 6: Await in conditional branches 76 - Ant.println('\nTest 6: Conditional await'); 76 + console.log('\nTest 6: Conditional await'); 77 77 async function conditionalAwait(flag) { 78 78 if (flag) { 79 79 const val = await Promise.resolve(100); ··· 84 84 } 85 85 } 86 86 87 - conditionalAwait(true).then(v => Ant.println('Integration Test 6a: ' + v)); 88 - conditionalAwait(false).then(v => Ant.println('Integration Test 6b: ' + v)); 87 + conditionalAwait(true).then(v => console.log('Integration Test 6a: ' + v)); 88 + conditionalAwait(false).then(v => console.log('Integration Test 6b: ' + v)); 89 89 90 90 // Test 7: Multiple awaits with operations 91 - Ant.println('\nTest 7: Multiple awaits with math'); 91 + console.log('\nTest 7: Multiple awaits with math'); 92 92 async function calculate() { 93 93 const x = await Promise.resolve(3); 94 94 const y = await Promise.resolve(4); ··· 96 96 return x * x + y * y; 97 97 } 98 98 99 - calculate().then(v => Ant.println('Integration Test 7: ' + v)); 99 + calculate().then(v => console.log('Integration Test 7: ' + v)); 100 100 101 101 // Test 8: Await with object manipulation 102 - Ant.println('\nTest 8: Await with objects'); 102 + console.log('\nTest 8: Await with objects'); 103 103 async function objectTest() { 104 104 const obj = await Promise.resolve({ name: 'test', value: 42 }); 105 105 obj.value = obj.value * 2; 106 106 return obj.value; 107 107 } 108 108 109 - objectTest().then(v => Ant.println('Integration Test 8: ' + v)); 109 + objectTest().then(v => console.log('Integration Test 8: ' + v)); 110 110 111 111 // Test 9: Await with array manipulation 112 - Ant.println('\nTest 9: Await with arrays'); 112 + console.log('\nTest 9: Await with arrays'); 113 113 async function arrayTest() { 114 114 const arr = await Promise.resolve([1, 2, 3]); 115 115 const first = arr[0]; ··· 117 117 return first + second; 118 118 } 119 119 120 - arrayTest().then(v => Ant.println('Integration Test 9: ' + v)); 120 + arrayTest().then(v => console.log('Integration Test 9: ' + v)); 121 121 122 122 // Test 10: Await in async method 123 - Ant.println('\nTest 10: Await in object method'); 123 + console.log('\nTest 10: Await in object method'); 124 124 const calculator = { 125 125 multiplier: 3, 126 126 asyncMultiply: async function(n) { ··· 129 129 } 130 130 }; 131 131 132 - calculator.asyncMultiply(7).then(v => Ant.println('Integration Test 10: ' + v)); 132 + calculator.asyncMultiply(7).then(v => console.log('Integration Test 10: ' + v)); 133 133 134 134 // Test 11: Immediate await vs deferred 135 - Ant.println('\nTest 11: Immediate vs deferred await'); 135 + console.log('\nTest 11: Immediate vs deferred await'); 136 136 async function immediate() { 137 137 return await Promise.resolve('immediate'); 138 138 } ··· 143 143 return result; 144 144 } 145 145 146 - immediate().then(v => Ant.println('Integration Test 11a: ' + v)); 147 - deferred().then(v => Ant.println('Integration Test 11b: ' + v)); 146 + immediate().then(v => console.log('Integration Test 11a: ' + v)); 147 + deferred().then(v => console.log('Integration Test 11b: ' + v)); 148 148 149 149 // Test 12: Await non-promise values directly 150 - Ant.println('\nTest 12: Await non-promises'); 150 + console.log('\nTest 12: Await non-promises'); 151 151 async function awaitNonPromise() { 152 152 const a = await 10; 153 153 const b = await 'string'; ··· 155 155 return a; 156 156 } 157 157 158 - awaitNonPromise().then(v => Ant.println('Integration Test 12: ' + v)); 158 + awaitNonPromise().then(v => console.log('Integration Test 12: ' + v)); 159 159 160 160 // Test 13: Complex expression with await 161 - Ant.println('\nTest 13: Complex await expression'); 161 + console.log('\nTest 13: Complex await expression'); 162 162 async function complexExpr() { 163 163 const result = (await Promise.resolve(5)) + (await Promise.resolve(3)) * 2; 164 164 return result; 165 165 } 166 166 167 - complexExpr().then(v => Ant.println('Integration Test 13: ' + v)); 167 + complexExpr().then(v => console.log('Integration Test 13: ' + v)); 168 168 169 169 // Test 14: Await with string concatenation 170 - Ant.println('\nTest 14: Await with string ops'); 170 + console.log('\nTest 14: Await with string ops'); 171 171 async function stringOps() { 172 172 const part1 = await Promise.resolve('Hello'); 173 173 const part2 = await Promise.resolve(' '); ··· 175 175 return part1 + part2 + part3; 176 176 } 177 177 178 - stringOps().then(v => Ant.println('Integration Test 14: ' + v)); 178 + stringOps().then(v => console.log('Integration Test 14: ' + v)); 179 179 180 180 // Test 15: Return statement with await 181 - Ant.println('\nTest 15: Direct return await'); 181 + console.log('\nTest 15: Direct return await'); 182 182 async function directReturn() { 183 183 return await Promise.resolve('direct return'); 184 184 } 185 185 186 - directReturn().then(v => Ant.println('Integration Test 15: ' + v)); 186 + directReturn().then(v => console.log('Integration Test 15: ' + v)); 187 187 188 - Ant.println('\n=== All integration tests initiated ==='); 188 + console.log('\n=== All integration tests initiated ===');
+17 -17
tests/test_async_class_methods.cjs
··· 8 8 9 9 // Regular method 10 10 regularMethod() { 11 - Ant.println('regularMethod: this.name = ' + this.name); 11 + console.log('regularMethod: this.name = ' + this.name); 12 12 return this.value; 13 13 } 14 14 15 15 // Async method 16 16 async asyncMethod() { 17 - Ant.println('asyncMethod: this.name = ' + this.name); 17 + console.log('asyncMethod: this.name = ' + this.name); 18 18 return Promise.resolve(this.value * 2); 19 19 } 20 20 21 21 // Async method with argument 22 22 async asyncWithArg(multiplier) { 23 - Ant.println('asyncWithArg: this.name = ' + this.name + ', multiplier = ' + multiplier); 23 + console.log('asyncWithArg: this.name = ' + this.name + ', multiplier = ' + multiplier); 24 24 return Promise.resolve(this.value * multiplier); 25 25 } 26 26 ··· 29 29 function helper() { 30 30 return 10; 31 31 } 32 - Ant.println('asyncWithHelper: this.name = ' + this.name); 32 + console.log('asyncWithHelper: this.name = ' + this.name); 33 33 const extra = helper(); 34 34 return Promise.resolve(this.value + extra); 35 35 } ··· 37 37 38 38 const obj = new AsyncTestClass(); 39 39 40 - Ant.println('=== Test 1: Regular method ==='); 40 + console.log('=== Test 1: Regular method ==='); 41 41 const result1 = obj.regularMethod(); 42 - Ant.println('Result: ' + result1); 42 + console.log('Result: ' + result1); 43 43 44 - Ant.println('\n=== Test 2: Async method ==='); 44 + console.log('\n=== Test 2: Async method ==='); 45 45 const promise2 = obj.asyncMethod(); 46 - Ant.println('Returned: ' + (typeof promise2)); 46 + console.log('Returned: ' + (typeof promise2)); 47 47 promise2.then((val) => { 48 - Ant.println('Resolved value: ' + val); 49 - Ant.println('Inside .then(), this.name: ' + this.name); 48 + console.log('Resolved value: ' + val); 49 + console.log('Inside .then(), this.name: ' + this.name); 50 50 }); 51 51 52 - Ant.println('\n=== Test 3: Async method with argument ==='); 52 + console.log('\n=== Test 3: Async method with argument ==='); 53 53 const promise3 = obj.asyncWithArg(5); 54 - Ant.println('Returned: ' + (typeof promise3)); 54 + console.log('Returned: ' + (typeof promise3)); 55 55 promise3.then((val) => { 56 - Ant.println('Resolved value: ' + val); 56 + console.log('Resolved value: ' + val); 57 57 }); 58 58 59 - Ant.println('\n=== Test 4: Async method with helper function ==='); 59 + console.log('\n=== Test 4: Async method with helper function ==='); 60 60 const promise4 = obj.asyncWithHelper(); 61 - Ant.println('Returned: ' + (typeof promise4)); 61 + console.log('Returned: ' + (typeof promise4)); 62 62 promise4.then((val) => { 63 - Ant.println('Resolved value: ' + val); 63 + console.log('Resolved value: ' + val); 64 64 }); 65 65 66 - Ant.println('\n=== All tests completed ==='); 66 + console.log('\n=== All tests completed ===');
+22 -22
tests/test_async_loops.cjs
··· 1 1 // Test async/await with loops 2 - Ant.println('=== Async/Await with Loops Tests ==='); 2 + console.log('=== Async/Await with Loops Tests ==='); 3 3 4 4 // Test 1: Await in for loop 5 - Ant.println('\nTest 1: Await in for loop'); 5 + console.log('\nTest 1: Await in for loop'); 6 6 async function test1() { 7 7 let sum = 0; 8 8 for (let i = 0; i < 3; i = i + 1) { ··· 11 11 } 12 12 return sum; 13 13 } 14 - test1().then(v => Ant.println('Test 1: ' + v)); 14 + test1().then(v => console.log('Test 1: ' + v)); 15 15 16 16 // Test 2: Await in while loop 17 - Ant.println('\nTest 2: Await in while loop'); 17 + console.log('\nTest 2: Await in while loop'); 18 18 async function test2() { 19 19 let i = 0; 20 20 let sum = 0; ··· 25 25 } 26 26 return sum; 27 27 } 28 - test2().then(v => Ant.println('Test 2: ' + v)); 28 + test2().then(v => console.log('Test 2: ' + v)); 29 29 30 30 // Test 3: Await in do-while loop 31 - Ant.println('\nTest 3: Await in do-while loop'); 31 + console.log('\nTest 3: Await in do-while loop'); 32 32 async function test3() { 33 33 let i = 0; 34 34 let sum = 0; ··· 39 39 } while (i < 3); 40 40 return sum; 41 41 } 42 - test3().then(v => Ant.println('Test 3: ' + v)); 42 + test3().then(v => console.log('Test 3: ' + v)); 43 43 44 44 // Test 4: Multiple awaits in loop 45 - Ant.println('\nTest 4: Multiple awaits in loop'); 45 + console.log('\nTest 4: Multiple awaits in loop'); 46 46 async function test4() { 47 47 let result = 0; 48 48 for (let i = 0; i < 2; i = i + 1) { ··· 52 52 } 53 53 return result; 54 54 } 55 - test4().then(v => Ant.println('Test 4: ' + v)); 55 + test4().then(v => console.log('Test 4: ' + v)); 56 56 57 57 // Test 5: Await with break 58 - Ant.println('\nTest 5: Await with break'); 58 + console.log('\nTest 5: Await with break'); 59 59 async function test5() { 60 60 let i = 0; 61 61 while (i < 10) { ··· 67 67 } 68 68 return i; 69 69 } 70 - test5().then(v => Ant.println('Test 5: ' + v)); 70 + test5().then(v => console.log('Test 5: ' + v)); 71 71 72 72 // Test 6: Await with continue 73 - Ant.println('\nTest 6: Await with continue'); 73 + console.log('\nTest 6: Await with continue'); 74 74 async function test6() { 75 75 let sum = 0; 76 76 for (let i = 0; i < 5; i = i + 1) { ··· 82 82 } 83 83 return sum; 84 84 } 85 - test6().then(v => Ant.println('Test 6: ' + v)); 85 + test6().then(v => console.log('Test 6: ' + v)); 86 86 87 87 // Test 7: Nested loops with await 88 - Ant.println('\nTest 7: Nested loops with await'); 88 + console.log('\nTest 7: Nested loops with await'); 89 89 async function test7() { 90 90 let count = 0; 91 91 for (let i = 0; i < 2; i = i + 1) { ··· 96 96 } 97 97 return count; 98 98 } 99 - test7().then(v => Ant.println('Test 7: ' + v)); 99 + test7().then(v => console.log('Test 7: ' + v)); 100 100 101 101 // Test 8: While loop with async condition check 102 - Ant.println('\nTest 8: While loop awaiting values'); 102 + console.log('\nTest 8: While loop awaiting values'); 103 103 async function test8() { 104 104 let i = 0; 105 105 let product = 1; ··· 110 110 } 111 111 return product; 112 112 } 113 - test8().then(v => Ant.println('Test 8: ' + v)); 113 + test8().then(v => console.log('Test 8: ' + v)); 114 114 115 115 // Test 9: Do-while with await and condition 116 - Ant.println('\nTest 9: Do-while with await'); 116 + console.log('\nTest 9: Do-while with await'); 117 117 async function test9() { 118 118 let count = 0; 119 119 let val; ··· 123 123 } while (val < 2); 124 124 return count; 125 125 } 126 - test9().then(v => Ant.println('Test 9: ' + v)); 126 + test9().then(v => console.log('Test 9: ' + v)); 127 127 128 128 // Test 10: For loop building array with await 129 - Ant.println('\nTest 10: Building array with await in loop'); 129 + console.log('\nTest 10: Building array with await in loop'); 130 130 async function test10() { 131 131 const arr = []; 132 132 for (let i = 0; i < 3; i = i + 1) { ··· 135 135 } 136 136 return arr[0] + arr[1] + arr[2]; 137 137 } 138 - test10().then(v => Ant.println('Test 10: ' + v)); 138 + test10().then(v => console.log('Test 10: ' + v)); 139 139 140 - Ant.println('\n=== All async loop tests initiated ==='); 140 + console.log('\n=== All async loop tests initiated ===');
+21 -21
tests/test_async_regular_function.cjs
··· 7 7 } 8 8 9 9 testPromiseWithRegularFunction() { 10 - Ant.println('=== testPromiseWithRegularFunction ==='); 11 - Ant.println('Before promise: this.name = ' + this.name); 10 + console.log('=== testPromiseWithRegularFunction ==='); 11 + console.log('Before promise: this.name = ' + this.name); 12 12 13 13 return Promise.resolve(42).then(function(val) { 14 - Ant.println('Inside .then() with function:'); 15 - Ant.println(' typeof this: ' + typeof this); 16 - Ant.println(' this.name: ' + this.name); 17 - Ant.println(' this.value: ' + this.value); 14 + console.log('Inside .then() with function:'); 15 + console.log(' typeof this: ' + typeof this); 16 + console.log(' this.name: ' + this.name); 17 + console.log(' this.value: ' + this.value); 18 18 return val + 1; 19 19 }); 20 20 } 21 21 22 22 testPromiseWithArrowFunction() { 23 - Ant.println('\n=== testPromiseWithArrowFunction ==='); 24 - Ant.println('Before promise: this.name = ' + this.name); 23 + console.log('\n=== testPromiseWithArrowFunction ==='); 24 + console.log('Before promise: this.name = ' + this.name); 25 25 26 26 return Promise.resolve(42).then((val) => { 27 - Ant.println('Inside .then() with arrow:'); 28 - Ant.println(' typeof this: ' + typeof this); 29 - Ant.println(' this.name: ' + this.name); 30 - Ant.println(' this.value: ' + this.value); 27 + console.log('Inside .then() with arrow:'); 28 + console.log(' typeof this: ' + typeof this); 29 + console.log(' this.name: ' + this.name); 30 + console.log(' this.value: ' + this.value); 31 31 return val + 1; 32 32 }); 33 33 } 34 34 35 35 testMethodCallingPromiseWithFunction() { 36 - Ant.println('\n=== testMethodCallingPromiseWithFunction ==='); 36 + console.log('\n=== testMethodCallingPromiseWithFunction ==='); 37 37 const self = this; 38 - Ant.println('Before promise: this.name = ' + this.name); 38 + console.log('Before promise: this.name = ' + this.name); 39 39 40 40 return Promise.resolve(1).then(function() { 41 - Ant.println('In .then() with function:'); 42 - Ant.println(' this.name: ' + this.name); 43 - Ant.println(' self.name: ' + self.name); 41 + console.log('In .then() with function:'); 42 + console.log(' this.name: ' + this.name); 43 + console.log(' self.name: ' + self.name); 44 44 return self.value; 45 45 }); 46 46 } ··· 49 49 const obj = new AsyncRegularFunctionTest('TestObject'); 50 50 51 51 obj.testPromiseWithRegularFunction().then(function(result) { 52 - Ant.println('Result 1: ' + result); 52 + console.log('Result 1: ' + result); 53 53 }); 54 54 55 55 obj.testPromiseWithArrowFunction().then((result) => { 56 - Ant.println('Result 2: ' + result); 56 + console.log('Result 2: ' + result); 57 57 }); 58 58 59 59 obj.testMethodCallingPromiseWithFunction().then((result) => { 60 - Ant.println('Result 3: ' + result); 60 + console.log('Result 3: ' + result); 61 61 }); 62 62 63 - Ant.println('\n=== All tests queued ==='); 63 + console.log('\n=== All tests queued ===');
+17 -17
tests/test_async_this.cjs
··· 7 7 } 8 8 9 9 asyncMethod(arg) { 10 - Ant.println('asyncMethod called:'); 11 - Ant.println(' this.name: ' + this.name); 12 - Ant.println(' this.value: ' + this.value); 13 - Ant.println(' arg: ' + arg); 10 + console.log('asyncMethod called:'); 11 + console.log(' this.name: ' + this.name); 12 + console.log(' this.value: ' + this.value); 13 + console.log(' arg: ' + arg); 14 14 return Promise.resolve(this.value + 10); 15 15 } 16 16 17 17 methodWithPromise() { 18 - Ant.println('methodWithPromise called:'); 19 - Ant.println(' this.name: ' + this.name); 18 + console.log('methodWithPromise called:'); 19 + console.log(' this.name: ' + this.name); 20 20 21 21 return Promise.resolve(this.value).then((v) => { 22 - Ant.println(' Inside .then(), this.name: ' + this.name); 23 - Ant.println(' Inside .then(), this.value: ' + this.value); 22 + console.log(' Inside .then(), this.name: ' + this.name); 23 + console.log(' Inside .then(), this.value: ' + this.value); 24 24 return v * 2; 25 25 }); 26 26 } 27 27 28 28 nestedAsync(helperFunc) { 29 - Ant.println('nestedAsync called:'); 30 - Ant.println(' this.name: ' + this.name); 29 + console.log('nestedAsync called:'); 30 + console.log(' this.name: ' + this.name); 31 31 const result = helperFunc(); 32 - Ant.println(' After helper call, this.name: ' + this.name); 32 + console.log(' After helper call, this.name: ' + this.name); 33 33 return result; 34 34 } 35 35 } ··· 40 40 41 41 const obj = new AsyncClass(); 42 42 43 - Ant.println('=== Test 1: Async method ==='); 43 + console.log('=== Test 1: Async method ==='); 44 44 const p1 = obj.asyncMethod('test'); 45 - Ant.println('Promise returned: ' + (typeof p1)); 45 + console.log('Promise returned: ' + (typeof p1)); 46 46 47 - Ant.println('\n=== Test 2: Method with promise chain ==='); 47 + console.log('\n=== Test 2: Method with promise chain ==='); 48 48 const p2 = obj.methodWithPromise(); 49 - Ant.println('Promise returned: ' + (typeof p2)); 49 + console.log('Promise returned: ' + (typeof p2)); 50 50 51 - Ant.println('\n=== Test 3: Nested call with helper ==='); 51 + console.log('\n=== Test 3: Nested call with helper ==='); 52 52 obj.nestedAsync(helperFunction); 53 53 54 - Ant.println('\n=== All tests completed ==='); 54 + console.log('\n=== All tests completed ===');
+11 -11
tests/test_async_this_binding.cjs
··· 6 6 } 7 7 8 8 methodThatReturnsPromise() { 9 - Ant.println('methodThatReturnsPromise: this.name = ' + this.name); 9 + console.log('methodThatReturnsPromise: this.name = ' + this.name); 10 10 11 11 // Use regular function (not arrow) in .then() 12 12 return Promise.resolve('value').then(function(val) { 13 13 // In standard JS, 'this' would be undefined here 14 14 // Let's see what Ant does 15 - Ant.println('In .then() regular function:'); 16 - Ant.println(' typeof this: ' + typeof this); 17 - Ant.println(' this: ' + this); 15 + console.log('In .then() regular function:'); 16 + console.log(' typeof this: ' + typeof this); 17 + console.log(' this: ' + this); 18 18 19 19 // Try to access properties 20 20 if (typeof this.name !== 'undefined') { 21 - Ant.println(' this.name: ' + this.name); 21 + console.log(' this.name: ' + this.name); 22 22 } else { 23 - Ant.println(' this.name is undefined'); 23 + console.log(' this.name is undefined'); 24 24 } 25 25 26 26 return val; ··· 31 31 const obj1 = new TestClass('Object1'); 32 32 const obj2 = new TestClass('Object2'); 33 33 34 - Ant.println('=== Calling obj1.methodThatReturnsPromise() ==='); 34 + console.log('=== Calling obj1.methodThatReturnsPromise() ==='); 35 35 obj1.methodThatReturnsPromise().then(function(result) { 36 - Ant.println('Final result: ' + result); 36 + console.log('Final result: ' + result); 37 37 }); 38 38 39 - Ant.println('\n=== Calling obj2.methodThatReturnsPromise() ==='); 39 + console.log('\n=== Calling obj2.methodThatReturnsPromise() ==='); 40 40 obj2.methodThatReturnsPromise().then(function(result) { 41 - Ant.println('Final result: ' + result); 41 + console.log('Final result: ' + result); 42 42 }); 43 43 44 - Ant.println('\n=== Tests queued ==='); 44 + console.log('\n=== Tests queued ===');
+16 -16
tests/test_async_this_context.cjs
··· 7 7 } 8 8 9 9 testPromiseThen() { 10 - Ant.println('=== testPromiseThen ==='); 11 - Ant.println('Before promise: this.name = ' + this.name); 10 + console.log('=== testPromiseThen ==='); 11 + console.log('Before promise: this.name = ' + this.name); 12 12 13 13 return Promise.resolve(42).then((val) => { 14 - Ant.println('Inside .then(): this.name = ' + this.name); 15 - Ant.println('Inside .then(): this.value = ' + this.value); 14 + console.log('Inside .then(): this.name = ' + this.name); 15 + console.log('Inside .then(): this.value = ' + this.value); 16 16 return this.value + val; 17 17 }); 18 18 } 19 19 20 20 testNestedPromises() { 21 - Ant.println('\n=== testNestedPromises ==='); 22 - Ant.println('Before promise: this.name = ' + this.name); 21 + console.log('\n=== testNestedPromises ==='); 22 + console.log('Before promise: this.name = ' + this.name); 23 23 24 24 return Promise.resolve(10).then((val1) => { 25 - Ant.println('First .then(): this.name = ' + this.name); 25 + console.log('First .then(): this.name = ' + this.name); 26 26 return Promise.resolve(val1 + this.value).then((val2) => { 27 - Ant.println('Second .then(): this.name = ' + this.name); 27 + console.log('Second .then(): this.name = ' + this.name); 28 28 return val2 * 2; 29 29 }); 30 30 }); 31 31 } 32 32 33 33 testMethodCallingAsync() { 34 - Ant.println('\n=== testMethodCallingAsync ==='); 35 - Ant.println('Before: this.name = ' + this.name); 34 + console.log('\n=== testMethodCallingAsync ==='); 35 + console.log('Before: this.name = ' + this.name); 36 36 37 37 const helper = () => { 38 - Ant.println('Inside helper: this.name = ' + this.name); 38 + console.log('Inside helper: this.name = ' + this.name); 39 39 return this.value; 40 40 }; 41 41 42 42 return Promise.resolve(1).then(() => { 43 - Ant.println('In .then(), calling helper'); 43 + console.log('In .then(), calling helper'); 44 44 return helper(); 45 45 }); 46 46 } ··· 49 49 const obj = new AsyncContextTest('TestObject'); 50 50 51 51 obj.testPromiseThen().then((result) => { 52 - Ant.println('Result 1: ' + result); 52 + console.log('Result 1: ' + result); 53 53 }); 54 54 55 55 obj.testNestedPromises().then((result) => { 56 - Ant.println('Result 2: ' + result); 56 + console.log('Result 2: ' + result); 57 57 }); 58 58 59 59 obj.testMethodCallingAsync().then((result) => { 60 - Ant.println('Result 3: ' + result); 60 + console.log('Result 3: ' + result); 61 61 }); 62 62 63 - Ant.println('\n=== All tests queued ==='); 63 + console.log('\n=== All tests queued ===');
+50 -50
tests/test_await.cjs
··· 1 1 // Test await functionality 2 - Ant.println('=== Await Tests ==='); 2 + console.log('=== Await Tests ==='); 3 3 4 4 // Test 1: Basic await with resolved promise 5 - Ant.println('\nTest 1: Basic await with resolved promise'); 5 + console.log('\nTest 1: Basic await with resolved promise'); 6 6 async function test1() { 7 7 const result = await Promise.resolve(42); 8 - Ant.println('Awaited resolved promise: ' + result); 8 + console.log('Awaited resolved promise: ' + result); 9 9 return result; 10 10 } 11 - test1().then(v => Ant.println('Test 1 returned: ' + v)); 11 + test1().then(v => console.log('Test 1 returned: ' + v)); 12 12 13 13 // Test 2: Await with Promise.resolve string 14 - Ant.println('\nTest 2: Await with string promise'); 14 + console.log('\nTest 2: Await with string promise'); 15 15 async function test2() { 16 16 const msg = await Promise.resolve('hello world'); 17 - Ant.println('Awaited string: ' + msg); 17 + console.log('Awaited string: ' + msg); 18 18 return msg; 19 19 } 20 - test2().then(v => Ant.println('Test 2 returned: ' + v)); 20 + test2().then(v => console.log('Test 2 returned: ' + v)); 21 21 22 22 // Test 3: Await non-promise value (should return value directly) 23 - Ant.println('\nTest 3: Await non-promise value'); 23 + console.log('\nTest 3: Await non-promise value'); 24 24 async function test3() { 25 25 const value = await 100; 26 - Ant.println('Awaited non-promise: ' + value); 26 + console.log('Awaited non-promise: ' + value); 27 27 return value; 28 28 } 29 - test3().then(v => Ant.println('Test 3 returned: ' + v)); 29 + test3().then(v => console.log('Test 3 returned: ' + v)); 30 30 31 31 // Test 4: Multiple awaits in sequence 32 - Ant.println('\nTest 4: Multiple sequential awaits'); 32 + console.log('\nTest 4: Multiple sequential awaits'); 33 33 async function test4() { 34 34 const a = await Promise.resolve(10); 35 35 const b = await Promise.resolve(20); 36 36 const c = await Promise.resolve(30); 37 37 const sum = a + b + c; 38 - Ant.println('Sum of awaited values: ' + sum); 38 + console.log('Sum of awaited values: ' + sum); 39 39 return sum; 40 40 } 41 - test4().then(v => Ant.println('Test 4 returned: ' + v)); 41 + test4().then(v => console.log('Test 4 returned: ' + v)); 42 42 43 43 // Test 5: Await in expression 44 - Ant.println('\nTest 5: Await in expression'); 44 + console.log('\nTest 5: Await in expression'); 45 45 async function test5() { 46 46 const result = (await Promise.resolve(5)) * 2; 47 - Ant.println('Awaited and multiplied: ' + result); 47 + console.log('Awaited and multiplied: ' + result); 48 48 return result; 49 49 } 50 - test5().then(v => Ant.println('Test 5 returned: ' + v)); 50 + test5().then(v => console.log('Test 5 returned: ' + v)); 51 51 52 52 // Test 6: Await with conditional 53 - Ant.println('\nTest 6: Await with conditional'); 53 + console.log('\nTest 6: Await with conditional'); 54 54 async function test6(flag) { 55 55 if (flag) { 56 56 const v = await Promise.resolve('true branch'); ··· 60 60 return v; 61 61 } 62 62 } 63 - test6(true).then(v => Ant.println('Test 6 (true): ' + v)); 64 - test6(false).then(v => Ant.println('Test 6 (false): ' + v)); 63 + test6(true).then(v => console.log('Test 6 (true): ' + v)); 64 + test6(false).then(v => console.log('Test 6 (false): ' + v)); 65 65 66 66 // Test 7: Async arrow function with await 67 - Ant.println('\nTest 7: Async arrow function with await'); 67 + console.log('\nTest 7: Async arrow function with await'); 68 68 const test7 = async () => { 69 69 const x = await Promise.resolve(7); 70 70 return x * 7; 71 71 }; 72 - test7().then(v => Ant.println('Test 7 returned: ' + v)); 72 + test7().then(v => console.log('Test 7 returned: ' + v)); 73 73 74 74 // Test 8: Async arrow with parameter and await 75 - Ant.println('\nTest 8: Async arrow with parameter'); 75 + console.log('\nTest 8: Async arrow with parameter'); 76 76 const test8 = async (n) => { 77 77 const result = await Promise.resolve(n); 78 78 return result + 10; 79 79 }; 80 - test8(5).then(v => Ant.println('Test 8 returned: ' + v)); 80 + test8(5).then(v => console.log('Test 8 returned: ' + v)); 81 81 82 82 // Test 9: Await with object property 83 - Ant.println('\nTest 9: Await with object'); 83 + console.log('\nTest 9: Await with object'); 84 84 async function test9() { 85 85 const obj = await Promise.resolve({ x: 100, y: 200 }); 86 - Ant.println('Awaited object.x: ' + obj.x); 86 + console.log('Awaited object.x: ' + obj.x); 87 87 return obj.y; 88 88 } 89 - test9().then(v => Ant.println('Test 9 returned: ' + v)); 89 + test9().then(v => console.log('Test 9 returned: ' + v)); 90 90 91 91 // Test 10: Await with array 92 - Ant.println('\nTest 10: Await with array'); 92 + console.log('\nTest 10: Await with array'); 93 93 async function test10() { 94 94 const arr = await Promise.resolve([1, 2, 3]); 95 - Ant.println('Awaited array[0]: ' + arr[0]); 95 + console.log('Awaited array[0]: ' + arr[0]); 96 96 return arr[1]; 97 97 } 98 - test10().then(v => Ant.println('Test 10 returned: ' + v)); 98 + test10().then(v => console.log('Test 10 returned: ' + v)); 99 99 100 100 // Test 11: Nested async functions with await 101 - Ant.println('\nTest 11: Nested async functions'); 101 + console.log('\nTest 11: Nested async functions'); 102 102 async function inner11() { 103 103 return await Promise.resolve('inner result'); 104 104 } ··· 106 106 const result = await inner11(); 107 107 return 'outer got: ' + result; 108 108 } 109 - outer11().then(v => Ant.println('Test 11 returned: ' + v)); 109 + outer11().then(v => console.log('Test 11 returned: ' + v)); 110 110 111 111 // Test 12: Await in async method 112 - Ant.println('\nTest 12: Await in async method'); 112 + console.log('\nTest 12: Await in async method'); 113 113 const obj12 = { 114 114 value: 50, 115 115 asyncMethod: async function() { ··· 117 117 return this.value * multiplier; 118 118 } 119 119 }; 120 - obj12.asyncMethod().then(v => Ant.println('Test 12 returned: ' + v)); 120 + obj12.asyncMethod().then(v => console.log('Test 12 returned: ' + v)); 121 121 122 122 // Test 13: Await with string concatenation 123 - Ant.println('\nTest 13: Await with string operations'); 123 + console.log('\nTest 13: Await with string operations'); 124 124 async function test13() { 125 125 const first = await Promise.resolve('Hello'); 126 126 const second = await Promise.resolve('World'); 127 127 return first + ' ' + second; 128 128 } 129 - test13().then(v => Ant.println('Test 13 returned: ' + v)); 129 + test13().then(v => console.log('Test 13 returned: ' + v)); 130 130 131 131 // Test 14: Await with nested promise chains 132 - Ant.println('\nTest 14: Await with chained values'); 132 + console.log('\nTest 14: Await with chained values'); 133 133 async function test14() { 134 134 const a = await Promise.resolve(1); 135 135 const b = await Promise.resolve(a + 1); 136 136 const c = await Promise.resolve(b + 1); 137 137 return c; 138 138 } 139 - test14().then(v => Ant.println('Test 14 returned: ' + v)); 139 + test14().then(v => console.log('Test 14 returned: ' + v)); 140 140 141 141 // Test 15: Return await 142 - Ant.println('\nTest 15: Return await'); 142 + console.log('\nTest 15: Return await'); 143 143 async function test15() { 144 144 return await Promise.resolve('returned from await'); 145 145 } 146 - test15().then(v => Ant.println('Test 15 returned: ' + v)); 146 + test15().then(v => console.log('Test 15 returned: ' + v)); 147 147 148 148 // Test 16: Await boolean value 149 - Ant.println('\nTest 16: Await boolean'); 149 + console.log('\nTest 16: Await boolean'); 150 150 async function test16() { 151 151 const result = await Promise.resolve(true); 152 152 if (result) { ··· 154 154 } 155 155 return 'boolean was false'; 156 156 } 157 - test16().then(v => Ant.println('Test 16 returned: ' + v)); 157 + test16().then(v => console.log('Test 16 returned: ' + v)); 158 158 159 159 // Test 17: Await null 160 - Ant.println('\nTest 17: Await null'); 160 + console.log('\nTest 17: Await null'); 161 161 async function test17() { 162 162 const result = await Promise.resolve(null); 163 163 return result; 164 164 } 165 - test17().then(v => Ant.println('Test 17 returned (null): ' + v)); 165 + test17().then(v => console.log('Test 17 returned (null): ' + v)); 166 166 167 167 // Test 18: Await undefined 168 - Ant.println('\nTest 18: Await undefined'); 168 + console.log('\nTest 18: Await undefined'); 169 169 async function test18() { 170 170 const result = await Promise.resolve(undefined); 171 171 return result; 172 172 } 173 - test18().then(v => Ant.println('Test 18 returned (undefined): ' + v)); 173 + test18().then(v => console.log('Test 18 returned (undefined): ' + v)); 174 174 175 175 // Test 19: Async function expression with await 176 - Ant.println('\nTest 19: Async function expression'); 176 + console.log('\nTest 19: Async function expression'); 177 177 const test19 = async function() { 178 178 const x = await Promise.resolve(19); 179 179 return x; 180 180 }; 181 - test19().then(v => Ant.println('Test 19 returned: ' + v)); 181 + test19().then(v => console.log('Test 19 returned: ' + v)); 182 182 183 183 // Test 20: Await with arithmetic operations 184 - Ant.println('\nTest 20: Await with arithmetic'); 184 + console.log('\nTest 20: Await with arithmetic'); 185 185 async function test20() { 186 186 const a = await Promise.resolve(10); 187 187 const b = await Promise.resolve(5); 188 188 return a + b * 2; 189 189 } 190 - test20().then(v => Ant.println('Test 20 returned: ' + v)); 190 + test20().then(v => console.log('Test 20 returned: ' + v)); 191 191 192 - Ant.println('\n=== Synchronous code finished ==='); 192 + console.log('\n=== Synchronous code finished ===');
+1 -1
tests/test_block_closure.cjs
··· 9 9 }; 10 10 } 11 11 } 12 - Ant.println(result()); // Should print 15 12 + console.log(result()); // Should print 15
+2 -2
tests/test_class_closure.cjs
··· 16 16 } 17 17 18 18 let obj = new MyClass(); 19 - Ant.println(obj.getX()); // Should print 100 20 - Ant.println(obj.getSum()); // Should print 110 19 + console.log(obj.getX()); // Should print 100 20 + console.log(obj.getSum()); // Should print 110
+50
tests/test_date.cjs
··· 1 + // Test Date builtin functionality 2 + 3 + // Test 1: Date.now() returns a number 4 + console.log('Test 1: Date.now() returns a number'); 5 + const now1 = Date.now(); 6 + console.log('Date.now() =', now1); 7 + console.log('typeof Date.now() =', typeof now1); 8 + 9 + // Test 2: Date.now() returns milliseconds since epoch 10 + console.log('\nTest 2: Date.now() returns reasonable timestamp'); 11 + const now2 = Date.now(); 12 + // Should be a large number (milliseconds since 1970) 13 + console.log('Date.now() > 1000000000000 ?', now2 > 1000000000000); 14 + 15 + // Test 3: new Date() creates an object 16 + console.log('\nTest 3: new Date() creates an object'); 17 + const d1 = new Date(); 18 + console.log('typeof new Date() =', typeof d1); 19 + console.log('new Date() =', d1); 20 + 21 + // Test 4: new Date(timestamp) works 22 + console.log('\nTest 4: new Date(timestamp)'); 23 + const d2 = new Date(1234567890000); 24 + console.log('new Date(1234567890000) =', d2); 25 + 26 + // Test 5: Date.now() is monotonic (or at least consistent) 27 + console.log('\nTest 5: Date.now() consistency'); 28 + const t1 = Date.now(); 29 + const t2 = Date.now(); 30 + console.log('t1 =', t1); 31 + console.log('t2 =', t2); 32 + console.log('t2 >= t1 ?', t2 >= t1); 33 + 34 + // Test 6: Multiple calls to Date.now() return numbers 35 + console.log('\nTest 6: Multiple Date.now() calls'); 36 + const times = []; 37 + for (let i = 0; i < 3; i++) { 38 + times.push(Date.now()); 39 + } 40 + console.log('Times:', times); 41 + console.log('All are numbers?', times.every(t => typeof t === 'number')); 42 + 43 + // Test 7: Date constructor with no args vs Date.now() 44 + console.log('\nTest 7: Compare new Date() and Date.now()'); 45 + const dateObj = new Date(); 46 + const nowTime = Date.now(); 47 + console.log('new Date() created:', dateObj); 48 + console.log('Date.now() =', nowTime); 49 + 50 + console.log('\nAll Date tests completed!');
+8 -8
tests/test_deep_this.cjs
··· 7 7 } 8 8 9 9 method1(func) { 10 - Ant.println('method1: this.name = ' + this.name + ', depth = ' + this.depth); 10 + console.log('method1: this.name = ' + this.name + ', depth = ' + this.depth); 11 11 this.depth++; 12 12 const result = func(); 13 13 this.depth--; ··· 15 15 } 16 16 17 17 method2(func) { 18 - Ant.println('method2: this.name = ' + this.name + ', depth = ' + this.depth); 18 + console.log('method2: this.name = ' + this.name + ', depth = ' + this.depth); 19 19 this.depth++; 20 20 const result = func(); 21 21 this.depth--; ··· 23 23 } 24 24 25 25 method3(func) { 26 - Ant.println('method3: this.name = ' + this.name + ', depth = ' + this.depth); 26 + console.log('method3: this.name = ' + this.name + ', depth = ' + this.depth); 27 27 this.depth++; 28 28 const result = func(); 29 29 this.depth--; ··· 31 31 } 32 32 33 33 leaf() { 34 - Ant.println('leaf: this.name = ' + this.name + ', depth = ' + this.depth); 34 + console.log('leaf: this.name = ' + this.name + ', depth = ' + this.depth); 35 35 return 'done'; 36 36 } 37 37 } ··· 47 47 const obj1 = new DeepClass('obj1'); 48 48 const obj2 = new DeepClass('obj2'); 49 49 50 - Ant.println('=== Test 1: Deeply nested calls on same object ==='); 50 + console.log('=== Test 1: Deeply nested calls on same object ==='); 51 51 obj1.method1(() => { 52 52 return obj1.method2(() => { 53 53 return obj1.method3(() => { ··· 56 56 }); 57 57 }); 58 58 59 - Ant.println('\n=== Test 2: Interleaved calls on different objects ==='); 59 + console.log('\n=== Test 2: Interleaved calls on different objects ==='); 60 60 obj1.method1(() => { 61 61 obj2.method1(() => { 62 62 return obj2.leaf(); ··· 66 66 }); 67 67 }); 68 68 69 - Ant.println('\n=== Test 3: With helper function calls in arguments ==='); 69 + console.log('\n=== Test 3: With helper function calls in arguments ==='); 70 70 obj1.method1(() => helper1()); 71 71 obj2.method2(() => helper2()); 72 72 73 - Ant.println('\n=== All deep nesting tests passed ==='); 73 + console.log('\n=== All deep nesting tests passed ===');
+1 -1
tests/test_dot.cjs
··· 1 1 const obj = { thing: 42 }; 2 2 const result = obj.thing; 3 - Ant.println(result); 3 + console.log(result);
+41 -41
tests/test_in_operator.cjs
··· 1 1 // Test 'in' operator and for-in loops 2 - Ant.println('=== In Operator and For-In Tests ==='); 2 + console.log('=== In Operator and For-In Tests ==='); 3 3 4 4 // Test 1: Basic 'in' operator with object 5 - Ant.println('\nTest 1: Basic in operator'); 5 + console.log('\nTest 1: Basic in operator'); 6 6 const obj1 = { name: 'test', value: 42, flag: true }; 7 - Ant.println("'name' in obj1: " + ('name' in obj1)); 8 - Ant.println("'value' in obj1: " + ('value' in obj1)); 9 - Ant.println("'missing' in obj1: " + ('missing' in obj1)); 7 + console.log("'name' in obj1: " + ('name' in obj1)); 8 + console.log("'value' in obj1: " + ('value' in obj1)); 9 + console.log("'missing' in obj1: " + ('missing' in obj1)); 10 10 11 11 // Test 2: 'in' operator with arrays 12 - Ant.println('\nTest 2: In operator with arrays'); 12 + console.log('\nTest 2: In operator with arrays'); 13 13 const arr = [10, 20, 30]; 14 - Ant.println("'0' in arr: " + ('0' in arr)); 15 - Ant.println("'1' in arr: " + ('1' in arr)); 16 - Ant.println("'5' in arr: " + ('5' in arr)); 17 - Ant.println("'length' in arr: " + ('length' in arr)); 14 + console.log("'0' in arr: " + ('0' in arr)); 15 + console.log("'1' in arr: " + ('1' in arr)); 16 + console.log("'5' in arr: " + ('5' in arr)); 17 + console.log("'length' in arr: " + ('length' in arr)); 18 18 19 19 // Test 3: Basic for-in loop with object 20 - Ant.println('\nTest 3: For-in loop with object'); 20 + console.log('\nTest 3: For-in loop with object'); 21 21 const obj2 = { a: 1, b: 2, c: 3 }; 22 22 let keys = ''; 23 23 for (let key in obj2) { 24 24 keys = keys + key + ','; 25 25 } 26 - Ant.println('Keys: ' + keys); 26 + console.log('Keys: ' + keys); 27 27 28 28 // Test 4: For-in loop with const 29 - Ant.println('\nTest 4: For-in with const'); 29 + console.log('\nTest 4: For-in with const'); 30 30 const obj3 = { x: 10, y: 20 }; 31 31 for (const prop in obj3) { 32 - Ant.println('Property: ' + prop + ' = ' + obj3[prop]); 32 + console.log('Property: ' + prop + ' = ' + obj3[prop]); 33 33 } 34 34 35 35 // Test 5: For-in loop accumulating values 36 - Ant.println('\nTest 5: For-in accumulating values'); 36 + console.log('\nTest 5: For-in accumulating values'); 37 37 const obj4 = { first: 5, second: 10, third: 15 }; 38 38 let sum = 0; 39 39 for (let k in obj4) { 40 40 sum = sum + obj4[k]; 41 41 } 42 - Ant.println('Sum of values: ' + sum); 42 + console.log('Sum of values: ' + sum); 43 43 44 44 // Test 6: For-in with break 45 - Ant.println('\nTest 6: For-in with break'); 45 + console.log('\nTest 6: For-in with break'); 46 46 const obj5 = { a: 1, b: 2, c: 3, d: 4 }; 47 47 let count = 0; 48 48 for (let key in obj5) { ··· 50 50 if (count === 2) { 51 51 break; 52 52 } 53 - Ant.println('Key: ' + key); 53 + console.log('Key: ' + key); 54 54 } 55 - Ant.println('Stopped at count: ' + count); 55 + console.log('Stopped at count: ' + count); 56 56 57 57 // Test 7: For-in with continue 58 - Ant.println('\nTest 7: For-in with continue'); 58 + console.log('\nTest 7: For-in with continue'); 59 59 const obj6 = { a: 1, b: 2, c: 3, d: 4 }; 60 60 for (let key in obj6) { 61 61 if (key === 'b' || key === 'd') { 62 62 continue; 63 63 } 64 - Ant.println('Processing: ' + key); 64 + console.log('Processing: ' + key); 65 65 } 66 66 67 67 // Test 8: For-in with array 68 - Ant.println('\nTest 8: For-in with array'); 68 + console.log('\nTest 8: For-in with array'); 69 69 const arr2 = ['first', 'second', 'third']; 70 70 for (let idx in arr2) { 71 - Ant.println('Index ' + idx + ': ' + arr2[idx]); 71 + console.log('Index ' + idx + ': ' + arr2[idx]); 72 72 } 73 73 74 74 // Test 9: Nested for-in loops 75 - Ant.println('\nTest 9: Nested for-in loops'); 75 + console.log('\nTest 9: Nested for-in loops'); 76 76 const outer = { a: { x: 1, y: 2 }, b: { x: 3, y: 4 } }; 77 77 for (let key1 in outer) { 78 78 for (let key2 in outer[key1]) { 79 - Ant.println(key1 + '.' + key2 + ' = ' + outer[key1][key2]); 79 + console.log(key1 + '.' + key2 + ' = ' + outer[key1][key2]); 80 80 } 81 81 } 82 82 83 83 // Test 10: In operator with nested properties 84 - Ant.println('\nTest 10: In operator with nested object'); 84 + console.log('\nTest 10: In operator with nested object'); 85 85 const nested = { outer: { inner: 'value' } }; 86 - Ant.println("'outer' in nested: " + ('outer' in nested)); 87 - Ant.println("'inner' in nested: " + ('inner' in nested)); 86 + console.log("'outer' in nested: " + ('outer' in nested)); 87 + console.log("'inner' in nested: " + ('inner' in nested)); 88 88 89 89 // Test 11: For-in counting properties 90 - Ant.println('\nTest 11: Counting properties with for-in'); 90 + console.log('\nTest 11: Counting properties with for-in'); 91 91 const obj7 = { prop1: 'a', prop2: 'b', prop3: 'c', prop4: 'd' }; 92 92 let propCount = 0; 93 93 for (let p in obj7) { 94 94 propCount = propCount + 1; 95 95 } 96 - Ant.println('Property count: ' + propCount); 96 + console.log('Property count: ' + propCount); 97 97 98 98 // Test 12: For-in with empty object 99 - Ant.println('\nTest 12: For-in with empty object'); 99 + console.log('\nTest 12: For-in with empty object'); 100 100 const empty = {}; 101 101 let ranOnce = false; 102 102 for (let k in empty) { 103 103 ranOnce = true; 104 104 } 105 - Ant.println('Loop ran: ' + ranOnce); 105 + console.log('Loop ran: ' + ranOnce); 106 106 107 107 // Test 13: In operator with different types 108 - Ant.println('\nTest 13: In operator checks'); 108 + console.log('\nTest 13: In operator checks'); 109 109 const testObj = { num: 42, str: 'hello', bool: true }; 110 - Ant.println("'num' in testObj: " + ('num' in testObj)); 111 - Ant.println("'str' in testObj: " + ('str' in testObj)); 112 - Ant.println("'bool' in testObj: " + ('bool' in testObj)); 110 + console.log("'num' in testObj: " + ('num' in testObj)); 111 + console.log("'str' in testObj: " + ('str' in testObj)); 112 + console.log("'bool' in testObj: " + ('bool' in testObj)); 113 113 114 114 // Test 14: For-in modifying external variable 115 - Ant.println('\nTest 14: For-in with external variable'); 115 + console.log('\nTest 14: For-in with external variable'); 116 116 const data = { a: 10, b: 20, c: 30 }; 117 117 let total = 0; 118 118 for (let key in data) { 119 119 total = total + data[key]; 120 120 } 121 - Ant.println('Total: ' + total); 121 + console.log('Total: ' + total); 122 122 123 123 // Test 15: For-in with conditional logic 124 - Ant.println('\nTest 15: For-in with conditional'); 124 + console.log('\nTest 15: For-in with conditional'); 125 125 const items = { item1: 5, item2: 15, item3: 25, item4: 35 }; 126 126 let filtered = 0; 127 127 for (let name in items) { ··· 129 129 filtered = filtered + items[name]; 130 130 } 131 131 } 132 - Ant.println('Filtered sum (>10): ' + filtered); 132 + console.log('Filtered sum (>10): ' + filtered); 133 133 134 - Ant.println('\n=== All in operator tests completed ==='); 134 + console.log('\n=== All in operator tests completed ===');
+43 -43
tests/test_loops.cjs
··· 1 1 // Test all loop types: for, while, do-while 2 - Ant.println('=== Loop Tests ==='); 2 + console.log('=== Loop Tests ==='); 3 3 4 4 // Test 1: Basic while loop 5 - Ant.println('\nTest 1: Basic while loop'); 5 + console.log('\nTest 1: Basic while loop'); 6 6 let i = 0; 7 7 let sum = 0; 8 8 while (i < 5) { 9 9 sum = sum + i; 10 10 i = i + 1; 11 11 } 12 - Ant.println('While loop sum (0-4): ' + sum); 12 + console.log('While loop sum (0-4): ' + sum); 13 13 14 14 // Test 2: While loop with break 15 - Ant.println('\nTest 2: While loop with break'); 15 + console.log('\nTest 2: While loop with break'); 16 16 let count = 0; 17 17 while (count < 10) { 18 18 if (count === 5) { ··· 20 20 } 21 21 count = count + 1; 22 22 } 23 - Ant.println('While with break, count: ' + count); 23 + console.log('While with break, count: ' + count); 24 24 25 25 // Test 3: While loop with continue 26 - Ant.println('\nTest 3: While loop with continue'); 26 + console.log('\nTest 3: While loop with continue'); 27 27 let j = 0; 28 28 let evenSum = 0; 29 29 while (j < 10) { ··· 33 33 } 34 34 evenSum = evenSum + j; 35 35 } 36 - Ant.println('Even sum (2,4,6,8,10): ' + evenSum); 36 + console.log('Even sum (2,4,6,8,10): ' + evenSum); 37 37 38 38 // Test 4: Basic do-while loop 39 - Ant.println('\nTest 4: Basic do-while loop'); 39 + console.log('\nTest 4: Basic do-while loop'); 40 40 let k = 0; 41 41 let result = 0; 42 42 do { 43 43 result = result + k; 44 44 k = k + 1; 45 45 } while (k < 5); 46 - Ant.println('Do-while sum (0-4): ' + result); 46 + console.log('Do-while sum (0-4): ' + result); 47 47 48 48 // Test 5: Do-while executes at least once 49 - Ant.println('\nTest 5: Do-while executes at least once'); 49 + console.log('\nTest 5: Do-while executes at least once'); 50 50 let executed = false; 51 51 do { 52 52 executed = true; 53 - Ant.println('Do-while executed even when condition is false'); 53 + console.log('Do-while executed even when condition is false'); 54 54 } while (false); 55 55 56 56 // Test 6: Do-while with break 57 - Ant.println('\nTest 6: Do-while with break'); 57 + console.log('\nTest 6: Do-while with break'); 58 58 let n = 0; 59 59 do { 60 60 n = n + 1; ··· 62 62 break; 63 63 } 64 64 } while (n < 10); 65 - Ant.println('Do-while with break, n: ' + n); 65 + console.log('Do-while with break, n: ' + n); 66 66 67 67 // Test 7: Do-while with continue 68 - Ant.println('\nTest 7: Do-while with continue'); 68 + console.log('\nTest 7: Do-while with continue'); 69 69 let m = 0; 70 70 let oddSum = 0; 71 71 do { ··· 75 75 } 76 76 oddSum = oddSum + m; 77 77 } while (m < 9); 78 - Ant.println('Odd sum (1,3,5,7,9): ' + oddSum); 78 + console.log('Odd sum (1,3,5,7,9): ' + oddSum); 79 79 80 80 // Test 8: For loop basic 81 - Ant.println('\nTest 8: For loop basic'); 81 + console.log('\nTest 8: For loop basic'); 82 82 let forSum = 0; 83 83 for (let x = 0; x < 5; x = x + 1) { 84 84 forSum = forSum + x; 85 85 } 86 - Ant.println('For loop sum (0-4): ' + forSum); 86 + console.log('For loop sum (0-4): ' + forSum); 87 87 88 88 // Test 9: For loop with break 89 - Ant.println('\nTest 9: For loop with break'); 89 + console.log('\nTest 9: For loop with break'); 90 90 let breakCount = 0; 91 91 for (let y = 0; y < 10; y = y + 1) { 92 92 if (y === 5) { ··· 94 94 } 95 95 breakCount = breakCount + 1; 96 96 } 97 - Ant.println('For loop with break, count: ' + breakCount); 97 + console.log('For loop with break, count: ' + breakCount); 98 98 99 99 // Test 10: For loop with continue 100 - Ant.println('\nTest 10: For loop with continue'); 100 + console.log('\nTest 10: For loop with continue'); 101 101 let skipSum = 0; 102 102 for (let z = 0; z < 10; z = z + 1) { 103 103 if (z % 2 === 0) { ··· 105 105 } 106 106 skipSum = skipSum + z; 107 107 } 108 - Ant.println('For loop skip evens (1+3+5+7+9): ' + skipSum); 108 + console.log('For loop skip evens (1+3+5+7+9): ' + skipSum); 109 109 110 110 // Test 11: Nested while loops 111 - Ant.println('\nTest 11: Nested while loops'); 111 + console.log('\nTest 11: Nested while loops'); 112 112 let outer = 0; 113 113 let nestedSum = 0; 114 114 while (outer < 3) { ··· 119 119 } 120 120 outer = outer + 1; 121 121 } 122 - Ant.println('Nested while loops, count: ' + nestedSum); 122 + console.log('Nested while loops, count: ' + nestedSum); 123 123 124 124 // Test 12: Nested for loops 125 - Ant.println('\nTest 12: Nested for loops'); 125 + console.log('\nTest 12: Nested for loops'); 126 126 let product = 0; 127 127 for (let a = 1; a <= 3; a = a + 1) { 128 128 for (let b = 1; b <= 3; b = b + 1) { 129 129 product = a * b; 130 130 } 131 131 } 132 - Ant.println('Last nested for product: ' + product); 132 + console.log('Last nested for product: ' + product); 133 133 134 134 // Test 13: While with complex condition 135 - Ant.println('\nTest 13: While with complex condition'); 135 + console.log('\nTest 13: While with complex condition'); 136 136 let p = 0; 137 137 let q = 10; 138 138 while (p < 5 && q > 5) { 139 139 p = p + 1; 140 140 q = q - 1; 141 141 } 142 - Ant.println('Complex while, p: ' + p + ', q: ' + q); 142 + console.log('Complex while, p: ' + p + ', q: ' + q); 143 143 144 144 // Test 14: For loop with let declaration 145 - Ant.println('\nTest 14: For loop with let'); 145 + console.log('\nTest 14: For loop with let'); 146 146 for (let temp = 0; temp < 3; temp = temp + 1) { 147 - Ant.println('For loop iteration: ' + temp); 147 + console.log('For loop iteration: ' + temp); 148 148 } 149 149 150 150 // Test 15: While loop with single statement 151 - Ant.println('\nTest 15: While with single statement'); 151 + console.log('\nTest 15: While with single statement'); 152 152 let single = 0; 153 153 while (single < 3) single = single + 1; 154 - Ant.println('Single statement while: ' + single); 154 + console.log('Single statement while: ' + single); 155 155 156 156 // Test 16: Do-while with single statement (in block) 157 - Ant.println('\nTest 16: Do-while with single statement'); 157 + console.log('\nTest 16: Do-while with single statement'); 158 158 let singleDo = 0; 159 159 do { singleDo = singleDo + 1; } while (singleDo < 3); 160 - Ant.println('Single statement do-while: ' + singleDo); 160 + console.log('Single statement do-while: ' + singleDo); 161 161 162 162 // Test 17: Empty while loop 163 - Ant.println('\nTest 17: Empty while loop'); 163 + console.log('\nTest 17: Empty while loop'); 164 164 let empty = 5; 165 165 while (empty < 5) { 166 - Ant.println('Should not print'); 166 + console.log('Should not print'); 167 167 } 168 - Ant.println('Empty while executed: no output above'); 168 + console.log('Empty while executed: no output above'); 169 169 170 170 // Test 18: For loop with const 171 - Ant.println('\nTest 18: For loop counting down'); 171 + console.log('\nTest 18: For loop counting down'); 172 172 let countdown = 0; 173 173 for (let val = 5; val > 0; val = val - 1) { 174 174 countdown = countdown + val; 175 175 } 176 - Ant.println('Countdown sum (5+4+3+2+1): ' + countdown); 176 + console.log('Countdown sum (5+4+3+2+1): ' + countdown); 177 177 178 178 // Test 19: While loop with array 179 - Ant.println('\nTest 19: While loop with array'); 179 + console.log('\nTest 19: While loop with array'); 180 180 const arr = [10, 20, 30]; 181 181 let idx = 0; 182 182 let arrSum = 0; ··· 184 184 arrSum = arrSum + arr[idx]; 185 185 idx = idx + 1; 186 186 } 187 - Ant.println('Array sum via while: ' + arrSum); 187 + console.log('Array sum via while: ' + arrSum); 188 188 189 189 // Test 20: Do-while minimal 190 - Ant.println('\nTest 20: Do-while minimal'); 190 + console.log('\nTest 20: Do-while minimal'); 191 191 let minimal = 0; 192 192 do { 193 193 minimal = minimal + 1; 194 194 } while (minimal < 1); 195 - Ant.println('Minimal do-while: ' + minimal); 195 + console.log('Minimal do-while: ' + minimal); 196 196 197 - Ant.println('\n=== All loop tests completed ==='); 197 + console.log('\n=== All loop tests completed ===');
+16 -16
tests/test_not_operator.cjs
··· 1 1 // Test the NOT operator fix 2 2 3 - Ant.println("Test 1 - if (!null) with block:"); 3 + console.log("Test 1 - if (!null) with block:"); 4 4 if (!null) { 5 - Ant.println(" PASS"); 5 + console.log(" PASS"); 6 6 } 7 7 8 - Ant.println("\nTest 2 - if (!undefined) with block:"); 8 + console.log("\nTest 2 - if (!undefined) with block:"); 9 9 if (!undefined) { 10 - Ant.println(" PASS"); 10 + console.log(" PASS"); 11 11 } 12 12 13 - Ant.println("\nTest 3 - if (!false) with block:"); 13 + console.log("\nTest 3 - if (!false) with block:"); 14 14 if (!false) { 15 - Ant.println(" PASS"); 15 + console.log(" PASS"); 16 16 } 17 17 18 - Ant.println("\nTest 4 - if (!0) with block:"); 18 + console.log("\nTest 4 - if (!0) with block:"); 19 19 if (!0) { 20 - Ant.println(" PASS"); 20 + console.log(" PASS"); 21 21 } 22 22 23 - Ant.println("\nTest 5 - if (!'') with block:"); 23 + console.log("\nTest 5 - if (!'') with block:"); 24 24 if (!'') { 25 - Ant.println(" PASS"); 25 + console.log(" PASS"); 26 26 } 27 27 28 28 const x = null; 29 - Ant.println("\nTest 6 - if (!x) return {}:"); 29 + console.log("\nTest 6 - if (!x) return {}:"); 30 30 function test6() { 31 31 if (!x) return {}; 32 32 return { value: "should not reach" }; 33 33 } 34 - Ant.println(" Result:", test6()); 34 + console.log(" Result:", test6()); 35 35 36 - Ant.println("\nTest 7 - if (!handler) return {} from radix3:"); 36 + console.log("\nTest 7 - if (!handler) return {} from radix3:"); 37 37 function lookup(handler) { 38 38 if (!handler) return {}; 39 39 return { handler, params: {} }; 40 40 } 41 - Ant.println(" With null:", lookup(null)); 42 - Ant.println(" With value:", lookup("test")); 41 + console.log(" With null:", lookup(null)); 42 + console.log(" With value:", lookup("test")); 43 43 44 - Ant.println("\nAll tests passed!"); 44 + console.log("\nAll tests passed!");
+1 -1
tests/test_obj_closure.cjs
··· 7 7 } 8 8 }; 9 9 10 - Ant.println(obj.method()); // Should print 100 10 + console.log(obj.method()); // Should print 100
+8 -8
tests/test_optional_chain.cjs
··· 1 1 // Simple test for optional chaining 2 2 3 - Ant.println("Test 1: Basic optional chaining"); 3 + console.log("Test 1: Basic optional chaining"); 4 4 const value = undefined; 5 5 const result = value?.thing; 6 - Ant.println("value?.thing:", result); 6 + console.log("value?.thing:", result); 7 7 8 - Ant.println("\nTest 2: With object"); 8 + console.log("\nTest 2: With object"); 9 9 const obj = { nested: { deep: "value" } }; 10 10 const result2 = obj?.nested?.deep; 11 - Ant.println("obj?.nested?.deep:", result2); 11 + console.log("obj?.nested?.deep:", result2); 12 12 13 - Ant.println("\nTest 3: In if statement"); 13 + console.log("\nTest 3: In if statement"); 14 14 if (value?.thing) { 15 - Ant.println("FAIL"); 15 + console.log("FAIL"); 16 16 } else { 17 - Ant.println("PASS: value?.thing is falsy"); 17 + console.log("PASS: value?.thing is falsy"); 18 18 } 19 19 20 - Ant.println("\nAll tests done"); 20 + console.log("\nAll tests done");
+13 -13
tests/test_promise.cjs
··· 1 - Ant.println('Test 1: Promise Constructor'); 1 + console.log('Test 1: Promise Constructor'); 2 2 let p = new Promise((resolve, reject) => { 3 3 resolve(42); 4 4 }); 5 5 6 - Ant.println('p is Promise: ' + (p instanceof Promise)); 6 + console.log('p is Promise: ' + (p instanceof Promise)); 7 7 8 8 p.then(v => { 9 - Ant.println('Resolved with ' + v); 9 + console.log('Resolved with ' + v); 10 10 }); 11 11 12 - Ant.println('Test 2: Chaining'); 12 + console.log('Test 2: Chaining'); 13 13 let p2 = new Promise(resolve => resolve(10)); 14 14 p2.then(v => { 15 15 return v * 2; 16 16 }).then(v => { 17 - Ant.println('Chained result: ' + v); // Should be 20 17 + console.log('Chained result: ' + v); // Should be 20 18 18 }); 19 19 20 - Ant.println('Test 3: Catch'); 20 + console.log('Test 3: Catch'); 21 21 let p3 = new Promise((_, reject) => reject('error')); 22 22 p3.catch(e => { 23 - Ant.println('Caught: ' + e); 23 + console.log('Caught: ' + e); 24 24 }); 25 25 26 - Ant.println('Test 4: Static resolve'); 26 + console.log('Test 4: Static resolve'); 27 27 Promise.resolve('static').then(v => { 28 - Ant.println('Static resolve: ' + v); 28 + console.log('Static resolve: ' + v); 29 29 }); 30 30 31 - Ant.println('Test 5: Promise.try'); 31 + console.log('Test 5: Promise.try'); 32 32 Promise.try(() => { 33 33 return 'try'; 34 34 }).then(v => { 35 - Ant.println('Try result: ' + v); 35 + console.log('Try result: ' + v); 36 36 }); 37 37 38 - Ant.println('Test 6: Finally'); 38 + console.log('Test 6: Finally'); 39 39 Promise.resolve('fin').finally(() => { 40 - Ant.println('Finally called'); 40 + console.log('Finally called'); 41 41 });
+30 -30
tests/test_promise_display.cjs
··· 1 1 // Test Promise display with various value types 2 - Ant.println('=== Promise Display Test ==='); 2 + console.log('=== Promise Display Test ==='); 3 3 4 4 // Test 1: Number 5 - Ant.println('\nTest 1: Promise with number'); 5 + console.log('\nTest 1: Promise with number'); 6 6 const p1 = Promise.resolve(42); 7 - Ant.println('Promise.resolve(42): ' + p1); 7 + console.log('Promise.resolve(42): ' + p1); 8 8 9 9 // Test 2: String 10 - Ant.println('\nTest 2: Promise with string'); 10 + console.log('\nTest 2: Promise with string'); 11 11 const p2 = Promise.resolve('hello'); 12 - Ant.println('Promise.resolve("hello"): ' + p2); 12 + console.log('Promise.resolve("hello"): ' + p2); 13 13 14 14 // Test 3: Boolean (true) 15 - Ant.println('\nTest 3: Promise with boolean'); 15 + console.log('\nTest 3: Promise with boolean'); 16 16 const p3 = Promise.resolve(true); 17 - Ant.println('Promise.resolve(true): ' + p3); 17 + console.log('Promise.resolve(true): ' + p3); 18 18 19 19 // Test 4: Boolean (false) 20 20 const p4 = Promise.resolve(false); 21 - Ant.println('Promise.resolve(false): ' + p4); 21 + console.log('Promise.resolve(false): ' + p4); 22 22 23 23 // Test 5: Null 24 - Ant.println('\nTest 5: Promise with null'); 24 + console.log('\nTest 5: Promise with null'); 25 25 const p5 = Promise.resolve(null); 26 - Ant.println('Promise.resolve(null): ' + p5); 26 + console.log('Promise.resolve(null): ' + p5); 27 27 28 28 // Test 6: Undefined 29 - Ant.println('\nTest 6: Promise with undefined'); 29 + console.log('\nTest 6: Promise with undefined'); 30 30 const p6 = Promise.resolve(undefined); 31 - Ant.println('Promise.resolve(undefined): ' + p6); 31 + console.log('Promise.resolve(undefined): ' + p6); 32 32 33 33 // Test 7: Object 34 - Ant.println('\nTest 7: Promise with object'); 34 + console.log('\nTest 7: Promise with object'); 35 35 const p7 = Promise.resolve({ x: 1, y: 2 }); 36 - Ant.println('Promise.resolve({x:1,y:2}): ' + p7); 36 + console.log('Promise.resolve({x:1,y:2}): ' + p7); 37 37 38 38 // Test 8: Array 39 - Ant.println('\nTest 8: Promise with array'); 39 + console.log('\nTest 8: Promise with array'); 40 40 const p8 = Promise.resolve([1, 2, 3]); 41 - Ant.println('Promise.resolve([1,2,3]): ' + p8); 41 + console.log('Promise.resolve([1,2,3]): ' + p8); 42 42 43 43 // Test 9: Rejected promise 44 - Ant.println('\nTest 9: Rejected promise'); 44 + console.log('\nTest 9: Rejected promise'); 45 45 const p9 = Promise.reject('error message'); 46 - Ant.println('Promise.reject("error message"): ' + p9); 46 + console.log('Promise.reject("error message"): ' + p9); 47 47 48 48 // Test 10: Pending promise 49 - Ant.println('\nTest 10: Pending promise'); 49 + console.log('\nTest 10: Pending promise'); 50 50 const p10 = new Promise((resolve) => { 51 51 Ant.setTimeout(() => { 52 52 resolve(100); 53 - Ant.println('After timeout, promise is: ' + p10); 53 + console.log('After timeout, promise is: ' + p10); 54 54 }, 100); 55 55 }); 56 - Ant.println('Before timeout, promise is: ' + p10); 56 + console.log('Before timeout, promise is: ' + p10); 57 57 58 58 // Test 11: Async function result 59 - Ant.println('\nTest 11: Async function result'); 59 + console.log('\nTest 11: Async function result'); 60 60 async function getValue() { 61 61 return 999; 62 62 } 63 63 const p11 = getValue(); 64 - Ant.println('Async function returned: ' + p11); 64 + console.log('Async function returned: ' + p11); 65 65 66 66 // Test 12: Async function with object 67 - Ant.println('\nTest 12: Async function with object'); 67 + console.log('\nTest 12: Async function with object'); 68 68 async function getObject() { 69 69 return { value: 42, name: 'test' }; 70 70 } 71 71 const p12 = getObject(); 72 - Ant.println('Async object function: ' + p12); 72 + console.log('Async object function: ' + p12); 73 73 74 74 // Test 13: Async function with array 75 - Ant.println('\nTest 13: Async function with array'); 75 + console.log('\nTest 13: Async function with array'); 76 76 async function getArray() { 77 77 return [10, 20, 30]; 78 78 } 79 79 const p13 = getArray(); 80 - Ant.println('Async array function: ' + p13); 80 + console.log('Async array function: ' + p13); 81 81 82 82 // Test 14: Promise chaining visibility 83 - Ant.println('\nTest 14: Promise in then handler'); 83 + console.log('\nTest 14: Promise in then handler'); 84 84 Promise.resolve(5).then(v => { 85 85 const inner = Promise.resolve(v * 2); 86 - Ant.println('Inner promise: ' + inner); 86 + console.log('Inner promise: ' + inner); 87 87 return inner; 88 88 }); 89 89 90 - Ant.println('\n=== Synchronous code finished ==='); 90 + console.log('\n=== Synchronous code finished ===');
+9 -9
tests/test_regexp_basic.cjs
··· 1 1 // Test basic RegExp constructor 2 2 const re1 = new RegExp('hello'); 3 - Ant.println('RegExp created:', re1.source); 4 - Ant.println('Flags:', re1.flags); 5 - Ant.println('Global:', re1.global); 3 + console.log('RegExp created:', re1.source); 4 + console.log('Flags:', re1.flags); 5 + console.log('Global:', re1.global); 6 6 7 7 // Test with flags 8 8 const re2 = new RegExp('test', 'g'); 9 - Ant.println('Global flag set:', re2.global); 10 - Ant.println('Flags:', re2.flags); 9 + console.log('Global flag set:', re2.global); 10 + console.log('Flags:', re2.flags); 11 11 12 12 // Test multiple flags 13 13 const re3 = new RegExp('pattern', 'gi'); 14 - Ant.println('Multiple flags:', re3.flags); 15 - Ant.println('Global:', re3.global); 16 - Ant.println('IgnoreCase:', re3.ignoreCase); 14 + console.log('Multiple flags:', re3.flags); 15 + console.log('Global:', re3.global); 16 + console.log('IgnoreCase:', re3.ignoreCase); 17 17 18 - Ant.println('All basic RegExp tests passed!'); 18 + console.log('All basic RegExp tests passed!');
+8 -8
tests/test_regexp_edge_cases.cjs
··· 2 2 3 3 // Empty pattern 4 4 const re1 = new RegExp(''); 5 - Ant.println('Empty pattern source:', re1.source); 5 + console.log('Empty pattern source:', re1.source); 6 6 7 7 // Empty string replacement 8 8 const str1 = 'hello'; 9 9 const result1 = str1.replace(new RegExp('l', 'g'), ''); 10 - Ant.println('Remove chars:', result1); 10 + console.log('Remove chars:', result1); 11 11 12 12 // No match 13 13 const str2 = 'hello world'; 14 14 const result2 = str2.replace(new RegExp('xyz'), 'foo'); 15 - Ant.println('No match:', result2); 15 + console.log('No match:', result2); 16 16 17 17 // Special characters that need escaping 18 18 const str3 = 'Price: $10.99'; 19 19 const re3 = new RegExp('[0-9.]+'); 20 20 const result3 = str3.replace(re3, '20.00'); 21 - Ant.println('Price replace:', result3); 21 + console.log('Price replace:', result3); 22 22 23 23 // Whitespace replacement 24 24 const str4 = 'hello world'; 25 25 const re4 = new RegExp(' +', 'g'); 26 26 const result4 = str4.replace(re4, ' '); 27 - Ant.println('Normalize spaces:', result4); 27 + console.log('Normalize spaces:', result4); 28 28 29 29 // Replace at start 30 30 const str5 = 'hello world'; 31 31 const re5 = new RegExp('^hello'); 32 32 const result5 = str5.replace(re5, 'hi'); 33 - Ant.println('Replace at start:', result5); 33 + console.log('Replace at start:', result5); 34 34 35 35 // Replace at end 36 36 const str6 = 'hello world'; 37 37 const re6 = new RegExp('world$'); 38 38 const result6 = str6.replace(re6, 'there'); 39 - Ant.println('Replace at end:', result6); 39 + console.log('Replace at end:', result6); 40 40 41 - Ant.println('All edge case tests passed!'); 41 + console.log('All edge case tests passed!');
+8 -8
tests/test_regexp_patterns.cjs
··· 4 4 const str1 = 'The quick brown fox'; 5 5 const re1 = new RegExp('quick', 'g'); 6 6 const result1 = str1.replace(re1, 'slow'); 7 - Ant.println('Word replace:', result1); 7 + console.log('Word replace:', result1); 8 8 9 9 // Test character classes 10 10 const str2 = 'a1b2c3'; 11 11 const re2 = new RegExp('[0-9]', 'g'); 12 12 const result2 = str2.replace(re2, 'X'); 13 - Ant.println('Digit replace:', result2); 13 + console.log('Digit replace:', result2); 14 14 15 15 // Test alternation 16 16 const str3 = 'I like cats and dogs'; 17 17 const re3 = new RegExp('cats', 'g'); 18 18 const result3 = str3.replace(re3, 'birds'); 19 - Ant.println('Alternation:', result3); 19 + console.log('Alternation:', result3); 20 20 21 21 // Test start of line 22 22 const str4 = 'hello world\nhello there'; 23 23 const re4 = new RegExp('hello', 'g'); 24 24 const result4 = str4.replace(re4, 'hi'); 25 - Ant.println('Multiple hello:', result4); 25 + console.log('Multiple hello:', result4); 26 26 27 27 // Test any character 28 28 const str5 = 'abc def ghi'; 29 29 const re5 = new RegExp('d.f'); 30 30 const result5 = str5.replace(re5, 'XXX'); 31 - Ant.println('Any char:', result5); 31 + console.log('Any char:', result5); 32 32 33 33 // Test quantifiers 34 34 const str6 = 'aaaa bb c'; 35 35 const re6 = new RegExp('a+', 'g'); 36 36 const result6 = str6.replace(re6, 'X'); 37 - Ant.println('Quantifier +:', result6); 37 + console.log('Quantifier +:', result6); 38 38 39 39 const str7 = 'aaaa bb c'; 40 40 const re7 = new RegExp('a*', 'g'); 41 41 const result7 = str7.replace(re7, 'X'); 42 - Ant.println('Quantifier *:', result7); 42 + console.log('Quantifier *:', result7); 43 43 44 - Ant.println('All pattern tests passed!'); 44 + console.log('All pattern tests passed!');
+15 -15
tests/test_rest_params.cjs
··· 9 9 return total; 10 10 } 11 11 12 - Ant.println("Test 1 - Basic rest params:"); 13 - Ant.println(sum(1, 2, 3, 4, 5)); // Should print 15 12 + console.log("Test 1 - Basic rest params:"); 13 + console.log(sum(1, 2, 3, 4, 5)); // Should print 15 14 14 15 15 // Test 2: Rest parameter with regular parameters 16 16 function greet(greeting, ...names) { ··· 21 21 return result; 22 22 } 23 23 24 - Ant.println("\nTest 2 - Rest params with regular params:"); 25 - Ant.println(greet("Hello", "Alice", "Bob", "Charlie")); // Should print "Hello Alice Bob Charlie" 24 + console.log("\nTest 2 - Rest params with regular params:"); 25 + console.log(greet("Hello", "Alice", "Bob", "Charlie")); // Should print "Hello Alice Bob Charlie" 26 26 27 27 // Test 3: Rest parameter with no arguments passed 28 28 function noArgs(...args) { 29 29 return args.length; 30 30 } 31 31 32 - Ant.println("\nTest 3 - Rest params with no args:"); 33 - Ant.println(noArgs()); // Should print 0 32 + console.log("\nTest 3 - Rest params with no args:"); 33 + console.log(noArgs()); // Should print 0 34 34 35 35 // Test 4: Rest parameter with single argument 36 36 function singleArg(...args) { 37 37 return args[0]; 38 38 } 39 39 40 - Ant.println("\nTest 4 - Rest params with single arg:"); 41 - Ant.println(singleArg(42)); // Should print 42 40 + console.log("\nTest 4 - Rest params with single arg:"); 41 + console.log(singleArg(42)); // Should print 42 42 42 43 43 // Test 5: Arrow function with rest parameters 44 44 const multiply = (...factors) => { ··· 49 49 return result; 50 50 }; 51 51 52 - Ant.println("\nTest 5 - Arrow function with rest params:"); 53 - Ant.println(multiply(2, 3, 4)); // Should print 24 52 + console.log("\nTest 5 - Arrow function with rest params:"); 53 + console.log(multiply(2, 3, 4)); // Should print 24 54 54 55 55 // Test 6: Multiple regular params with rest 56 56 function compute(operation, initial, ...values) { ··· 68 68 return result; 69 69 } 70 70 71 - Ant.println("\nTest 6 - Multiple params with rest:"); 72 - Ant.println(compute("add", 10, 5, 3, 2)); // Should print 20 73 - Ant.println(compute("multiply", 2, 3, 4)); // Should print 24 71 + console.log("\nTest 6 - Multiple params with rest:"); 72 + console.log(compute("add", 10, 5, 3, 2)); // Should print 20 73 + console.log(compute("multiply", 2, 3, 4)); // Should print 24 74 74 75 75 // Test 7: Rest parameter is an actual array 76 76 function checkArray(...items) { 77 77 return items.length; 78 78 } 79 79 80 - Ant.println("\nTest 7 - Rest param is array:"); 81 - Ant.println(checkArray("a", "b", "c", "d")); // Should print 4 80 + console.log("\nTest 7 - Rest param is array:"); 81 + console.log(checkArray("a", "b", "c", "d")); // Should print 4
+12 -12
tests/test_return.cjs
··· 2 2 3 3 class Test { 4 4 method1(x) { 5 - Ant.println("Method1: x =", x); 5 + console.log("Method1: x =", x); 6 6 if (x > 5) { 7 - Ant.println("Returning early"); 7 + console.log("Returning early"); 8 8 return; 9 9 } 10 - Ant.println("After if block"); 10 + console.log("After if block"); 11 11 } 12 12 13 13 method2(x) { 14 - Ant.println("Method2: x =", x); 14 + console.log("Method2: x =", x); 15 15 if (x > 5) { 16 - Ant.println("Returning early with value"); 16 + console.log("Returning early with value"); 17 17 return "early"; 18 18 } 19 - Ant.println("After if block"); 19 + console.log("After if block"); 20 20 return "normal"; 21 21 } 22 22 } 23 23 24 24 let t = new Test(); 25 25 26 - Ant.println("Test 1:"); 26 + console.log("Test 1:"); 27 27 t.method1(3); 28 28 29 - Ant.println("\nTest 2:"); 29 + console.log("\nTest 2:"); 30 30 t.method1(7); 31 31 32 - Ant.println("\nTest 3:"); 32 + console.log("\nTest 3:"); 33 33 let r1 = t.method2(3); 34 - Ant.println("Returned:", r1); 34 + console.log("Returned:", r1); 35 35 36 - Ant.println("\nTest 4:"); 36 + console.log("\nTest 4:"); 37 37 let r2 = t.method2(7); 38 - Ant.println("Returned:", r2); 38 + console.log("Returned:", r2);
+11 -11
tests/test_shadowing.cjs
··· 2 2 let x = "outer"; 3 3 { 4 4 let x = "inner"; 5 - Ant.println(x); // Should print "inner" 5 + console.log(x); // Should print "inner" 6 6 } 7 - Ant.println(x); // Should print "outer" 7 + console.log(x); // Should print "outer" 8 8 9 9 // Test 2: Closure capturing outer scope 10 10 let y = 10; ··· 16 16 }; 17 17 } 18 18 let counter = makeCounter(); 19 - Ant.println(counter()); // Should print 11 20 - Ant.println(counter()); // Should print 12 19 + console.log(counter()); // Should print 11 20 + console.log(counter()); // Should print 12 21 21 22 22 // Test 3: Variable shadowing in function 23 23 let z = "global"; ··· 25 25 let z = "local"; 26 26 return z; 27 27 } 28 - Ant.println(testShadow()); // Should print "local" 29 - Ant.println(z); // Should print "global" 28 + console.log(testShadow()); // Should print "local" 29 + console.log(z); // Should print "global" 30 30 31 31 // Test 4: Nested function closures 32 32 function outer() { ··· 41 41 } 42 42 return middle(); 43 43 } 44 - Ant.println(outer()); // Should print 6 44 + console.log(outer()); // Should print 6 45 45 46 46 // Test 5: Multiple closures sharing same outer scope 47 47 function makeCounters() { ··· 53 53 }; 54 54 } 55 55 let counters = makeCounters(); 56 - Ant.println(counters.inc()); // Should print 1 57 - Ant.println(counters.inc()); // Should print 2 58 - Ant.println(counters.dec()); // Should print 1 59 - Ant.println(counters.get()); // Should print 1 56 + console.log(counters.inc()); // Should print 1 57 + console.log(counters.inc()); // Should print 2 58 + console.log(counters.dec()); // Should print 1 59 + console.log(counters.get()); // Should print 1
+10 -10
tests/test_stack_depth.cjs
··· 7 7 8 8 // Regular method that calls another with function arg 9 9 methodA(getArg) { 10 - Ant.println('methodA: this.name = ' + this.name); 10 + console.log('methodA: this.name = ' + this.name); 11 11 return this.methodB(getArg()); 12 12 } 13 13 14 14 methodB(arg) { 15 - Ant.println('methodB: this.name = ' + this.name + ', arg = ' + arg); 15 + console.log('methodB: this.name = ' + this.name + ', arg = ' + arg); 16 16 return this.name + ':' + arg; 17 17 } 18 18 19 19 // Method that returns a promise 20 20 asyncMethod() { 21 - Ant.println('asyncMethod: this.name = ' + this.name); 21 + console.log('asyncMethod: this.name = ' + this.name); 22 22 return Promise.resolve(this.name); 23 23 } 24 24 } ··· 30 30 const obj1 = new StackTest('obj1'); 31 31 const obj2 = new StackTest('obj2'); 32 32 33 - Ant.println('=== Test 1: Synchronous nested calls ==='); 33 + console.log('=== Test 1: Synchronous nested calls ==='); 34 34 const result1 = obj1.methodA(() => helperFunc()); 35 - Ant.println('Result: ' + result1); 35 + console.log('Result: ' + result1); 36 36 37 - Ant.println('\n=== Test 2: Async then sync ==='); 37 + console.log('\n=== Test 2: Async then sync ==='); 38 38 obj1.asyncMethod().then((val) => { 39 - Ant.println('In .then(), val = ' + val); 39 + console.log('In .then(), val = ' + val); 40 40 // Now do a sync call with function arg 41 41 const result = obj2.methodA(() => 'fromPromise'); 42 - Ant.println('After sync call: ' + result); 42 + console.log('After sync call: ' + result); 43 43 }); 44 44 45 - Ant.println('\n=== Test 3: Multiple objects interleaved ==='); 45 + console.log('\n=== Test 3: Multiple objects interleaved ==='); 46 46 obj1.methodA(() => { 47 47 obj2.methodB('nested'); 48 48 return 'test'; 49 49 }); 50 50 51 - Ant.println('\n=== All tests done ==='); 51 + console.log('\n=== All tests done ===');
+7 -7
tests/test_string_replace_regex.cjs
··· 4 4 const str1 = 'hello world'; 5 5 const re1 = new RegExp('world'); 6 6 const result1 = str1.replace(re1, 'universe'); 7 - Ant.println('Basic replace:', result1); 7 + console.log('Basic replace:', result1); 8 8 9 9 // Test with global flag 10 10 const str2 = 'foo bar foo baz'; 11 11 const re2 = new RegExp('foo', 'g'); 12 12 const result2 = str2.replace(re2, 'qux'); 13 - Ant.println('Global replace:', result2); 13 + console.log('Global replace:', result2); 14 14 15 15 // Test without global flag (should replace only first) 16 16 const str3 = 'foo bar foo baz'; 17 17 const re3 = new RegExp('foo'); 18 18 const result3 = str3.replace(re3, 'qux'); 19 - Ant.println('Non-global replace:', result3); 19 + console.log('Non-global replace:', result3); 20 20 21 21 // Test with regex pattern (digits) 22 22 const str4 = 'I have 2 apples and 3 oranges'; 23 23 const re4 = new RegExp('[0-9]+', 'g'); 24 24 const result4 = str4.replace(re4, 'X'); 25 - Ant.println('Replace digits:', result4); 25 + console.log('Replace digits:', result4); 26 26 27 27 // Test with dot pattern 28 28 const str5 = 'abc123def'; 29 29 const re5 = new RegExp('...', 'g'); 30 30 const result5 = str5.replace(re5, 'X'); 31 - Ant.println('Replace with dot:', result5); 31 + console.log('Replace with dot:', result5); 32 32 33 33 // Test string replace (without regex) - should still work 34 34 const str6 = 'hello world'; 35 35 const result6 = str6.replace('world', 'there'); 36 - Ant.println('String replace:', result6); 36 + console.log('String replace:', result6); 37 37 38 - Ant.println('All replace tests passed!'); 38 + console.log('All replace tests passed!');
+6 -6
tests/test_throw_stack.cjs
··· 1 1 // Test throw statement with stack traces 2 - Ant.println('=== Throw with Stack Trace Test ==='); 2 + console.log('=== Throw with Stack Trace Test ==='); 3 3 4 4 function level3() { 5 - Ant.println('In level3'); 5 + console.log('In level3'); 6 6 throw "error from level3"; 7 7 } 8 8 9 9 function level2() { 10 - Ant.println('In level2'); 10 + console.log('In level2'); 11 11 level3(); 12 12 } 13 13 14 14 function level1() { 15 - Ant.println('In level1'); 15 + console.log('In level1'); 16 16 level2(); 17 17 } 18 18 19 - Ant.println('Starting test...'); 19 + console.log('Starting test...'); 20 20 level1(); 21 - Ant.println('This should not print'); 21 + console.log('This should not print');
+10 -10
tests/test_timers.cjs
··· 1 1 // Test setTimeout 2 - Ant.println('Starting timer tests...'); 2 + console.log('Starting timer tests...'); 3 3 4 4 Ant.setTimeout(() => { 5 - Ant.println('setTimeout executed after 1000ms'); 5 + console.log('setTimeout executed after 1000ms'); 6 6 }, 1000); 7 7 8 8 Ant.setTimeout(() => { 9 - Ant.println('setTimeout executed after 500ms'); 9 + console.log('setTimeout executed after 500ms'); 10 10 }, 500); 11 11 12 12 // Test queueMicrotask 13 13 Ant.queueMicrotask(() => { 14 - Ant.println('Microtask 1 executed'); 14 + console.log('Microtask 1 executed'); 15 15 }); 16 16 17 17 Ant.queueMicrotask(() => { 18 - Ant.println('Microtask 2 executed'); 18 + console.log('Microtask 2 executed'); 19 19 }); 20 20 21 - Ant.println('Synchronous code finished'); 21 + console.log('Synchronous code finished'); 22 22 23 23 // Test setInterval 24 24 let count = 0; 25 25 const intervalId = Ant.setInterval(() => { 26 26 count++; 27 - Ant.println('Interval execution #' + count); 27 + console.log('Interval execution #' + count); 28 28 29 29 if (count >= 3) { 30 30 Ant.clearInterval(intervalId); 31 - Ant.println('Interval cleared after 3 executions'); 31 + console.log('Interval cleared after 3 executions'); 32 32 } 33 33 }, 200); 34 34 35 35 // Test clearTimeout 36 36 const timeoutId = Ant.setTimeout(() => { 37 - Ant.println('This should NOT be printed'); 37 + console.log('This should NOT be printed'); 38 38 }, 300); 39 39 40 40 Ant.clearTimeout(timeoutId); 41 - Ant.println('Timeout cleared before execution'); 41 + console.log('Timeout cleared before execution');
+25 -25
tests/test_var.cjs
··· 1 1 // Test var keyword (should work like let but show warnings) 2 - Ant.println('=== Var Keyword Tests ==='); 2 + console.log('=== Var Keyword Tests ==='); 3 3 4 4 // Test 1: Basic var declaration 5 - Ant.println('\nTest 1: Basic var declaration'); 5 + console.log('\nTest 1: Basic var declaration'); 6 6 var x = 10; 7 - Ant.println('var x = 10: ' + x); 7 + console.log('var x = 10: ' + x); 8 8 9 9 // Test 2: Var reassignment 10 - Ant.println('\nTest 2: Var reassignment'); 10 + console.log('\nTest 2: Var reassignment'); 11 11 var y = 5; 12 12 y = y + 10; 13 - Ant.println('var y reassigned: ' + y); 13 + console.log('var y reassigned: ' + y); 14 14 15 15 // Test 3: Var in for loop 16 - Ant.println('\nTest 3: Var in for loop'); 16 + console.log('\nTest 3: Var in for loop'); 17 17 var sum = 0; 18 18 for (var i = 0; i < 5; i = i + 1) { 19 19 sum = sum + i; 20 20 } 21 - Ant.println('Sum with var: ' + sum); 21 + console.log('Sum with var: ' + sum); 22 22 23 23 // Test 4: Var in for-in loop 24 - Ant.println('\nTest 4: Var in for-in loop'); 24 + console.log('\nTest 4: Var in for-in loop'); 25 25 const obj = { a: 1, b: 2, c: 3 }; 26 26 var keys = ''; 27 27 for (var key in obj) { 28 28 keys = keys + key + ','; 29 29 } 30 - Ant.println('Keys with var: ' + keys); 30 + console.log('Keys with var: ' + keys); 31 31 32 32 // Test 5: Multiple var declarations 33 - Ant.println('\nTest 5: Multiple var declarations'); 33 + console.log('\nTest 5: Multiple var declarations'); 34 34 var a = 1, b = 2, c = 3; 35 - Ant.println('var a, b, c: ' + (a + b + c)); 35 + console.log('var a, b, c: ' + (a + b + c)); 36 36 37 37 // Test 6: Var in while loop 38 - Ant.println('\nTest 6: Var in while loop'); 38 + console.log('\nTest 6: Var in while loop'); 39 39 var count = 0; 40 40 while (count < 3) { 41 41 count = count + 1; 42 42 } 43 - Ant.println('While with var: ' + count); 43 + console.log('While with var: ' + count); 44 44 45 45 // Test 7: Var with objects 46 - Ant.println('\nTest 7: Var with objects'); 46 + console.log('\nTest 7: Var with objects'); 47 47 var obj2 = { name: 'test', value: 42 }; 48 - Ant.println('var object: ' + obj2.name + ' = ' + obj2.value); 48 + console.log('var object: ' + obj2.name + ' = ' + obj2.value); 49 49 50 50 // Test 8: Var with arrays 51 - Ant.println('\nTest 8: Var with arrays'); 51 + console.log('\nTest 8: Var with arrays'); 52 52 var arr = [10, 20, 30]; 53 - Ant.println('var array[1]: ' + arr[1]); 53 + console.log('var array[1]: ' + arr[1]); 54 54 55 55 // Test 9: Var in nested scopes 56 - Ant.println('\nTest 9: Var in nested scopes'); 56 + console.log('\nTest 9: Var in nested scopes'); 57 57 var outer = 'outer'; 58 58 if (true) { 59 59 var inner = 'inner'; 60 - Ant.println('Inner var: ' + inner); 60 + console.log('Inner var: ' + inner); 61 61 } 62 - Ant.println('Outer var: ' + outer); 62 + console.log('Outer var: ' + outer); 63 63 64 64 // Test 10: Var works like let 65 - Ant.println('\nTest 10: Var behavior like let'); 65 + console.log('\nTest 10: Var behavior like let'); 66 66 var testVar = 100; 67 67 if (testVar > 50) { 68 68 var modified = testVar * 2; 69 - Ant.println('Modified: ' + modified); 69 + console.log('Modified: ' + modified); 70 70 } 71 - Ant.println('Original: ' + testVar); 71 + console.log('Original: ' + testVar); 72 72 73 - Ant.println('\n=== All var tests completed ==='); 74 - Ant.println('Note: You should see deprecation warnings above'); 73 + console.log('\n=== All var tests completed ==='); 74 + console.log('Note: You should see deprecation warnings above');
+31 -31
tests/test_void_operator.cjs
··· 1 1 // Test void operator with promises and async functions 2 - Ant.println('=== Void Operator Tests ==='); 2 + console.log('=== Void Operator Tests ==='); 3 3 4 4 // Test 1: void with async function (fire and forget) 5 - Ant.println('\nTest 1: void with async function'); 5 + console.log('\nTest 1: void with async function'); 6 6 async function asyncTask() { 7 - Ant.println('Async task executing'); 7 + console.log('Async task executing'); 8 8 return 'task result'; 9 9 } 10 10 11 11 // Using void indicates we don't care about the result/promise 12 12 void asyncTask(); 13 - Ant.println('After void async call'); 13 + console.log('After void async call'); 14 14 15 15 // Test 2: void with Promise.resolve 16 - Ant.println('\nTest 2: void with Promise.resolve'); 17 - void Promise.resolve(42).then(v => Ant.println('Promise resolved with: ' + v)); 18 - Ant.println('After void Promise.resolve'); 16 + console.log('\nTest 2: void with Promise.resolve'); 17 + void Promise.resolve(42).then(v => console.log('Promise resolved with: ' + v)); 18 + console.log('After void Promise.resolve'); 19 19 20 20 // Test 3: void with regular function call 21 - Ant.println('\nTest 3: void with regular function'); 21 + console.log('\nTest 3: void with regular function'); 22 22 function regularFunc() { 23 - Ant.println('Regular function called'); 23 + console.log('Regular function called'); 24 24 return 'regular result'; 25 25 } 26 26 const result = void regularFunc(); 27 - Ant.println('Result of void is: ' + result); 27 + console.log('Result of void is: ' + result); 28 28 29 29 // Test 4: void in expression 30 - Ant.println('\nTest 4: void in expression'); 30 + console.log('\nTest 4: void in expression'); 31 31 const x = 10; 32 32 const y = void x; 33 - Ant.println('void x where x=10 is: ' + y); 33 + console.log('void x where x=10 is: ' + y); 34 34 35 35 // Test 5: void with multiple expressions 36 - Ant.println('\nTest 5: void prevents await'); 36 + console.log('\nTest 5: void prevents await'); 37 37 async function noAwait() { 38 38 // void means we explicitly don't want to await this 39 39 void Promise.resolve('not awaited'); 40 - Ant.println('Continued without awaiting'); 40 + console.log('Continued without awaiting'); 41 41 return 'done'; 42 42 } 43 - noAwait().then(v => Ant.println('noAwait returned: ' + v)); 43 + noAwait().then(v => console.log('noAwait returned: ' + v)); 44 44 45 45 // Test 6: void vs await comparison 46 - Ant.println('\nTest 6: void vs await comparison'); 46 + console.log('\nTest 6: void vs await comparison'); 47 47 async function withAwait() { 48 48 const result = await Promise.resolve('awaited value'); 49 - Ant.println('With await: ' + result); 49 + console.log('With await: ' + result); 50 50 return result; 51 51 } 52 52 53 53 async function withVoid() { 54 54 void Promise.resolve('void value'); 55 - Ant.println('With void: undefined (not waiting)'); 55 + console.log('With void: undefined (not waiting)'); 56 56 return 'immediate return'; 57 57 } 58 58 59 - withAwait().then(v => Ant.println('withAwait result: ' + v)); 60 - withVoid().then(v => Ant.println('withVoid result: ' + v)); 59 + withAwait().then(v => console.log('withAwait result: ' + v)); 60 + withVoid().then(v => console.log('withVoid result: ' + v)); 61 61 62 62 // Test 7: void with chained promise (fire and forget) 63 - Ant.println('\nTest 7: void with promise chain'); 63 + console.log('\nTest 7: void with promise chain'); 64 64 void Promise.resolve(1) 65 65 .then(v => v + 1) 66 66 .then(v => v + 1) 67 - .then(v => Ant.println('Chained promise result: ' + v)); 68 - Ant.println('Promise chain started but not awaited'); 67 + .then(v => console.log('Chained promise result: ' + v)); 68 + console.log('Promise chain started but not awaited'); 69 69 70 70 // Test 8: void return value 71 - Ant.println('\nTest 8: void always returns undefined'); 71 + console.log('\nTest 8: void always returns undefined'); 72 72 function returnVoid() { 73 73 return void 100; 74 74 } 75 75 const voidResult = returnVoid(); 76 - Ant.println('Function returning void 100: ' + voidResult); 76 + console.log('Function returning void 100: ' + voidResult); 77 77 78 78 // Test 9: void with function expression 79 - Ant.println('\nTest 9: void with function expression'); 79 + console.log('\nTest 9: void with function expression'); 80 80 void function() { 81 - Ant.println('IIFE with void executed'); 81 + console.log('IIFE with void executed'); 82 82 }(); 83 83 84 84 // Test 10: void indicating intentional non-handling 85 - Ant.println('\nTest 10: void for intentional non-handling'); 85 + console.log('\nTest 10: void for intentional non-handling'); 86 86 async function backgroundTask() { 87 87 return await Promise.resolve('background work done'); 88 88 } ··· 90 90 async function mainTask() { 91 91 // void explicitly shows we don't want to wait for backgroundTask 92 92 void backgroundTask(); 93 - Ant.println('Main task continues immediately'); 93 + console.log('Main task continues immediately'); 94 94 return 'main done'; 95 95 } 96 96 97 - mainTask().then(v => Ant.println('mainTask result: ' + v)); 97 + mainTask().then(v => console.log('mainTask result: ' + v)); 98 98 99 - Ant.println('\n=== Synchronous code finished ==='); 99 + console.log('\n=== Synchronous code finished ===');
+59 -59
tests/this_demo.cjs
··· 1 1 // Demonstration of 'this' keyword and 'new' operator 2 2 3 - Ant.println("=== Constructor Functions with 'new' and 'this' ===\n"); 3 + console.log("=== Constructor Functions with 'new' and 'this' ===\n"); 4 4 5 5 // Basic constructor function 6 6 function Person(name, age) { ··· 12 12 } 13 13 14 14 // Create instances using 'new' 15 - Ant.println("Creating person1 with new Person('Alice', 30)"); 15 + console.log("Creating person1 with new Person('Alice', 30)"); 16 16 let person1 = new Person("Alice", 30); 17 - Ant.println("person1.name:", person1.name); 18 - Ant.println("person1.age:", person1.age); 19 - Ant.println("person1.greet():", person1.greet()); 20 - Ant.println(); 17 + console.log("person1.name:", person1.name); 18 + console.log("person1.age:", person1.age); 19 + console.log("person1.greet():", person1.greet()); 20 + console.log(); 21 21 22 - Ant.println("Creating person2 with new Person('Bob', 25)"); 22 + console.log("Creating person2 with new Person('Bob', 25)"); 23 23 let person2 = new Person("Bob", 25); 24 - Ant.println("person2.name:", person2.name); 25 - Ant.println("person2.age:", person2.age); 26 - Ant.println("person2.greet():", person2.greet()); 27 - Ant.println(); 24 + console.log("person2.name:", person2.name); 25 + console.log("person2.age:", person2.age); 26 + console.log("person2.greet():", person2.greet()); 27 + console.log(); 28 28 29 29 // Each instance has its own 'this' context 30 - Ant.println("=== Independent 'this' contexts ==="); 31 - Ant.println("person1.name:", person1.name); 32 - Ant.println("person2.name:", person2.name); 33 - Ant.println("They are different instances with independent 'this' values"); 34 - Ant.println(); 30 + console.log("=== Independent 'this' contexts ==="); 31 + console.log("person1.name:", person1.name); 32 + console.log("person2.name:", person2.name); 33 + console.log("They are different instances with independent 'this' values"); 34 + console.log(); 35 35 36 36 // Constructor with methods that use 'this' 37 37 function Counter(start) { ··· 49 49 }; 50 50 } 51 51 52 - Ant.println("=== Counter Example ==="); 52 + console.log("=== Counter Example ==="); 53 53 let counter = new Counter(10); 54 - Ant.println("Initial value:", counter.getValue()); 55 - Ant.println("After increment:", counter.increment()); 56 - Ant.println("After increment:", counter.increment()); 57 - Ant.println("After decrement:", counter.decrement()); 58 - Ant.println("Final value:", counter.getValue()); 59 - Ant.println(); 54 + console.log("Initial value:", counter.getValue()); 55 + console.log("After increment:", counter.increment()); 56 + console.log("After increment:", counter.increment()); 57 + console.log("After decrement:", counter.decrement()); 58 + console.log("Final value:", counter.getValue()); 59 + console.log(); 60 60 61 61 // Multiple counters with independent state 62 - Ant.println("=== Multiple Independent Counters ==="); 62 + console.log("=== Multiple Independent Counters ==="); 63 63 let counter1 = new Counter(0); 64 64 let counter2 = new Counter(100); 65 65 66 - Ant.println("counter1 initial:", counter1.getValue()); 67 - Ant.println("counter2 initial:", counter2.getValue()); 66 + console.log("counter1 initial:", counter1.getValue()); 67 + console.log("counter2 initial:", counter2.getValue()); 68 68 69 69 counter1.increment(); 70 70 counter1.increment(); 71 71 counter2.decrement(); 72 72 73 - Ant.println("counter1 after 2 increments:", counter1.getValue()); 74 - Ant.println("counter2 after 1 decrement:", counter2.getValue()); 75 - Ant.println(); 73 + console.log("counter1 after 2 increments:", counter1.getValue()); 74 + console.log("counter2 after 1 decrement:", counter2.getValue()); 75 + console.log(); 76 76 77 77 // Constructor with computed properties 78 78 function Rectangle(width, height) { ··· 86 86 }; 87 87 } 88 88 89 - Ant.println("=== Rectangle Example ==="); 89 + console.log("=== Rectangle Example ==="); 90 90 let rect1 = new Rectangle(5, 10); 91 - Ant.println("Rectangle 5x10:"); 92 - Ant.println(" Width:", rect1.width); 93 - Ant.println(" Height:", rect1.height); 94 - Ant.println(" Area:", rect1.area()); 95 - Ant.println(" Perimeter:", rect1.perimeter()); 96 - Ant.println(); 91 + console.log("Rectangle 5x10:"); 92 + console.log(" Width:", rect1.width); 93 + console.log(" Height:", rect1.height); 94 + console.log(" Area:", rect1.area()); 95 + console.log(" Perimeter:", rect1.perimeter()); 96 + console.log(); 97 97 98 98 let rect2 = new Rectangle(3, 7); 99 - Ant.println("Rectangle 3x7:"); 100 - Ant.println(" Width:", rect2.width); 101 - Ant.println(" Height:", rect2.height); 102 - Ant.println(" Area:", rect2.area()); 103 - Ant.println(" Perimeter:", rect2.perimeter()); 104 - Ant.println(); 99 + console.log("Rectangle 3x7:"); 100 + console.log(" Width:", rect2.width); 101 + console.log(" Height:", rect2.height); 102 + console.log(" Area:", rect2.area()); 103 + console.log(" Perimeter:", rect2.perimeter()); 104 + console.log(); 105 105 106 106 // 'this' refers to the object being constructed 107 107 function Car(make, model, year) { ··· 113 113 }; 114 114 } 115 115 116 - Ant.println("=== Car Example ==="); 116 + console.log("=== Car Example ==="); 117 117 let car1 = new Car("Toyota", "Camry", 2020); 118 118 let car2 = new Car("Honda", "Civic", 2021); 119 119 120 - Ant.println("car1:", car1.displayInfo()); 121 - Ant.println("car2:", car2.displayInfo()); 122 - Ant.println(); 120 + console.log("car1:", car1.displayInfo()); 121 + console.log("car2:", car2.displayInfo()); 122 + console.log(); 123 123 124 124 // 'this' in nested functions 125 125 function Account(owner, balance) { ··· 141 141 }; 142 142 } 143 143 144 - Ant.println("=== Bank Account Example ==="); 144 + console.log("=== Bank Account Example ==="); 145 145 let account1 = new Account("Alice", 1000); 146 - Ant.println("Initial:", account1.getInfo()); 146 + console.log("Initial:", account1.getInfo()); 147 147 148 148 account1.deposit(500); 149 - Ant.println("After deposit 500:", account1.getInfo()); 149 + console.log("After deposit 500:", account1.getInfo()); 150 150 151 151 account1.withdraw(200); 152 - Ant.println("After withdraw 200:", account1.getInfo()); 153 - Ant.println(); 152 + console.log("After withdraw 200:", account1.getInfo()); 153 + console.log(); 154 154 155 155 // Multiple accounts 156 156 let account2 = new Account("Bob", 2000); 157 - Ant.println("account1:", account1.getInfo()); 158 - Ant.println("account2:", account2.getInfo()); 159 - Ant.println(); 157 + console.log("account1:", account1.getInfo()); 158 + console.log("account2:", account2.getInfo()); 159 + console.log(); 160 160 161 - Ant.println("=== Summary ==="); 162 - Ant.println("- 'new' creates a new object"); 163 - Ant.println("- 'this' inside constructor refers to the new object"); 164 - Ant.println("- Each instance has its own 'this' context"); 165 - Ant.println("- Methods can access and modify 'this' properties"); 161 + console.log("=== Summary ==="); 162 + console.log("- 'new' creates a new object"); 163 + console.log("- 'this' inside constructor refers to the new object"); 164 + console.log("- Each instance has its own 'this' context"); 165 + console.log("- Methods can access and modify 'this' properties");
+1 -1
tests/throw.cjs
··· 10 10 } 11 11 12 12 meow(); 13 - Ant.println('This should not print'); 13 + console.log('This should not print');
+2 -2
tests/uuid.cjs
··· 36 36 ); 37 37 } 38 38 39 - Ant.println('builtin:', Ant.Crypto.randomUUID()); 40 - Ant.println('engine:', generateUUID()); 39 + console.log('builtin:', Ant.Crypto.randomUUID()); 40 + console.log('engine:', generateUUID());
+29 -29
tests/uuidv7.cjs
··· 55 55 } 56 56 57 57 // Test 1: Generate and validate format 58 - Ant.println('Test 1: Basic UUIDv7 generation'); 58 + console.log('Test 1: Basic UUIDv7 generation'); 59 59 const uuid1 = Ant.Crypto.randomUUIDv7(); 60 - Ant.println('Generated:', uuid1); 61 - Ant.println('Valid format:', validateUUIDv7Format(uuid1) ? 'PASS' : 'FAIL'); 62 - Ant.println('Length:', uuid1.length === 36 ? 'PASS' : 'FAIL'); 63 - Ant.println(''); 60 + console.log('Generated:', uuid1); 61 + console.log('Valid format:', validateUUIDv7Format(uuid1) ? 'PASS' : 'FAIL'); 62 + console.log('Length:', uuid1.length === 36 ? 'PASS' : 'FAIL'); 63 + console.log(''); 64 64 65 65 // Test 2: Uniqueness - generate multiple UUIDs 66 - Ant.println('Test 2: Uniqueness check'); 66 + console.log('Test 2: Uniqueness check'); 67 67 const uuids = []; 68 68 const count = 100; 69 69 for (let i = 0; i < count; i++) { ··· 75 75 for (let j = i + 1; j < count; j++) { 76 76 if (uuids[i] === uuids[j]) { 77 77 allUnique = false; 78 - Ant.println('Collision found:', uuids[i]); 78 + console.log('Collision found:', uuids[i]); 79 79 break; 80 80 } 81 81 } 82 82 if (!allUnique) break; 83 83 } 84 - Ant.println('Generated', count, 'unique UUIDs:', allUnique ? 'PASS' : 'FAIL'); 85 - Ant.println(''); 84 + console.log('Generated', count, 'unique UUIDs:', allUnique ? 'PASS' : 'FAIL'); 85 + console.log(''); 86 86 87 87 // Test 3: Timestamp ordering 88 - Ant.println('Test 3: Timestamp ordering'); 88 + console.log('Test 3: Timestamp ordering'); 89 89 const uuid2 = Ant.Crypto.randomUUIDv7(); 90 90 const uuid3 = Ant.Crypto.randomUUIDv7(); 91 91 92 92 const ts2 = extractTimestamp(uuid2); 93 93 const ts3 = extractTimestamp(uuid3); 94 94 95 - Ant.println('UUID 1:', uuid2); 96 - Ant.println('Timestamp 1:', ts2); 97 - Ant.println('UUID 2:', uuid3); 98 - Ant.println('Timestamp 2:', ts3); 99 - Ant.println('Chronologically ordered:', ts3 >= ts2 ? 'PASS' : 'FAIL'); 100 - Ant.println(''); 95 + console.log('UUID 1:', uuid2); 96 + console.log('Timestamp 1:', ts2); 97 + console.log('UUID 2:', uuid3); 98 + console.log('Timestamp 2:', ts3); 99 + console.log('Chronologically ordered:', ts3 >= ts2 ? 'PASS' : 'FAIL'); 100 + console.log(''); 101 101 102 102 // Test 4: Version and variant bits 103 - Ant.println('Test 4: Version and variant validation'); 103 + console.log('Test 4: Version and variant validation'); 104 104 const testUuid = Ant.Crypto.randomUUIDv7(); 105 105 const parts = testUuid.split('-'); 106 106 107 107 // Check version (4 bits at position 48-51, should be 0111 = 7) 108 108 const versionChar = parts[2][0]; 109 - Ant.println('Version character:', versionChar); 110 - Ant.println('Version is 7:', versionChar === '7' ? 'PASS' : 'FAIL'); 109 + console.log('Version character:', versionChar); 110 + console.log('Version is 7:', versionChar === '7' ? 'PASS' : 'FAIL'); 111 111 112 112 // Check variant (2 bits at position 64-65, should be 10) 113 113 const variantChar = parts[3][0]; 114 114 const variantValid = variantChar === '8' || variantChar === '9' || 115 115 variantChar === 'a' || variantChar === 'b'; 116 - Ant.println('Variant character:', variantChar); 117 - Ant.println('Variant is RFC 4122:', variantValid ? 'PASS' : 'FAIL'); 118 - Ant.println(''); 116 + console.log('Variant character:', variantChar); 117 + console.log('Variant is RFC 4122:', variantValid ? 'PASS' : 'FAIL'); 118 + console.log(''); 119 119 120 120 // Test 5: Timestamp reasonableness 121 - Ant.println('Test 5: Timestamp reasonableness'); 121 + console.log('Test 5: Timestamp reasonableness'); 122 122 const currentUuid = Ant.Crypto.randomUUIDv7(); 123 123 const currentTs = extractTimestamp(currentUuid); 124 124 ··· 126 126 const ts2020 = 1577836800000; // 2020-01-01 in ms 127 127 const ts2100 = 4102444800000; // 2100-01-01 in ms 128 128 129 - Ant.println('Extracted timestamp:', currentTs, 'ms'); 130 - Ant.println('After 2020:', currentTs > ts2020 ? 'PASS' : 'FAIL'); 131 - Ant.println('Before 2100:', currentTs < ts2100 ? 'PASS' : 'FAIL'); 132 - Ant.println(''); 129 + console.log('Extracted timestamp:', currentTs, 'ms'); 130 + console.log('After 2020:', currentTs > ts2020 ? 'PASS' : 'FAIL'); 131 + console.log('Before 2100:', currentTs < ts2100 ? 'PASS' : 'FAIL'); 132 + console.log(''); 133 133 134 134 // Test 6: Display multiple UUIDs 135 - Ant.println('Test 6: Sample UUIDv7s'); 135 + console.log('Test 6: Sample UUIDv7s'); 136 136 for (let i = 0; i < 5; i++) { 137 - Ant.println(i + 1 + ':', Ant.Crypto.randomUUIDv7()); 137 + console.log(i + 1 + ':', Ant.Crypto.randomUUIDv7()); 138 138 }