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