diff options
Diffstat (limited to 'js/scripting-lang/scratch_tests')
107 files changed, 3001 insertions, 0 deletions
diff --git a/js/scripting-lang/scratch_tests/dev_01_simple_test.txt b/js/scripting-lang/scratch_tests/dev_01_simple_test.txt new file mode 100644 index 0000000..74edad2 --- /dev/null +++ b/js/scripting-lang/scratch_tests/dev_01_simple_test.txt @@ -0,0 +1,9 @@ +/* Simple test for function call parsing */ + +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +result : factorial 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/dev_02_test_parser_changes.txt b/js/scripting-lang/scratch_tests/dev_02_test_parser_changes.txt new file mode 100644 index 0000000..a4af8bb --- /dev/null +++ b/js/scripting-lang/scratch_tests/dev_02_test_parser_changes.txt @@ -0,0 +1,35 @@ +/* Test: Parser Changes */ +/* Tests: Operator expressions are now translated to combinator calls */ + +/* Test arithmetic operations */ +result1 : 3 + 4; +result2 : 10 - 3; +result3 : 5 * 6; +result4 : 20 / 4; +result5 : -7; + +..out result1; +..out result2; +..out result3; +..out result4; +..out result5; + +/* Test comparison operations */ +test1 : 5 = 5; +test2 : 3 != 7; +test3 : 2 < 8; +test4 : 10 > 3; + +..out test1; +..out test2; +..out test3; +..out test4; + +/* Test logical operations */ +logic1 : true and true; +logic2 : false or true; +logic3 : not false; + +..out logic1; +..out logic2; +..out logic3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/fac.txt b/js/scripting-lang/scratch_tests/fac.txt new file mode 100644 index 0000000..a94f8e1 --- /dev/null +++ b/js/scripting-lang/scratch_tests/fac.txt @@ -0,0 +1,8 @@ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +/* Using factorial */ +..out factorial 5; /* Output: 120 */ +..out factorial 0; /* Output: 1 */ diff --git a/js/scripting-lang/scratch_tests/test_abs.txt b/js/scripting-lang/scratch_tests/test_abs.txt new file mode 100644 index 0000000..c83d644 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_abs.txt @@ -0,0 +1,10 @@ +/* Test abs function */ +abs : x -> when x is + x < 0 then -x + _ then x; + +result1 : abs -5; +result2 : abs 5; + +..out result1; +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_abs_fixed.txt b/js/scripting-lang/scratch_tests/test_abs_fixed.txt new file mode 100644 index 0000000..57e226d --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_abs_fixed.txt @@ -0,0 +1,19 @@ +/* Test that abs -5 now works correctly */ +/* This was the original issue from PARSER_BUG_ANALYSIS.md */ + +x : 5; +abs : x -> when x is + x < 0 then -x + _ then x; + +/* Test 1: Function call with negative literal - THIS SHOULD WORK NOW */ +result1 : abs -5; /* Should be apply(abs, negate(5)) = 5 */ + +/* Test 2: Function call with negative variable - THIS SHOULD WORK NOW */ +result2 : abs -x; /* Should be apply(abs, negate(x)) = 5 */ + +/* Test 3: Function call with parenthesized negative expression - THIS SHOULD WORK NOW */ +result3 : abs (-x); /* Should be apply(abs, negate(x)) = 5 */ + +/* Test 4: Complex expression with negative argument - THIS SHOULD WORK NOW */ +result4 : abs -5 + 10; /* Should be add(apply(abs, negate(5)), 10) = 15 */ \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_alternative_syntax.txt b/js/scripting-lang/scratch_tests/test_alternative_syntax.txt new file mode 100644 index 0000000..94b25cf --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_alternative_syntax.txt @@ -0,0 +1,18 @@ +/* Test alternative syntax for -5 + 3 */ + +/* Original (failing) */ +test1 : -5 + 3; + +/* Alternative 1: Parenthesized */ +test2 : (-5) + 3; + +/* Alternative 2: Using negate function */ +test3 : negate 5 + 3; + +/* Alternative 3: Using subtract */ +test4 : 0 - 5 + 3; + +..out test1; +..out test2; +..out test3; +..out test4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_alternatives_only.txt b/js/scripting-lang/scratch_tests/test_alternatives_only.txt new file mode 100644 index 0000000..17406ad --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_alternatives_only.txt @@ -0,0 +1,14 @@ +/* Test alternative syntaxes only */ + +/* Alternative 1: Parenthesized */ +test2 : (-5) + 3; + +/* Alternative 2: Using negate function */ +test3 : negate 5 + 3; + +/* Alternative 3: Using subtract */ +test4 : 0 - 5 + 3; + +..out test2; +..out test3; +..out test4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_at_operator.txt b/js/scripting-lang/scratch_tests/test_at_operator.txt new file mode 100644 index 0000000..bd663bd --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_at_operator.txt @@ -0,0 +1,21 @@ +/* Test the @ operator for function references */ + +f : x -> x * 2; +g : x -> x + 1; + +/* Test 1: Function reference in when expression */ +abs : x -> when x is + x < 0 then -x + _ then x; + +/* Test 2: Using @ operator to reference a function */ +result1 : @f 5; /* Should be apply(f, 5) = 10 */ + +/* Test 3: Function reference in when expression */ +test : x -> when x is + @f then "f was called" + @g then "g was called" + _ then "neither"; + +/* Test 4: Function reference as argument */ +result2 : @f; /* Should return the function f itself */ \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_backward_compatibility.txt b/js/scripting-lang/scratch_tests/test_backward_compatibility.txt new file mode 100644 index 0000000..787423f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_backward_compatibility.txt @@ -0,0 +1,21 @@ +/* Test backward compatibility */ + +x : 5; +f : x -> x * 2; +g : x -> x + 1; + +/* All these should work exactly as before */ +result1 : x + 5; +..out result1; + +result2 : f x; +..out result2; + +result3 : f (g x); +..out result3; + +result4 : -x; +..out result4; + +result5 : not true; +..out result5; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_boolean_keys.txt b/js/scripting-lang/scratch_tests/test_boolean_keys.txt new file mode 100644 index 0000000..85b3f6a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_boolean_keys.txt @@ -0,0 +1,7 @@ +/* Test table literals with boolean keys */ +bool_table : { + true: "yes", + false: "no" +}; + +..out "bool_table created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_case_debug.txt b/js/scripting-lang/scratch_tests/test_case_debug.txt new file mode 100644 index 0000000..6345e16 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_case_debug.txt @@ -0,0 +1,9 @@ +/* Minimal test to debug case expressions */ +grade : score -> + when score is + 90 then "A" + 80 then "B" + _ then "F"; + +result : grade 95; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_combinator_solution.txt b/js/scripting-lang/scratch_tests/test_combinator_solution.txt new file mode 100644 index 0000000..cc806a0 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_combinator_solution.txt @@ -0,0 +1,22 @@ +/* Test our combinator solution */ +x : 5; +y : (x); /* Should be identity(x) = 5 */ +z : (x - 1); /* Should be subtract(x, 1) = 4 */ +f : x -> x * 2; +result1 : f x; /* Should be apply(f, x) = 10 */ +result2 : (f x); /* Should be identity(apply(f, x)) = 10 */ + +/* Test recursive function */ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +result3 : factorial 3; + +/* Print results */ +..out y; +..out z; +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_comparison_functions.txt b/js/scripting-lang/scratch_tests/test_comparison_functions.txt new file mode 100644 index 0000000..d3f673a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_comparison_functions.txt @@ -0,0 +1,17 @@ +/* Test comparison functions */ + +/* Test greaterThan */ +gt_1 : greaterThan 5 3; +gt_2 : greaterThan 3 5; +gt_3 : greaterThan 3 3; +..assert gt_1 = true; +..assert gt_2 = false; +..assert gt_3 = false; + +/* Test equals */ +eq_1 : equals 5 5; +eq_2 : equals 5 3; +..assert eq_1 = true; +..assert eq_2 = false; + +..out "Comparison functions test completed"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_complex_negate.txt b/js/scripting-lang/scratch_tests/test_complex_negate.txt new file mode 100644 index 0000000..60f858f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_complex_negate.txt @@ -0,0 +1,28 @@ +/* Test complex unary minus scenarios */ +x : 5; +y : 3; + +/* Test nested unary minus */ +z1 : -(-5); /* negate(negate(5)) = 5 */ +z2 : -(-x); /* negate(negate(x)) = 5 */ + +/* Test unary minus with expressions */ +z3 : -(x + y); /* negate(add(x, y)) = -8 */ +z4 : -x + y; /* add(negate(x), y) = -2 */ + +/* Test unary minus with function calls */ +f : x -> x * 2; +z5 : -f x; /* negate(apply(f, x)) = -10 */ + +/* Test edge cases */ +z6 : -0; /* negate(0) = 0 */ +z7 : -(-0); /* negate(negate(0)) = 0 */ + +/* Output results */ +..out z1; +..out z2; +..out z3; +..out z4; +..out z5; +..out z6; +..out z7; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_compose_debug.txt b/js/scripting-lang/scratch_tests/test_compose_debug.txt new file mode 100644 index 0000000..e4e0f4d --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_compose_debug.txt @@ -0,0 +1,15 @@ +/* Debug compose function */ + +f : x -> x * 2; +g : x -> x + 1; + +/* Test individual functions */ +result1 : f 5; +result2 : g 5; +..out result1; +..out result2; + +/* Test composition */ +composed : compose(f, g); +result3 : composed 5; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_compose_debug_detailed.txt b/js/scripting-lang/scratch_tests/test_compose_debug_detailed.txt new file mode 100644 index 0000000..1dd80d7 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_compose_debug_detailed.txt @@ -0,0 +1,22 @@ +/* Debug compose function in detail */ + +/* Create simple functions */ +double : x -> x * 2; +add1 : x -> x + 1; + +/* Test individual functions */ +test1 : double 5; +test2 : add1 5; +..out test1; +..out test2; + +/* Test composition step by step */ +step1 : add1 5; +step2 : double step1; +..out step1; +..out step2; + +/* Test compose function */ +composed : compose(double, add1); +result : composed 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_compose_direct.txt b/js/scripting-lang/scratch_tests/test_compose_direct.txt new file mode 100644 index 0000000..103ed46 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_compose_direct.txt @@ -0,0 +1,9 @@ +/* Test compose function directly */ + +f : x -> x * 2; +g : x -> x + 1; + +/* Test compose function directly */ +composed : compose(f, g); +result : composed 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_compose_order.txt b/js/scripting-lang/scratch_tests/test_compose_order.txt new file mode 100644 index 0000000..2866a6d --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_compose_order.txt @@ -0,0 +1,12 @@ +/* Test compose function order */ + +/* Create functions that show the order */ +first : x -> x * 10; +second : x -> x + 1; + +/* Test composition */ +composed : compose(first, second); +result : composed 5; +..out result; + +/* Expected: first(second(5)) = first(6) = 60 */ \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_composition.txt b/js/scripting-lang/scratch_tests/test_composition.txt new file mode 100644 index 0000000..8f52414 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_composition.txt @@ -0,0 +1,4 @@ +double : x -> x * 2 +triple : x -> x * 3 +composed : double via triple 5; +..out composed; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_composition_debug.txt b/js/scripting-lang/scratch_tests/test_composition_debug.txt new file mode 100644 index 0000000..fd5e052 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_composition_debug.txt @@ -0,0 +1,16 @@ +/* Test function composition with multiple functions */ +f1 : x -> x + 1; +f2 : x -> x * 2; +f3 : x -> x - 1; +f4 : x -> x / 2; + +composed1 : compose @f1 (compose @f2 (compose @f3 @f4)) 10; +composed2 : pipe @f4 (pipe @f3 (pipe @f2 @f1)) 10; + +..out "composed1 = "; +..out composed1; +..out "composed2 = "; +..out composed2; + +..assert composed1 = 9; +..assert composed2 = 10.5; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_composition_implementation.txt b/js/scripting-lang/scratch_tests/test_composition_implementation.txt new file mode 100644 index 0000000..a50065c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_composition_implementation.txt @@ -0,0 +1,34 @@ +/* Test function composition implementation */ + +f : x -> x * 2; +g : x -> x + 1; +h : x -> x * x; + +/* Test 1: Basic composition */ +result1 : f via g 5; /* Should be compose(f, g)(5) = f(g(5)) = f(6) = 12 */ + +/* Test 2: Multiple composition */ +result2 : f via g via h 3; /* Should be compose(f, compose(g, h))(3) = f(g(h(3))) = f(g(9)) = f(10) = 20 */ + +/* Test 3: Function references */ +result3 : @f; /* Should return the function f */ + +/* Test 4: Function reference in composition */ +result4 : @f via @g 5; /* Should be compose(f, g)(5) = 12 */ + +/* Test 5: Pipe function */ +result5 : pipe(f, g) 5; /* Should be g(f(5)) = g(10) = 11 */ + +/* Test 6: Backward compatibility */ +result6 : f 5; /* Should still work: apply(f, 5) = 10 */ +result7 : f g 5; /* Should still work: apply(apply(f, g), 5) - may fail as expected */ + +/* Test 7: Natural language examples */ +data : {1, 2, 3, 4, 5}; +result8 : data via filter via map via reduce; /* Pipeline example */ + +/* Test 8: Enhanced compose with multiple functions */ +result9 : compose(f, g, h) 2; /* Should be f(g(h(2))) = f(g(4)) = f(5) = 10 */ + +/* Test 9: Enhanced pipe with multiple functions */ +result10 : pipe(h, g, f) 2; /* Should be f(g(h(2))) = f(g(4)) = f(5) = 10 */ \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_composition_working.txt b/js/scripting-lang/scratch_tests/test_composition_working.txt new file mode 100644 index 0000000..5ec1d4c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_composition_working.txt @@ -0,0 +1,33 @@ +/* Test working composition features */ + +f : x -> x * 2; +g : x -> x + 1; +h : x -> x * x; + +/* Test 1: Basic composition */ +result1 : f via g 5; +..out result1; + +/* Test 2: Multiple composition */ +result2 : f via g via h 3; +..out result2; + +/* Test 3: Function references */ +result3 : @f; +..out result3; + +/* Test 4: Function reference in composition */ +result4 : @f via @g 5; +..out result4; + +/* Test 5: Pipe function */ +result5 : pipe(f, g) 5; +..out result5; + +/* Test 6: Enhanced compose with multiple functions */ +result6 : compose(f, g, h) 2; +..out result6; + +/* Test 7: Enhanced pipe with multiple functions */ +result7 : pipe(h, g, f) 2; +..out result7; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_current_tables.txt b/js/scripting-lang/scratch_tests/test_current_tables.txt new file mode 100644 index 0000000..e3a64a5 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_current_tables.txt @@ -0,0 +1,33 @@ +/* Test current table behavior before implementing enhancements */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; +person : {name: "Alice", age: 30, active: true}; + +/* Test current map behavior */ +double : x -> x * 2; +doubled : map @double numbers; +/* Expected: 10 (applies to last value only) */ + +/* Test current filter behavior */ +isEven : x -> x % 2 == 0; +even_result : filter @isEven numbers; +/* Expected: 0 (filter returns 0 for false) */ + +/* Test current reduce behavior */ +sum : x y -> x + y; +total : reduce @sum 0 numbers; +/* Expected: 5 (reduces with last value only) */ + +/* Output results */ +..out "Current table behavior:"; +..out "Numbers:"; +..out numbers; +..out "Person:"; +..out person; +..out "Map result:"; +..out doubled; +..out "Filter result:"; +..out even_result; +..out "Reduce result:"; +..out total; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_curry.txt b/js/scripting-lang/scratch_tests/test_curry.txt new file mode 100644 index 0000000..f3b3661 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_curry.txt @@ -0,0 +1,5 @@ +/* Curry test */ + +add_func : x y -> x + y; +curried : curry @add_func 3 4; +..out curried; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_arrow.txt b/js/scripting-lang/scratch_tests/test_debug_arrow.txt new file mode 100644 index 0000000..050bf18 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_arrow.txt @@ -0,0 +1,26 @@ +/* Debug test for arrow functions */ + +// Test 1: Regular arrow function assignment +add_func : x y -> x + y; + +// Test 2: Arrow function in table +calculator : { + add: x y -> x + y +}; + +// Test 3: Just the table creation +table_only : { + name: "test", + add: x y -> x + y +}; + +// Output tests +..out "=== DEBUG ARROW FUNCTIONS ==="; + +..out "Regular function:"; +result1 : add_func 5 3; +..out result1; + +..out "Table function:"; +result2 : calculator.add 5 3; +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_composition.txt b/js/scripting-lang/scratch_tests/test_debug_composition.txt new file mode 100644 index 0000000..24947fc --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_composition.txt @@ -0,0 +1,7 @@ +/* Debug composition parsing */ + +f : x -> x * 2; +g : x -> x + 1; + +/* Test basic composition */ +result : f via g 5; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_t_map.txt b/js/scripting-lang/scratch_tests/test_debug_t_map.txt new file mode 100644 index 0000000..f8ec8a9 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_t_map.txt @@ -0,0 +1,21 @@ +/* Debug test for t.map */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; + +/* Test direct function call */ +double : x -> x * 2; + +/* Test t.map step by step */ +step1 : t.map; +step2 : step1 @double; +step3 : step2 numbers; + +/* Output results */ +..out "=== DEBUG T.MAP ==="; +..out "Step 1 (t.map):"; +..out step1; +..out "Step 2 (t.map @double):"; +..out step2; +..out "Step 3 (result numbers):"; +..out step3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_table.txt b/js/scripting-lang/scratch_tests/test_debug_table.txt new file mode 100644 index 0000000..4306a4c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_table.txt @@ -0,0 +1,11 @@ +/* Debug table function parsing */ + +// Test with debug output +table : { + func: x -> x, + value: 42 +}; + +// Just try to access the value first +..out "=== DEBUG TABLE ==="; +..out table.value; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_dot_notation.txt b/js/scripting-lang/scratch_tests/test_dot_notation.txt new file mode 100644 index 0000000..47f7b65 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_dot_notation.txt @@ -0,0 +1,12 @@ +/* Test dot notation parsing */ + +/* Basic table creation */ +numbers : {1, 2, 3}; + +/* Test simple dot access */ +t_access : t.map; + +/* Output results */ +..out "=== DOT NOTATION TEST ==="; +..out "t.map access:"; +..out t_access; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_combinator.txt b/js/scripting-lang/scratch_tests/test_each_combinator.txt new file mode 100644 index 0000000..487b0f0 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_combinator.txt @@ -0,0 +1,59 @@ +/* Test each combinator for APL-style element-wise operations */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; + +/* Test each with no tables (backward compatibility) */ +normal_add : each @add 5 3; +/* Expected: 8 */ + +/* Test each with single table */ +double : x -> x * 2; +each_result : each @double numbers; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */ + +/* Test each with mixed table and scalar */ +mixed_operation : each @add numbers 10; +/* Expected: {1: 11, 2: 12, 3: 13, 4: 14, 5: 15} */ + +/* Test each with multiple tables */ +multi_table_sum : each @add table1 table2; +/* Expected: {a: 11, b: 22, c: 33} */ + +/* Test each with three arguments using composition */ +add_100 : x -> add x 100; +triple_sum : each @add_100 table1; +/* Expected: {a: 101, b: 102, c: 103} */ + +/* Test nested table operations */ +nested : { + data: {a: 1, b: 2, c: 3}, + meta: {type: "numbers", count: 3} +}; + +/* Top-level only (nested tables unchanged) */ +top_level_only : each @double nested; +/* Expected: {data: {a: 1, b: 2, c: 3}, meta: {type: "numbers", count: 3}} */ + +/* Nested operations with explicit composition */ +nested_doubled : each (each @double) nested; +/* Expected: {data: {a: 2, b: 4, c: 6}, meta: {type: "numbers", count: 3}} */ + +/* Output results */ +..out "=== EACH COMBINATOR TESTS ==="; +..out "Normal add (no tables):"; +..out normal_add; +..out "Each with single table:"; +..out each_result; +..out "Each with mixed table and scalar:"; +..out mixed_operation; +..out "Each with multiple tables:"; +..out multi_table_sum; +..out "Each with three arguments using composition:"; +..out triple_sum; +..out "Top-level only (nested):"; +..out top_level_only; +..out "Nested with explicit composition:"; +..out nested_doubled; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_comprehensive.txt b/js/scripting-lang/scratch_tests/test_each_comprehensive.txt new file mode 100644 index 0000000..abcb74f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_comprehensive.txt @@ -0,0 +1,43 @@ +/* Comprehensive test for each combinator */ + +numbers : {1, 2, 3, 4, 5}; +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; + +/* Test 1: each with table and scalar */ +result1 : each @add numbers 10; +..out "Test 1 - each with table and scalar:"; +..out result1; + +/* Test 2: each with two tables */ +result2 : each @add table1 table2; +..out "Test 2 - each with two tables:"; +..out result2; + +/* Test 3: each with scalar and table */ +result3 : each @add 10 numbers; +..out "Test 3 - each with scalar and table:"; +..out result3; + +/* Test 4: each with partial application */ +add_to_ten : each @add 10; +result4 : add_to_ten numbers; +..out "Test 4 - each with partial application:"; +..out result4; + +/* Test 5: each with different operations */ +result5 : each @multiply numbers 2; +..out "Test 5 - each with multiply:"; +..out result5; + +/* Test 6: each with comparison */ +result6 : each @greaterThan numbers 3; +..out "Test 6 - each with comparison:"; +..out result6; + +/* Test 7: each with nested tables */ +nested1 : {data: {x: 1, y: 2}, meta: {type: "point"}}; +nested2 : {data: {x: 10, y: 20}, meta: {type: "point"}}; +result7 : each @add nested1 nested2; +..out "Test 7 - each with nested tables:"; +..out result7; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_debug.txt b/js/scripting-lang/scratch_tests/test_each_debug.txt new file mode 100644 index 0000000..98bcac4 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_debug.txt @@ -0,0 +1,28 @@ +/* Debug test for each combinator */ + +/* Test basic each usage */ +numbers : {1, 2, 3, 4, 5}; +add_ten : x -> x + 10; + +/* Test 1: each with single table */ +result1 : each @add_ten numbers; +..out "Test 1 - each with single table:"; +..out result1; + +/* Test 2: each with table and scalar */ +result2 : each @add numbers 10; +..out "Test 2 - each with table and scalar:"; +..out result2; + +/* Test 3: each with two tables */ +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; +result3 : each @add table1 table2; +..out "Test 3 - each with two tables:"; +..out result3; + +/* Test 4: each with partial application */ +add_to_ten : each @add 10; +result4 : add_to_ten numbers; +..out "Test 4 - each with partial application:"; +..out result4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_parsing.txt b/js/scripting-lang/scratch_tests/test_each_parsing.txt new file mode 100644 index 0000000..59ba27c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_parsing.txt @@ -0,0 +1,27 @@ +/* Test to understand each parsing behavior */ + +numbers : {1, 2, 3, 4, 5}; +add_ten : x -> x + 10; + +/* Test 1: each with single table - should work like map */ +result1 : each @add_ten numbers; +..out "Test 1 - each with single table:"; +..out result1; + +/* Test 2: each with table and scalar - should work */ +result2 : each @add numbers 10; +..out "Test 2 - each with table and scalar:"; +..out result2; + +/* Test 3: each with two tables - should work */ +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; +result3 : each @add table1 table2; +..out "Test 3 - each with two tables:"; +..out result3; + +/* Test 4: each with partial application - should work */ +add_to_ten : each @add 10; +result4 : add_to_ten numbers; +..out "Test 4 - each with partial application:"; +..out result4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_simple.txt b/js/scripting-lang/scratch_tests/test_each_simple.txt new file mode 100644 index 0000000..45c941a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_simple.txt @@ -0,0 +1,22 @@ +/* Simple each test */ + +numbers : {1, 2, 3, 4, 5}; + +/* each with table and scalar */ +each_add : each @add numbers 10; +each_1 : each_add[1]; +each_2 : each_add[2]; +each_3 : each_add[3]; +..assert each_1 = 11; +..assert each_2 = 12; +..assert each_3 = 13; + +/* each with two tables */ +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; +each_sum : each @add table1 table2; +..assert each_sum.a = 11; +..assert each_sum.b = 22; +..assert each_sum.c = 33; + +..out "Simple each test completed"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_simple_call.txt b/js/scripting-lang/scratch_tests/test_each_simple_call.txt new file mode 100644 index 0000000..746d0d4 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_simple_call.txt @@ -0,0 +1,20 @@ +/* Simple test for each function call */ + +/* Basic table creation */ +numbers : {1, 2, 3}; + +/* Define function */ +double : x -> x * 2; + +/* Test direct function call */ +direct_call : double 5; + +/* Test each with explicit arguments */ +each_call : each @double numbers; + +/* Output results */ +..out "=== EACH SIMPLE CALL TEST ==="; +..out "Direct call result:"; +..out direct_call; +..out "Each call result:"; +..out each_call; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_solution.txt b/js/scripting-lang/scratch_tests/test_each_solution.txt new file mode 100644 index 0000000..f8dbf90 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_solution.txt @@ -0,0 +1,27 @@ +/* Test to show correct usage patterns for each */ + +numbers : {1, 2, 3, 4, 5}; +add_ten : x -> x + 10; + +/* For single table operations, use map */ +map_result : map @add_ten numbers; +..out "Map with single table:"; +..out map_result; + +/* For two-argument operations with table and scalar, use each */ +each_result1 : each @add numbers 10; +..out "Each with table and scalar:"; +..out each_result1; + +/* For two-table operations, use each */ +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; +each_result2 : each @add table1 table2; +..out "Each with two tables:"; +..out each_result2; + +/* For partial application, use each */ +add_to_ten : each @add 10; +each_result3 : add_to_ten numbers; +..out "Each with partial application:"; +..out each_result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_each_step_by_step.txt b/js/scripting-lang/scratch_tests/test_each_step_by_step.txt new file mode 100644 index 0000000..2a0e3ef --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_each_step_by_step.txt @@ -0,0 +1,26 @@ +/* Step-by-step test for each combinator */ + +/* Basic table creation */ +numbers : {1, 2, 3}; + +/* Define function first */ +double : x -> x * 2; + +/* Test each step by step */ +step1 : each; +step2 : step1 @double; +step3 : step2 numbers; + +/* Test direct call */ +direct_result : each @double numbers; + +/* Output results */ +..out "=== EACH STEP BY STEP TEST ==="; +..out "Step 1 (each):"; +..out step1; +..out "Step 2 (each @double):"; +..out step2; +..out "Step 3 (result numbers):"; +..out step3; +..out "Direct result:"; +..out direct_result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_embedded_functions.txt b/js/scripting-lang/scratch_tests/test_embedded_functions.txt new file mode 100644 index 0000000..4be9365 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_embedded_functions.txt @@ -0,0 +1,84 @@ +/* Test embedded functions in tables */ + +// Test 1: Simple embedded function (arrow syntax) +calculator : { + add: x y -> x + y, + multiply: x y -> x * y +}; + +// Test 2: Arrow function syntax +calculator2 : { + add: x y -> x + y, + multiply: x y -> x * y +}; + +// Test 3: When expression in table +classifier : { + classify: x -> when x is + 0 then "zero" + 1 then "one" + _ then "other" +}; + +// Test 4: Mixed content +mixed : { + name: "Calculator", + version: 1.0, + add: x y -> x + y, + is_valid: x -> x > 0 +}; + +// Test 5: Nested tables with functions +nested : { + math: { + add: x y -> x + y, + subtract: x y -> x - y + }, + logic: { + logical_and: x y -> x and y, + logical_or: x y -> x or y + } +}; + +// Test 6: Function that returns a table +table_factory : { + create_point: x y -> {x: x, y: y}, + create_range: start end -> {start: start, end: end, length: end - start} +}; + +// Output tests +..out "=== EMBEDDED FUNCTIONS TEST ==="; + +..out "Calculator add:"; +result1 : calculator.add 5 3; +..out result1; + +..out "Calculator2 multiply:"; +result2 : calculator2.multiply 4 7; +..out result2; + +..out "Classifier:"; +class1 : classifier.classify 0; +..out class1; +class2 : classifier.classify 5; +..out class2; + +..out "Mixed table:"; +..out mixed.name; +..out mixed.version; +result3 : mixed.add 10 20; +..out result3; +valid : mixed.is_valid 5; +..out valid; + +..out "Nested functions:"; +nested_add : nested.math.add 15 25; +..out nested_add; +nested_logic : nested.logic.logical_and true false; +..out nested_logic; + +..out "Table factory:"; +point : table_factory.create_point 10 20; +..out point; +range : table_factory.create_range 1 10; +..out range; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_embedded_functions_comprehensive.txt b/js/scripting-lang/scratch_tests/test_embedded_functions_comprehensive.txt new file mode 100644 index 0000000..9a2eeab --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_embedded_functions_comprehensive.txt @@ -0,0 +1,162 @@ +/* Comprehensive test for embedded functions in tables */ + +/* Test 1: Basic arrow functions */ +basic : { + identity: x -> x, + double: x -> x * 2, + add: x y -> x + y, + multiply: x y -> x * y +}; + +/* Test 2: When expressions */ +classifier : { + classify: x -> when x is + 0 then "zero" + 1 then "one" + 2 then "two" + _ then "other", + is_positive: x -> when x is + 0 then false + _ then true +}; + +/* Test 3: Mixed content tables */ +mixed : { + name: "Calculator", + version: 1.0, + active: true, + add: x y -> x + y, + is_valid: x -> x > 0, + description: "A calculator with embedded functions" +}; + +/* Test 4: Nested tables with functions */ +nested : { + math: { + add: x y -> x + y, + subtract: x y -> x - y, + multiply: x y -> x * y, + divide: x y -> x / y + }, + logic: { + logical_and: x y -> x and y, + logical_or: x y -> x or y, + logical_not: x -> not x + }, + utils: { + abs: x -> when x is + 0 then 0 + _ then x, + max: x y -> when x is + 0 then y + _ then x + } +}; + +/* Test 5: Functions that return tables */ +table_factory : { + create_point: x y -> {x: x, y: y}, + create_range: start end -> {start: start, end: end, length: end - start}, + create_config: name value -> { + name: name, + value: value, + timestamp: 1234567890 + } +}; + +/* Test 6: Complex nested functions */ +complex : { + math: { + operations: { + add: x y -> x + y, + multiply: x y -> x * y + }, + helpers: { + square: x -> x * x, + cube: x -> x * x * x + } + }, + data: { + processors: { + map: f list -> list, /* Placeholder for map function */ + filter: p list -> list /* Placeholder for filter function */ + } + } +}; + +/* Output tests */ +..out "=== COMPREHENSIVE EMBEDDED FUNCTIONS TEST ==="; + +..out "Basic functions:"; +id_result : basic.identity 42; +..out id_result; +double_result : basic.double 21; +..out double_result; +add_result : basic.add 10 20; +..out add_result; +mult_result : basic.multiply 6 7; +..out mult_result; + +..out "Classifier functions:"; +class_zero : classifier.classify 0; +..out class_zero; +class_one : classifier.classify 1; +..out class_one; +class_other : classifier.classify 99; +..out class_other; +pos_test : classifier.is_positive 5; +..out pos_test; +neg_test : classifier.is_positive -3; +..out neg_test; + +..out "Mixed table:"; +..out mixed.name; +..out mixed.version; +..out mixed.active; +mixed_add : mixed.add 15 25; +..out mixed_add; +mixed_valid : mixed.is_valid 10; +..out mixed_valid; +..out mixed.description; + +..out "Nested math functions:"; +nested_add : nested.math.add 100 200; +..out nested_add; +nested_sub : nested.math.subtract 50 30; +..out nested_sub; +nested_mul : nested.math.multiply 8 9; +..out nested_mul; +nested_div : nested.math.divide 100 4; +..out nested_div; + +..out "Nested logic functions:"; +logic_and : nested.logic.logical_and true false; +..out logic_and; +logic_or : nested.logic.logical_or true false; +..out logic_or; +logic_not : nested.logic.logical_not false; +..out logic_not; + +..out "Nested utility functions:"; +abs_neg : nested.utils.abs -42; +..out abs_neg; +abs_pos : nested.utils.abs 42; +..out abs_pos; +max_test : nested.utils.max 10 20; +..out max_test; + +..out "Table factory functions:"; +point : table_factory.create_point 15 25; +..out point; +range : table_factory.create_range 1 10; +..out range; +config : table_factory.create_config "test" 123; +..out config; + +..out "Complex nested functions:"; +complex_add : complex.math.operations.add 5 10; +..out complex_add; +complex_square : complex.math.helpers.square 6; +..out complex_square; +complex_cube : complex.math.helpers.cube 3; +..out complex_cube; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_embedded_functions_gradual.txt b/js/scripting-lang/scratch_tests/test_embedded_functions_gradual.txt new file mode 100644 index 0000000..7387c93 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_embedded_functions_gradual.txt @@ -0,0 +1,59 @@ +/* Gradual embedded functions test */ + +// Test 1: Basic arrow functions +basic : { + identity: x -> x, + double: x -> x * 2 +}; + +// Test 2: When expressions (simple) +classifier1 : { + classify: x -> when x is + 0 then "zero" + _ then "other" +}; + +// Test 3: When expressions (multiple cases) +classifier2 : { + classify: x -> when x is + 0 then "zero" + 1 then "one" + 2 then "two" + _ then "other" +}; + +// Test 4: Mixed content tables +mixed : { + name: "Calculator", + add: x y -> x + y +}; + +// Output tests +..out "=== GRADUAL EMBEDDED FUNCTIONS TEST ==="; + +..out "Basic functions:"; +id_result : basic.identity 42; +..out id_result; +double_result : basic.double 21; +..out double_result; + +..out "Simple classifier:"; +class1_zero : classifier1.classify 0; +..out class1_zero; +class1_other : classifier1.classify 99; +..out class1_other; + +..out "Complex classifier:"; +class2_zero : classifier2.classify 0; +..out class2_zero; +class2_one : classifier2.classify 1; +..out class2_one; +class2_two : classifier2.classify 2; +..out class2_two; +class2_other : classifier2.classify 99; +..out class2_other; + +..out "Mixed table:"; +..out mixed.name; +mixed_add : mixed.add 15 25; +..out mixed_add; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_embedded_functions_minimal.txt b/js/scripting-lang/scratch_tests/test_embedded_functions_minimal.txt new file mode 100644 index 0000000..8a516f0 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_embedded_functions_minimal.txt @@ -0,0 +1,40 @@ +/* Minimal embedded functions test */ + +// Test 1: Basic arrow functions +basic : { + identity: x -> x, + double: x -> x * 2 +}; + +// Test 2: When expressions +classifier : { + classify: x -> when x is + 0 then "zero" + _ then "other" +}; + +// Test 3: Mixed content tables +mixed : { + name: "Calculator", + add: x y -> x + y +}; + +// Output tests +..out "=== MINIMAL EMBEDDED FUNCTIONS TEST ==="; + +..out "Basic functions:"; +id_result : basic.identity 42; +..out id_result; +double_result : basic.double 21; +..out double_result; + +..out "Classifier functions:"; +class_zero : classifier.classify 0; +..out class_zero; +class_other : classifier.classify 99; +..out class_other; + +..out "Mixed table:"; +..out mixed.name; +mixed_add : mixed.add 15 25; +..out mixed_add; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_embedded_functions_partial.txt b/js/scripting-lang/scratch_tests/test_embedded_functions_partial.txt new file mode 100644 index 0000000..7cc201c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_embedded_functions_partial.txt @@ -0,0 +1,50 @@ +/* Partial embedded functions test */ + +/* Test 1: Basic arrow functions */ +basic : { + identity: x -> x, + double: x -> x * 2, + add: x y -> x + y, + multiply: x y -> x * y +}; + +/* Test 2: When expressions */ +classifier : { + classify: x -> when x is + 0 then "zero" + 1 then "one" + 2 then "two" + _ then "other", + is_positive: x -> when x is + 0 then false + _ then true +}; + +/* Output tests */ +..out "=== PARTIAL EMBEDDED FUNCTIONS TEST ==="; + +..out "Basic functions:"; +id_result : basic.identity 42; +..out id_result; +double_result : basic.double 21; +..out double_result; +add_result : basic.add 10 20; +..out add_result; +mult_result : basic.multiply 6 7; +..out mult_result; + +..out "Classifier functions:"; +class_zero : classifier.classify 0; +..out class_zero; +class_one : classifier.classify 1; +..out class_one; +class_two : classifier.classify 2; +..out class_two; +class_other : classifier.classify 99; +..out class_other; + +..out "Positive test:"; +pos_test : classifier.is_positive 5; +..out pos_test; +neg_test : classifier.is_positive -3; +..out neg_test; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_embedded_functions_simple.txt b/js/scripting-lang/scratch_tests/test_embedded_functions_simple.txt new file mode 100644 index 0000000..550402c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_embedded_functions_simple.txt @@ -0,0 +1,29 @@ +/* Simple test for embedded functions in tables */ + +// Test 1: Just arrow functions (should work) +calculator : { + add: x y -> x + y, + multiply: x y -> x * y +}; + +// Test 2: Mixed content +mixed : { + name: "Calculator", + add: x y -> x + y +}; + +// Output tests +..out "=== SIMPLE EMBEDDED FUNCTIONS TEST ==="; + +..out "Calculator add:"; +result1 : calculator.add 5 3; +..out result1; + +..out "Calculator multiply:"; +result2 : calculator.multiply 4 7; +..out result2; + +..out "Mixed table:"; +..out mixed.name; +result3 : mixed.add 10 20; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_enhanced_compose.txt b/js/scripting-lang/scratch_tests/test_enhanced_compose.txt new file mode 100644 index 0000000..d277c64 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_enhanced_compose.txt @@ -0,0 +1,9 @@ +/* Test enhanced compose function */ + +f : x -> x * 2; +g : x -> x + 1; +h : x -> x * x; + +/* Test enhanced compose with multiple functions */ +result : compose(f, g, h) 2; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_expression_function.txt b/js/scripting-lang/scratch_tests/test_expression_function.txt new file mode 100644 index 0000000..4b3308f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_expression_function.txt @@ -0,0 +1,9 @@ +/* Test function with expression in body */ + +// Function with expression +expr_func : x y -> x + y; + +// Test it +..out "=== EXPRESSION FUNCTION TEST ==="; +result : expr_func 5 3; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_factorial.txt b/js/scripting-lang/scratch_tests/test_factorial.txt new file mode 100644 index 0000000..9945285 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_factorial.txt @@ -0,0 +1,8 @@ +/* Test factorial function */ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +result : factorial 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_factorial_fixed.txt b/js/scripting-lang/scratch_tests/test_factorial_fixed.txt new file mode 100644 index 0000000..db0ec5f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_factorial_fixed.txt @@ -0,0 +1,8 @@ +/* Test factorial function with @ operator */ +factorial : n -> + when n is + 0 then 1 + _ then n * (@factorial (n - 1)); + +result : factorial 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_filter_debug.txt b/js/scripting-lang/scratch_tests/test_filter_debug.txt new file mode 100644 index 0000000..6b9df38 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_filter_debug.txt @@ -0,0 +1,3 @@ +isPositive : x -> x > 0; +filtered2 : filter @isPositive -3; +..out filtered2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_filter_issue.txt b/js/scripting-lang/scratch_tests/test_filter_issue.txt new file mode 100644 index 0000000..63331d9 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_filter_issue.txt @@ -0,0 +1,11 @@ +/* Test filter issue */ + +numbers : {1, 2, 3, 4, 5}; +is_even : x -> x % 2 = 0; +evens : filter @is_even numbers; +even_2 : evens[2]; +even_4 : evens[4]; +..assert even_2 = 2; +..assert even_4 = 4; + +..out "Filter test completed"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_function_arg_syntax.txt b/js/scripting-lang/scratch_tests/test_function_arg_syntax.txt new file mode 100644 index 0000000..4b4afbe --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_function_arg_syntax.txt @@ -0,0 +1,3 @@ +add_func : x y -> x + y; +result : add_func @(3 + 2) @(4 + 1); +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_function_declaration.txt b/js/scripting-lang/scratch_tests/test_function_declaration.txt new file mode 100644 index 0000000..90c1594 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_function_declaration.txt @@ -0,0 +1,37 @@ +/* Test FunctionDeclaration behavior */ + +// Test 1: Regular function declaration +test_func : x y -> x + y; + +// Test 2: Function declaration with when expression +test_when : x -> when x is + 0 then "zero" + _ then "other" +; + +// Test 3: Function declaration in table +table_func : { + add: x y -> x + y, + classify: x -> when x is + 0 then "zero" + _ then "other" +}; + +// Output tests +..out "=== FUNCTION DECLARATION TEST ==="; + +..out "Regular function:"; +result1 : test_func 5 3; +..out result1; + +..out "When function:"; +result2 : test_when 0; +..out result2; +result3 : test_when 5; +..out result3; + +..out "Table functions:"; +result4 : table_func.add 10 20; +..out result4; +result5 : table_func.classify 0; +..out result5; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_function_issue.txt b/js/scripting-lang/scratch_tests/test_function_issue.txt new file mode 100644 index 0000000..991e92e --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_function_issue.txt @@ -0,0 +1,3 @@ +add_func : x y -> x + y; +result : add_func 3 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_function_precedence.txt b/js/scripting-lang/scratch_tests/test_function_precedence.txt new file mode 100644 index 0000000..e453d72 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_function_precedence.txt @@ -0,0 +1,32 @@ +/* Test function application precedence fix */ +/* This should test that abs -5 is parsed as apply(abs, negate(5)) not subtract(abs, 5) */ + +x : 5; +abs : x -> when x is + x < 0 then -x + _ then x; + +/* Test 1: Function call with negative literal */ +result1 : abs -5; /* Should be apply(abs, negate(5)) = 5 */ + +/* Test 2: Function call with negative variable */ +result2 : abs -x; /* Should be apply(abs, negate(x)) = 5 */ + +/* Test 3: Multiple function applications */ +double : x -> x * 2; +result3 : double abs -3; /* Should be apply(double, apply(abs, negate(3))) = 6 */ + +/* Test 4: Function call with parenthesized expression */ +result4 : abs (-x); /* Should be apply(abs, negate(x)) = 5 */ + +/* Test 5: Complex expression */ +result5 : abs -5 + 10; /* Should be add(apply(abs, negate(5)), 10) = 15 */ + +/* Test 6: Left-associative function application */ +f : x -> x * 2; +g : x -> x + 1; +result6 : f g 3; /* Should be apply(apply(f, g), 3) = 8 */ + +/* Test 7: Function call with table access */ +table : {value: -5}; +result7 : abs table.value; /* Should be apply(abs, table.value) = 5 */ \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_function_reference.txt b/js/scripting-lang/scratch_tests/test_function_reference.txt new file mode 100644 index 0000000..6c3a609 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_function_reference.txt @@ -0,0 +1,8 @@ +/* Test function references */ + +f : x -> x * 2; +g : x -> x + 1; + +/* Test function reference */ +ref : @f; +..out ref; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_functions.txt b/js/scripting-lang/scratch_tests/test_functions.txt new file mode 100644 index 0000000..8e3ea43 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_functions.txt @@ -0,0 +1,15 @@ +/* Test individual functions */ +f1 : x -> x + 1; +f2 : x -> x * 2; +f3 : x -> x - 1; + +test1 : f1 10; +test2 : f2 10; +test3 : f3 10; + +..out "f1(10) = "; +..out test1; +..out "f2(10) = "; +..out test2; +..out "f3(10) = "; +..out test3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_grade.txt b/js/scripting-lang/scratch_tests/test_grade.txt new file mode 100644 index 0000000..730987c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_grade.txt @@ -0,0 +1,15 @@ +/* Test grade function */ +grade : score -> + when score is + 90 then "A" + 80 then "B" + 70 then "C" + _ then "F"; + +result1 : grade 95; +result2 : grade 85; +result3 : grade 65; + +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_grade_comparison.txt b/js/scripting-lang/scratch_tests/test_grade_comparison.txt new file mode 100644 index 0000000..39df2f8 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_grade_comparison.txt @@ -0,0 +1,15 @@ +/* Test grade function with comparison patterns */ +grade : score -> + when score is + score >= 90 then "A" + score >= 80 then "B" + score >= 70 then "C" + _ then "F"; + +result1 : grade 95; +result2 : grade 85; +result3 : grade 65; + +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_gradual_build.txt b/js/scripting-lang/scratch_tests/test_gradual_build.txt new file mode 100644 index 0000000..4494770 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_gradual_build.txt @@ -0,0 +1,24 @@ +/* Gradual build test */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; + +/* Test enhanced map */ +double : x -> x * 2; +doubled : map @double numbers; + +/* Test t.map */ +t_doubled : t.map @double numbers; + +/* Test enhanced filter */ +isEven : x -> x % 2 == 0; +even_numbers : filter @isEven numbers; + +/* Output results */ +..out "=== GRADUAL BUILD TEST ==="; +..out "Enhanced map:"; +..out doubled; +..out "t.map:"; +..out t_doubled; +..out "Enhanced filter:"; +..out even_numbers; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_map_comparison.txt b/js/scripting-lang/scratch_tests/test_map_comparison.txt new file mode 100644 index 0000000..742c9dd --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_map_comparison.txt @@ -0,0 +1,14 @@ +/* Test to compare map and each behavior */ + +numbers : {1, 2, 3, 4, 5}; +add_ten : x -> x + 10; + +/* Test map with single table */ +map_result : map @add_ten numbers; +..out "Map with single table:"; +..out map_result; + +/* Test each with single table */ +each_result : each @add_ten numbers; +..out "Each with single table:"; +..out each_result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_minus_debug.txt b/js/scripting-lang/scratch_tests/test_minus_debug.txt new file mode 100644 index 0000000..d81107b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_minus_debug.txt @@ -0,0 +1,12 @@ +/* Debug minus operator */ + +x : 42; +y : 10; + +/* Test binary minus */ +result1 : x - y; +..out result1; + +/* Test unary minus */ +result2 : -x; +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_multi_param_when.txt b/js/scripting-lang/scratch_tests/test_multi_param_when.txt new file mode 100644 index 0000000..cb4843e --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_multi_param_when.txt @@ -0,0 +1,9 @@ +/* Test multi-parameter when expressions */ +classify : x y -> + when x y is + 0 0 then "both zero" + 0 _ then "x is zero" + _ 0 then "y is zero" + _ _ then "neither zero"; + +..out "multi-parameter when expression created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_nested_debug.txt b/js/scripting-lang/scratch_tests/test_nested_debug.txt new file mode 100644 index 0000000..ad68670 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_nested_debug.txt @@ -0,0 +1,8 @@ +nested_func1 : x -> x + 1; +nested_func2 : x -> nested_func1 x; +nested_func3 : x -> nested_func2 x; +nested_func4 : x -> nested_func3 x; +nested_func5 : x -> nested_func4 x; + +deep_nested : nested_func5 10; +..out deep_nested; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_nested_functions.txt b/js/scripting-lang/scratch_tests/test_nested_functions.txt new file mode 100644 index 0000000..539491b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_nested_functions.txt @@ -0,0 +1,28 @@ +/* Test nested table functions */ + +// Test nested tables with functions +nested : { + math: { + add: x y -> x + y, + subtract: x y -> x - y + }, + logic: { + logical_and: x y -> x and y, + logical_or: x y -> x or y + } +}; + +// Output tests +..out "=== NESTED FUNCTIONS TEST ==="; + +..out "Nested math functions:"; +nested_add : nested.math.add 100 200; +..out nested_add; +nested_sub : nested.math.subtract 50 30; +..out nested_sub; + +..out "Nested logic functions:"; +logic_and : nested.logic.logical_and true false; +..out logic_and; +logic_or : nested.logic.logical_or true false; +..out logic_or; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_nested_table.txt b/js/scripting-lang/scratch_tests/test_nested_table.txt new file mode 100644 index 0000000..9895e4e --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_nested_table.txt @@ -0,0 +1,10 @@ +/* Test nested table literals */ +nested_table : { + outer: { + inner: { + value: 42 + } + } +}; + +..out "nested_table created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_nested_when.txt b/js/scripting-lang/scratch_tests/test_nested_when.txt new file mode 100644 index 0000000..b39c370 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_nested_when.txt @@ -0,0 +1,11 @@ +/* Test nested when expressions */ +classify : x y -> + when x y is + 0 0 then "both zero" + 0 _ then "x is zero" + _ 0 then "y is zero" + _ _ then when x is + 0 then "x is zero (nested)" + _ then "neither zero"; + +..out "nested when expression created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_original_problem.txt b/js/scripting-lang/scratch_tests/test_original_problem.txt new file mode 100644 index 0000000..e0d838f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_original_problem.txt @@ -0,0 +1,6 @@ +add_func : x y -> x + y; +result : add_func @(3 + 2) @(4 + 1); +..out result; + +result2 : add_func (3 + 2) (4 + 1); +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_parenthesized_only.txt b/js/scripting-lang/scratch_tests/test_parenthesized_only.txt new file mode 100644 index 0000000..ce0d5d2 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_parenthesized_only.txt @@ -0,0 +1,5 @@ +/* Test parenthesized version only */ + +test2 : (-5) + 3; + +..out test2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_pattern_part1.txt b/js/scripting-lang/scratch_tests/test_pattern_part1.txt new file mode 100644 index 0000000..60af053 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pattern_part1.txt @@ -0,0 +1,12 @@ +/* Integration Test: Pattern Matching */ +/* Combines: case expressions, functions, recursion, complex patterns */ + +..out "=== Integration Test: Pattern Matching ==="; + +/* Recursive factorial with case expressions */ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +..out "factorial function created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_pattern_part2.txt b/js/scripting-lang/scratch_tests/test_pattern_part2.txt new file mode 100644 index 0000000..dffef79 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pattern_part2.txt @@ -0,0 +1,24 @@ +/* Integration Test: Pattern Matching */ +/* Combines: case expressions, functions, recursion, complex patterns */ + +..out "=== Integration Test: Pattern Matching ==="; + +/* Recursive factorial with case expressions */ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +/* Pattern matching with multiple parameters */ +classify : x y -> + when x y is + 0 0 then "both zero" + 0 _ then "x is zero" + _ 0 then "y is zero" + _ _ then when x is + 0 then "x is zero (nested)" + _ then when y is + 0 then "y is zero (nested)" + _ then "neither zero"; + +..out "both functions created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_pattern_part3.txt b/js/scripting-lang/scratch_tests/test_pattern_part3.txt new file mode 100644 index 0000000..3c32b90 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pattern_part3.txt @@ -0,0 +1,28 @@ +/* Integration Test: Pattern Matching */ +/* Combines: case expressions, functions, recursion, complex patterns */ + +..out "=== Integration Test: Pattern Matching ==="; + +/* Recursive factorial with case expressions */ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +/* Pattern matching with multiple parameters */ +classify : x y -> + when x y is + 0 0 then "both zero" + 0 _ then "x is zero" + _ 0 then "y is zero" + _ _ then when x is + 0 then "x is zero (nested)" + _ then when y is + 0 then "y is zero (nested)" + _ then "neither zero"; + +/* Test factorial */ +fact5 : factorial 5; +fact3 : factorial 3; + +..out "test calls created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_pipe_debug.txt b/js/scripting-lang/scratch_tests/test_pipe_debug.txt new file mode 100644 index 0000000..5c8d5fb --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pipe_debug.txt @@ -0,0 +1,14 @@ +/* Debug pipe function */ + +double : x -> x * 2; +add1 : x -> x + 1; + +/* Test pipe function step by step */ +step1 : pipe double; +..out step1; + +step2 : step1 add1; +..out step2; + +step3 : step2 5; +..out step3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_pipe_function.txt b/js/scripting-lang/scratch_tests/test_pipe_function.txt new file mode 100644 index 0000000..3842a86 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pipe_function.txt @@ -0,0 +1,8 @@ +/* Test pipe function */ + +f : x -> x * 2; +g : x -> x + 1; + +/* Test pipe function */ +result : pipe(f, g) 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_pipe_nested.txt b/js/scripting-lang/scratch_tests/test_pipe_nested.txt new file mode 100644 index 0000000..6cc2738 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pipe_nested.txt @@ -0,0 +1,9 @@ +/* Test nested pipe function */ +f1 : x -> x + 1; +f2 : x -> x * 2; +f3 : x -> x - 1; + +nested_pipe : pipe @f1 (pipe @f2 @f3) 10; + +..out "nested_pipe = "; +..out nested_pipe; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_pipe_simple.txt b/js/scripting-lang/scratch_tests/test_pipe_simple.txt new file mode 100644 index 0000000..c96613d --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pipe_simple.txt @@ -0,0 +1,11 @@ +/* Test simple pipe function */ +f1 : x -> x + 1; +f2 : x -> x * 2; + +simple_pipe : pipe @f1 @f2 10; +simple_compose : compose @f1 @f2 10; + +..out "simple_pipe = "; +..out simple_pipe; +..out "simple_compose = "; +..out simple_compose; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_plus_debug.txt b/js/scripting-lang/scratch_tests/test_plus_debug.txt new file mode 100644 index 0000000..99591fa --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_plus_debug.txt @@ -0,0 +1,3 @@ +/* Minimal test for PLUS token issue */ +result : -5 + 3; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_precedence_comprehensive.txt b/js/scripting-lang/scratch_tests/test_precedence_comprehensive.txt new file mode 100644 index 0000000..29f1420 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_precedence_comprehensive.txt @@ -0,0 +1,129 @@ +/* Comprehensive Precedence Test Cases */ + +/* Setup variables */ +x : 5; +y : 3; +z : 2; + +/* Setup functions */ +f : x -> x * 2; +g : x -> x + 1; +h : x -> x * x; + +/* 1. Basic Arithmetic Operations */ +result1 : x + y; +result2 : x - y; +result3 : x * y; +result4 : x / y; +result5 : x % y; +result6 : x ^ z; + +..out "=== Basic Arithmetic ==="; +..out result1; +..out result2; +..out result3; +..out result4; +..out result5; +..out result6; + +/* 2. Unary Operations */ +result7 : -x; +result8 : not true; + +..out "=== Unary Operations ==="; +..out result7; +..out result8; + +/* 3. Mixed Unary and Binary Operations */ +result9 : x * -y; +result10 : -x + y; +result11 : x - -y; +result12 : -x * -y; + +..out "=== Mixed Operations ==="; +..out result9; +..out result10; +..out result11; +..out result12; + +/* 4. Function Application */ +result13 : f 5; +result14 : f g 5; +result15 : f (g 5); + +..out "=== Function Application ==="; +..out result13; +..out result14; +..out result15; + +/* 5. Function Composition */ +result16 : f via g 5; +result17 : f via g via h 3; +result18 : pipe(f, g) 5; +result19 : compose(f, g) 5; + +..out "=== Function Composition ==="; +..out result16; +..out result17; +..out result18; +..out result19; + +/* 6. Comparison Operations */ +result20 : x = y; +result21 : x != y; +result22 : x < y; +result23 : x > y; +result24 : x <= y; +result25 : x >= y; + +..out "=== Comparison Operations ==="; +..out result20; +..out result21; +..out result22; +..out result23; +..out result24; +..out result25; + +/* 7. Logical Operations */ +a : true; +b : false; +result26 : a and b; +result27 : a or b; +result28 : a xor b; +result29 : not a; + +..out "=== Logical Operations ==="; +..out result26; +..out result27; +..out result28; +..out result29; + +/* 8. Complex Expressions */ +result30 : x + y * z; +result31 : (x + y) * z; +result32 : x - y + z; +result33 : x * -y + z; +result34 : f x + g y; + +..out "=== Complex Expressions ==="; +..out result30; +..out result31; +..out result32; +..out result33; +..out result34; + +/* 9. Edge Cases */ +result35 : -5; +result36 : 5 - 3; +result37 : f -5; +result38 : f 5 - 3; +result39 : f (5 - 3); + +..out "=== Edge Cases ==="; +..out result35; +..out result36; +..out result37; +..out result38; +..out result39; + +..out "=== Test Complete ==="; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_precedence_fix.txt b/js/scripting-lang/scratch_tests/test_precedence_fix.txt new file mode 100644 index 0000000..776aabe --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_precedence_fix.txt @@ -0,0 +1,10 @@ +x : 10; +y : 3; +result : x - y; +..out result; + +z : -5; +..out z; + +mixed : x * -y; +..out mixed; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_precedence_simple.txt b/js/scripting-lang/scratch_tests/test_precedence_simple.txt new file mode 100644 index 0000000..32b5bb9 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_precedence_simple.txt @@ -0,0 +1,21 @@ +/* Simple Precedence Test */ + +/* Basic variables */ +x : 5; +y : 3; + +/* Test 1: Simple arithmetic */ +result1 : x + y; +..out result1; + +/* Test 2: Binary minus (the problematic one) */ +result2 : x - y; +..out result2; + +/* Test 3: Unary minus */ +result3 : -x; +..out result3; + +/* Test 4: Mixed */ +result4 : x * -y; +..out result4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_precedence_variations.txt b/js/scripting-lang/scratch_tests/test_precedence_variations.txt new file mode 100644 index 0000000..66a43bf --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_precedence_variations.txt @@ -0,0 +1,16 @@ +/* Test various precedence combinations */ + +/* These should work */ +test1 : 5 + 3; +test2 : -5; +test3 : 5 * -3; +test4 : (-5) + 3; + +/* This is the problematic one */ +test5 : -5 + 3; + +..out test1; +..out test2; +..out test3; +..out test4; +..out test5; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_reduce_debug.txt b/js/scripting-lang/scratch_tests/test_reduce_debug.txt new file mode 100644 index 0000000..741d223 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_reduce_debug.txt @@ -0,0 +1,3 @@ +add_func : x y -> x + y; +reduced : reduce @add_func @(0) @(5); +..out reduced; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_reduce_simple.txt b/js/scripting-lang/scratch_tests/test_reduce_simple.txt new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_reduce_simple.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple.txt b/js/scripting-lang/scratch_tests/test_simple.txt new file mode 100644 index 0000000..b5839fe --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple.txt @@ -0,0 +1,5 @@ +/* Simple test */ + +add_func : x y -> x + y; +result : add_func 3 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_bracket.txt b/js/scripting-lang/scratch_tests/test_simple_bracket.txt new file mode 100644 index 0000000..6ab9dba --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_bracket.txt @@ -0,0 +1,9 @@ +/* Simple test for bracket notation */ + +numbers : {1, 2, 3, 4, 5}; +first : numbers[1]; +second : numbers[2]; +..assert first = 1; +..assert second = 2; + +..out "Bracket notation test completed"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_composition.txt b/js/scripting-lang/scratch_tests/test_simple_composition.txt new file mode 100644 index 0000000..44e42b6 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_composition.txt @@ -0,0 +1,8 @@ +/* Test simple composition */ + +f : x -> x * 2; +g : x -> x + 1; + +/* Test basic composition */ +result : f via g 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_function.txt b/js/scripting-lang/scratch_tests/test_simple_function.txt new file mode 100644 index 0000000..3f8ece7 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_function.txt @@ -0,0 +1,9 @@ +/* Simple function test */ + +// Just create a function +simple_func : x -> x; + +// Test it +..out "=== SIMPLE FUNCTION TEST ==="; +result : simple_func 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_minus.txt b/js/scripting-lang/scratch_tests/test_simple_minus.txt new file mode 100644 index 0000000..a322508 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_minus.txt @@ -0,0 +1,4 @@ +/* Simple minus test */ + +result : 5 - 3; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_plus.txt b/js/scripting-lang/scratch_tests/test_simple_plus.txt new file mode 100644 index 0000000..327d9aa --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_plus.txt @@ -0,0 +1,3 @@ +/* Simple addition test */ +result : 5 + 3; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_unary_minus.txt b/js/scripting-lang/scratch_tests/test_simple_unary_minus.txt new file mode 100644 index 0000000..221cfdc --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_unary_minus.txt @@ -0,0 +1,3 @@ +/* Simple unary minus test */ +result : -5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_when.txt b/js/scripting-lang/scratch_tests/test_simple_when.txt new file mode 100644 index 0000000..0b1154f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_when.txt @@ -0,0 +1,9 @@ +/* Simple when expression test */ + +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +result : factorial 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_t_access_simple.txt b/js/scripting-lang/scratch_tests/test_t_access_simple.txt new file mode 100644 index 0000000..bc233c1 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_t_access_simple.txt @@ -0,0 +1,13 @@ +/* Simple test for t. namespace access */ + +/* Basic table creation */ +numbers : {1, 2, 3}; + +/* Test t.map access */ +t_map_test : t.map; +/* Expected: function */ + +/* Output results */ +..out "=== T. ACCESS TEST ==="; +..out "t.map:"; +..out t_map_test; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_t_function_call.txt b/js/scripting-lang/scratch_tests/test_t_function_call.txt new file mode 100644 index 0000000..a258f0d --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_t_function_call.txt @@ -0,0 +1,15 @@ +/* Test t. function calls */ + +/* Basic table creation */ +numbers : {1, 2, 3}; + +/* Define function */ +double : x -> x * 2; + +/* Test t.map function call */ +t_map_result : t.map @double numbers; + +/* Output results */ +..out "=== T. FUNCTION CALL TEST ==="; +..out "t.map result:"; +..out t_map_result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_t_namespace.txt b/js/scripting-lang/scratch_tests/test_t_namespace.txt new file mode 100644 index 0000000..421655b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_t_namespace.txt @@ -0,0 +1,11 @@ +/* Simple test for t namespace */ + +numbers : {1, 2, 3, 4, 5}; +double : x -> x * 2; + +/* Test t.map */ +t_doubled : t.map @double numbers; +first : t_doubled[1]; +..assert first = 2; + +..out "T namespace test completed"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_enhancements.txt b/js/scripting-lang/scratch_tests/test_table_enhancements.txt new file mode 100644 index 0000000..004b32e --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_enhancements.txt @@ -0,0 +1,747 @@ +/* Test file for table enhancements + Comprehensive test suite for APL-inspired broadcasting and immutable operations + Based on design/TABLE_ENHANCEMENTS.md + + NOTE: This file contains tests for features that have NOT been implemented yet. + These tests will fail until the features are implemented. */ + +/* ===== BASIC TABLE CREATION ===== */ +numbers : {1, 2, 3, 4, 5}; +person : {name: "Alice", age: 30, active: true}; +mixed_table : {a: 1, b: "hello", c: true, d: 42.5}; + +/* ===== ENHANCED BROADCASTING COMBINATORS ===== */ +/* Test enhanced map with APL-inspired broadcasting */ +double : x -> x * 2; +doubled : map @double numbers; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */ + +square : x -> x * x; +squared : map @square numbers; +/* Expected: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25} */ + +/* Test map with mixed data types */ +isNumber : x -> typeof x == "number"; +type_check : map @isNumber mixed_table; +/* Expected: {a: true, b: false, c: false, d: true} */ + +/* ===== TABLE-SPECIFIC COMBINATORS (t. namespace) ===== */ +/* Test t.map for table-specific operations */ +t_doubled : t.map @double numbers; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */ + +/* Test t.filter for table filtering */ +isEven : x -> x % 2 == 0; +even_numbers : t.filter @isEven numbers; +/* Expected: {2: 2, 4: 4} */ + +isPositive : x -> x > 0; +positive_numbers : t.filter @isPositive numbers; +/* Expected: {1: 1, 2: 2, 3: 3, 4: 4, 5: 5} */ + +/* Test t.reduce for table reduction */ +sum : x y -> x + y; +total : t.reduce @sum 0 numbers; +/* Expected: 15 */ + +max : x y -> x > y ? x : y; +maximum : t.reduce @max numbers.1 numbers; +/* Expected: 5 */ + +/* ===== IMMUTABLE TABLE OPERATIONS (t. namespace) ===== */ +/* Test t.set for immutable updates */ +updated_person : t.set person "age" 31; +/* Expected: {name: "Alice", age: 31, active: true} */ + +added_city : t.set person "city" "New York"; +/* Expected: {name: "Alice", age: 30, active: true, city: "New York"} */ + +/* Test t.delete for immutable deletion */ +without_age : t.delete person "age"; +/* Expected: {name: "Alice", active: true} */ + +without_nonexistent : t.delete person "email"; +/* Expected: {name: "Alice", age: 30, active: true} (unchanged) */ + +/* Test t.merge for immutable merging */ +person2 : {city: "New York", country: "USA"}; +merged : t.merge person person2; +/* Expected: {name: "Alice", age: 30, active: true, city: "New York", country: "USA"} */ + +overwrite_merge : t.merge person {age: 25, city: "Boston"}; +/* Expected: {name: "Alice", age: 25, active: true, city: "Boston"} */ + +/* ===== TABLE INFORMATION OPERATIONS (t. namespace) ===== */ +/* Test t.pairs for getting key-value pairs */ +all_pairs : t.pairs person; +/* Expected: [["name", "Alice"], ["age", 30], ["active", true]] */ + +/* Test t.keys for getting keys */ +all_keys : t.keys person; +/* Expected: ["name", "age", "active"] */ + +/* Test t.values for getting values */ +all_values : t.values person; +/* Expected: ["Alice", 30, true] */ + +/* Test t.length for getting table size */ +table_size : t.length person; +/* Expected: 3 */ + +/* Test t.has for checking key existence */ +has_name : t.has person "name"; +/* Expected: true */ + +has_email : t.has person "email"; +/* Expected: false */ + +/* Test t.get for safe property access */ +age_or_default : t.get person "age" 0; +/* Expected: 30 */ + +email_or_default : t.get person "email" "unknown"; +/* Expected: "unknown" */ + +/* ===== APL-INSPIRED ELEMENT-WISE OPERATIONS ===== */ +/* Test each combinator for multi-argument element-wise operations */ +/* No tables - apply normally */ +normal_add : each @add 5 3; +/* Expected: 8 */ + +/* Single table - element-wise */ +add_ten : x -> x + 10; +each_result : each @add_ten numbers; +/* Expected: {1: 11, 2: 12, 3: 13, 4: 14, 5: 15} */ + +/* Mixed table and scalar */ +mixed_operation : each @add numbers 10; +/* Expected: {1: 11, 2: 12, 3: 13, 4: 14, 5: 15} */ + +/* Multiple tables */ +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; +multi_table_sum : each @add table1 table2; +/* Expected: {a: 11, b: 22, c: 33} */ + +/* Three tables */ +table3 : {a: 100, b: 200, c: 300}; +triple_sum : each @add table1 table2 table3; +/* Expected: {a: 111, b: 222, c: 333} */ + +/* Mixed types (table + scalar) */ +mixed_types : each @add table1 5; +/* Expected: {a: 6, b: 7, c: 8} */ + +mixed_types2 : each @add 5 table1; +/* Expected: {a: 6, b: 7, c: 8} */ + +/* ===== NESTED TABLE HANDLING ===== */ +/* Test nested table operations */ +nested : { + data: {a: 1, b: 2, c: 3}, + meta: {type: "numbers", count: 3}, + flags: {active: true, visible: false} +}; + +/* Top-level only (nested tables unchanged) */ +top_level_only : each @double nested; +/* Expected: {data: {a: 1, b: 2, c: 3}, meta: {type: "numbers", count: 3}, flags: {active: true, visible: false}} */ + +/* Nested operations with explicit composition */ +nested_doubled : each (each @double) nested; +/* Expected: {data: {a: 2, b: 4, c: 6}, meta: {type: "numbers", count: 3}, flags: {active: true, visible: false}} */ + +/* Nested operations with t.map */ +nested_with_t_map : t.map (t.map @double) nested; +/* Expected: {data: {a: 2, b: 4, c: 6}, meta: {type: "numbers", count: 3}, flags: {active: true, visible: false}} */ + +/* Deep nested structure */ +deep_nested : { + level1: { + level2: { + level3: {x: 1, y: 2, z: 3} + } + } +}; + +/* Deep nested operations */ +deep_doubled : each (each (each @double)) deep_nested; +/* Expected: {level1: {level2: {level3: {x: 2, y: 4, z: 6}}}} */ + +deep_with_t_map : t.map (t.map (t.map @double)) deep_nested; +/* Expected: {level1: {level2: {level3: {x: 2, y: 4, z: 6}}}} */ + +/* ===== EMBEDDED COMPLEX STRUCTURES ===== */ +/* Test functions and when expressions in tables */ +calculator : { + add: x y -> x + y, + multiply: x y -> x * y, + classify: x -> when x is + 0 then "zero" + 1 then "one" + _ then "other" +}; + +/* Usage of embedded functions */ +calc_result : calculator.add 5 3; +/* Expected: 8 */ + +calc_multiply : calculator.multiply 4 7; +/* Expected: 28 */ + +calc_classify_zero : calculator.classify 0; +/* Expected: "zero" */ + +calc_classify_one : calculator.classify 1; +/* Expected: "one" */ + +calc_classify_other : calculator.classify 42; +/* Expected: "other" */ + +/* ===== EDGE CASES AND ERROR HANDLING ===== */ +/* Test empty table operations */ +empty_table : {}; + +empty_pairs : t.pairs empty_table; +/* Expected: [] */ + +empty_keys : t.keys empty_table; +/* Expected: [] */ + +empty_values : t.values empty_table; +/* Expected: [] */ + +empty_length : t.length empty_table; +/* Expected: 0 */ + +/* Test safe operations (should not error) */ +safe_get : t.get person "nonexistent" "default"; +/* Expected: "default" */ + +safe_pairs : t.pairs empty_table; +/* Expected: [] */ + +/* Test boolean keys (existing feature) */ +boolean_table : {true: "enabled", false: "disabled"}; +boolean_keys : t.keys boolean_table; +/* Expected: [true, false] */ + +boolean_values : t.values boolean_table; +/* Expected: ["enabled", "disabled"] */ + +/* Test numeric keys */ +numeric_table : {1: "one", 2: "two", 3: "three"}; +numeric_keys : t.keys numeric_table; +/* Expected: [1, 2, 3] */ + +/* ===== FUNCTION COMPOSITION WITH TABLES ===== */ +/* Test table operations with function composition */ +transform : compose @t.map @double @t.filter @isPositive; +transformed : transform numbers; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */ + +pipe_transform : pipe @t.filter @isPositive @t.map @double; +pipe_result : pipe_transform numbers; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */ + +/* Test each with function composition */ +triple : x -> x * 3; +each_with_functions : each @double table1; +/* Expected: {a: 2, b: 4, c: 6} */ + +each_with_composition : each (compose @double @triple) table1; +/* Expected: {a: 6, b: 12, c: 18} */ + +/* ===== COMPLEX DATA STRUCTURES ===== */ +/* Test with complex nested data */ +data : { + users: {1: {name: "Alice", age: 30}, 2: {name: "Bob", age: 25}}, + scores: {1: 85, 2: 92}, + active: {1: true, 2: false} +}; + +/* Element-wise operations over nested structure */ +get_name : user -> user.name; +user_names : t.map @get_name data.users; +/* Expected: {1: "Alice", 2: "Bob"} */ + +/* Test table operations on complex data */ +user_count : t.length data.users; +/* Expected: 2 */ + +active_users : t.filter @identity data.active; +/* Expected: {1: true} */ + +/* ===== BACKWARD COMPATIBILITY TESTS ===== */ +/* Test that existing table operations still work */ +existing_table : {x: 1, y: 2, z: 3}; +existing_access : existing_table.x; +/* Expected: 1 */ + +existing_chained : {outer: {inner: {value: 42}}}; +chained_access : existing_chained.outer.inner.value; +/* Expected: 42 */ + +/* Test that existing map works with non-table values */ +existing_map_result : map @double 5; +/* Expected: 10 */ + +/* Test that existing reduce works with non-table values */ +existing_reduce_result : reduce @add 0 5; +/* Expected: 5 */ + +/* ===== PERFORMANCE AND STRESS TESTS ===== */ +/* Test with larger tables (for performance validation) */ +large_table : {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10}; +large_doubled : t.map @double large_table; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10, 6: 12, 7: 14, 8: 16, 9: 18, 10: 20} */ + +large_filtered : t.filter @isEven large_table; +/* Expected: {2: 2, 4: 4, 6: 6, 8: 8, 10: 10} */ + +large_reduced : t.reduce @sum 0 large_table; +/* Expected: 55 */ + +/* Test nested operations on large structures */ +large_nested : { + data1: large_table, + data2: large_table, + data3: large_table +}; + +large_nested_doubled : t.map (t.map @double) large_nested; +/* Expected: {data1: {1: 2, 2: 4, ...}, data2: {1: 2, 2: 4, ...}, data3: {1: 2, 2: 4, ...}} */ + +/* ===== ASSERTION VALIDATION TESTS ===== */ +/* Validate enhanced broadcasting results */ +..assert doubled.1 == 2; +..assert doubled.2 == 4; +..assert doubled.3 == 6; +..assert doubled.4 == 8; +..assert doubled.5 == 10; + +..assert squared.1 == 1; +..assert squared.2 == 4; +..assert squared.3 == 9; +..assert squared.4 == 16; +..assert squared.5 == 25; + +..assert type_check.a == true; +..assert type_check.b == false; +..assert type_check.c == false; +..assert type_check.d == true; + +/* Validate table-specific operations */ +..assert t_doubled.1 == 2; +..assert t_doubled.2 == 4; +..assert t_doubled.3 == 6; +..assert t_doubled.4 == 8; +..assert t_doubled.5 == 10; + +..assert even_numbers.2 == 2; +..assert even_numbers.4 == 4; +..assert t.has even_numbers 1 == false; +..assert t.has even_numbers 3 == false; + +..assert positive_numbers.1 == 1; +..assert positive_numbers.2 == 2; +..assert positive_numbers.3 == 3; +..assert positive_numbers.4 == 4; +..assert positive_numbers.5 == 5; + +..assert total == 15; +..assert maximum == 5; + +/* Validate immutable operations */ +..assert updated_person.age == 31; +..assert updated_person.name == "Alice"; +..assert updated_person.active == true; + +..assert added_city.city == "New York"; +..assert added_city.name == "Alice"; +..assert added_city.age == 30; + +..assert t.has without_age "age" == false; +..assert without_age.name == "Alice"; +..assert without_age.active == true; + +..assert without_nonexistent.name == "Alice"; +..assert without_nonexistent.age == 30; +..assert without_nonexistent.active == true; + +..assert merged.name == "Alice"; +..assert merged.age == 30; +..assert merged.active == true; +..assert merged.city == "New York"; +..assert merged.country == "USA"; + +..assert overwrite_merge.name == "Alice"; +..assert overwrite_merge.age == 25; +..assert overwrite_merge.active == true; +..assert overwrite_merge.city == "Boston"; + +/* Validate table information operations */ +..assert t.length all_pairs == 3; +..assert all_pairs[0][0] == "name"; +..assert all_pairs[0][1] == "Alice"; +..assert all_pairs[1][0] == "age"; +..assert all_pairs[1][1] == 30; +..assert all_pairs[2][0] == "active"; +..assert all_pairs[2][1] == true; + +..assert t.length all_keys == 3; +..assert all_keys[0] == "name"; +..assert all_keys[1] == "age"; +..assert all_keys[2] == "active"; + +..assert t.length all_values == 3; +..assert all_values[0] == "Alice"; +..assert all_values[1] == 30; +..assert all_values[2] == true; + +..assert table_size == 3; + +..assert has_name == true; +..assert has_email == false; + +..assert age_or_default == 30; +..assert email_or_default == "unknown"; + +/* Validate element-wise operations */ +..assert normal_add == 8; + +..assert each_result.1 == 11; +..assert each_result.2 == 12; +..assert each_result.3 == 13; +..assert each_result.4 == 14; +..assert each_result.5 == 15; + +..assert mixed_operation.1 == 11; +..assert mixed_operation.2 == 12; +..assert mixed_operation.3 == 13; +..assert mixed_operation.4 == 14; +..assert mixed_operation.5 == 15; + +..assert multi_table_sum.a == 11; +..assert multi_table_sum.b == 22; +..assert multi_table_sum.c == 33; + +..assert triple_sum.a == 111; +..assert triple_sum.b == 222; +..assert triple_sum.c == 333; + +..assert mixed_types.a == 6; +..assert mixed_types.b == 7; +..assert mixed_types.c == 8; + +..assert mixed_types2.a == 6; +..assert mixed_types2.b == 7; +..assert mixed_types2.c == 8; + +/* Validate nested table operations */ +..assert top_level_only.data.a == 1; +..assert top_level_only.data.b == 2; +..assert top_level_only.data.c == 3; +..assert top_level_only.meta.type == "numbers"; +..assert top_level_only.meta.count == 3; +..assert top_level_only.flags.active == true; +..assert top_level_only.flags.visible == false; + +..assert nested_doubled.data.a == 2; +..assert nested_doubled.data.b == 4; +..assert nested_doubled.data.c == 6; +..assert nested_doubled.meta.type == "numbers"; +..assert nested_doubled.meta.count == 3; +..assert nested_doubled.flags.active == true; +..assert nested_doubled.flags.visible == false; + +..assert nested_with_t_map.data.a == 2; +..assert nested_with_t_map.data.b == 4; +..assert nested_with_t_map.data.c == 6; +..assert nested_with_t_map.meta.type == "numbers"; +..assert nested_with_t_map.meta.count == 3; +..assert nested_with_t_map.flags.active == true; +..assert nested_with_t_map.flags.visible == false; + +..assert deep_doubled.level1.level2.level3.x == 2; +..assert deep_doubled.level1.level2.level3.y == 4; +..assert deep_doubled.level1.level2.level3.z == 6; + +..assert deep_with_t_map.level1.level2.level3.x == 2; +..assert deep_with_t_map.level1.level2.level3.y == 4; +..assert deep_with_t_map.level1.level2.level3.z == 6; + +/* Validate embedded functions */ +..assert calc_result == 8; +..assert calc_multiply == 28; +..assert calc_classify_zero == "zero"; +..assert calc_classify_one == "one"; +..assert calc_classify_other == "other"; + +/* Validate edge cases */ +..assert t.length empty_pairs == 0; +..assert t.length empty_keys == 0; +..assert t.length empty_values == 0; +..assert empty_length == 0; + +..assert safe_get == "default"; +..assert t.length safe_pairs == 0; + +..assert t.length boolean_keys == 2; +..assert boolean_keys[0] == true; +..assert boolean_keys[1] == false; + +..assert t.length boolean_values == 2; +..assert boolean_values[0] == "enabled"; +..assert boolean_values[1] == "disabled"; + +..assert t.length numeric_keys == 3; +..assert numeric_keys[0] == 1; +..assert numeric_keys[1] == 2; +..assert numeric_keys[2] == 3; + +/* Validate function composition */ +..assert transformed.1 == 2; +..assert transformed.2 == 4; +..assert transformed.3 == 6; +..assert transformed.4 == 8; +..assert transformed.5 == 10; + +..assert pipe_result.1 == 2; +..assert pipe_result.2 == 4; +..assert pipe_result.3 == 6; +..assert pipe_result.4 == 8; +..assert pipe_result.5 == 10; + +..assert each_with_functions.a == 2; +..assert each_with_functions.b == 4; +..assert each_with_functions.c == 6; + +..assert each_with_composition.a == 6; +..assert each_with_composition.b == 12; +..assert each_with_composition.c == 18; + +/* Validate complex data structures */ +..assert user_names.1 == "Alice"; +..assert user_names.2 == "Bob"; + +..assert user_count == 2; + +..assert active_users.1 == true; +..assert t.has active_users 2 == false; + +/* Validate backward compatibility */ +..assert existing_access == 1; +..assert chained_access == 42; +..assert existing_map_result == 10; +..assert existing_reduce_result == 5; + +/* Validate performance tests */ +..assert large_doubled.1 == 2; +..assert large_doubled.10 == 20; +..assert t.length large_doubled == 10; + +..assert large_filtered.2 == 2; +..assert large_filtered.4 == 4; +..assert large_filtered.6 == 6; +..assert large_filtered.8 == 8; +..assert large_filtered.10 == 10; +..assert t.length large_filtered == 5; + +..assert large_reduced == 55; + +..assert large_nested_doubled.data1.1 == 2; +..assert large_nested_doubled.data1.10 == 20; +..assert large_nested_doubled.data2.1 == 2; +..assert large_nested_doubled.data3.1 == 2; + +/* ===== OUTPUT ALL RESULTS ===== */ +..out "=== BASIC TABLE CREATION ==="; +..out "Numbers:"; +..out numbers; +..out "Person:"; +..out person; +..out "Mixed table:"; +..out mixed_table; + +..out "=== ENHANCED BROADCASTING ==="; +..out "Doubled numbers:"; +..out doubled; +..out "Squared numbers:"; +..out squared; +..out "Type check:"; +..out type_check; + +..out "=== TABLE-SPECIFIC OPERATIONS ==="; +..out "t.map doubled:"; +..out t_doubled; +..out "Even numbers:"; +..out even_numbers; +..out "Positive numbers:"; +..out positive_numbers; +..out "Sum total:"; +..out total; +..out "Maximum:"; +..out maximum; + +..out "=== IMMUTABLE OPERATIONS ==="; +..out "Updated person:"; +..out updated_person; +..out "Added city:"; +..out added_city; +..out "Without age:"; +..out without_age; +..out "Without nonexistent:"; +..out without_nonexistent; +..out "Merged:"; +..out merged; +..out "Overwrite merge:"; +..out overwrite_merge; + +..out "=== TABLE INFORMATION ==="; +..out "All pairs:"; +..out all_pairs; +..out "All keys:"; +..out all_keys; +..out "All values:"; +..out all_values; +..out "Table size:"; +..out table_size; +..out "Has name:"; +..out has_name; +..out "Has email:"; +..out has_email; +..out "Age or default:"; +..out age_or_default; +..out "Email or default:"; +..out email_or_default; + +..out "=== ELEMENT-WISE OPERATIONS ==="; +..out "Normal add:"; +..out normal_add; +..out "Each result:"; +..out each_result; +..out "Mixed operation:"; +..out mixed_operation; +..out "Multi-table sum:"; +..out multi_table_sum; +..out "Triple sum:"; +..out triple_sum; +..out "Mixed types:"; +..out mixed_types; +..out "Mixed types2:"; +..out mixed_types2; + +..out "=== NESTED TABLE OPERATIONS ==="; +..out "Top-level only:"; +..out top_level_only; +..out "Nested doubled:"; +..out nested_doubled; +..out "Nested with t.map:"; +..out nested_with_t_map; +..out "Deep doubled:"; +..out deep_doubled; +..out "Deep with t.map:"; +..out deep_with_t_map; + +..out "=== EMBEDDED FUNCTIONS ==="; +..out "Calculator add:"; +..out calc_result; +..out "Calculator multiply:"; +..out calc_multiply; +..out "Classify zero:"; +..out calc_classify_zero; +..out "Classify one:"; +..out calc_classify_one; +..out "Classify other:"; +..out calc_classify_other; + +..out "=== EDGE CASES ==="; +..out "Empty pairs:"; +..out empty_pairs; +..out "Empty keys:"; +..out empty_keys; +..out "Empty values:"; +..out empty_values; +..out "Empty length:"; +..out empty_length; +..out "Safe get:"; +..out safe_get; +..out "Safe pairs:"; +..out safe_pairs; + +..out "=== BOOLEAN AND NUMERIC KEYS ==="; +..out "Boolean keys:"; +..out boolean_keys; +..out "Boolean values:"; +..out boolean_values; +..out "Numeric keys:"; +..out numeric_keys; + +..out "=== FUNCTION COMPOSITION ==="; +..out "Transformed:"; +..out transformed; +..out "Pipe result:"; +..out pipe_result; +..out "Each with functions:"; +..out each_with_functions; +..out "Each with composition:"; +..out each_with_composition; + +..out "=== COMPLEX DATA STRUCTURES ==="; +..out "User names:"; +..out user_names; +..out "User count:"; +..out user_count; +..out "Active users:"; +..out active_users; + +..out "=== BACKWARD COMPATIBILITY ==="; +..out "Existing access:"; +..out existing_access; +..out "Chained access:"; +..out chained_access; +..out "Existing map result:"; +..out existing_map_result; +..out "Existing reduce result:"; +..out existing_reduce_result; + +..out "=== PERFORMANCE TESTS ==="; +..out "Large doubled:"; +..out large_doubled; +..out "Large filtered:"; +..out large_filtered; +..out "Large reduced:"; +..out large_reduced; +..out "Large nested doubled:"; +..out large_nested_doubled; + +/* ===== ERROR HANDLING TESTS ===== */ +/* These tests demonstrate expected error behavior */ +/* Uncomment individual lines to test specific error cases */ + +/* Type validation errors */ +/* tableSet_error : t.set "not_a_table" "key" "value"; */ +/* tableGet_error : t.get "not_a_table" "key"; */ +/* tableHas_error : t.has "not_a_table" "key"; */ +/* tableMerge_error : t.merge "not_a_table" person; */ + +/* Missing argument errors */ +/* tableSet_missing : t.set person "key"; */ +/* tableGet_missing : t.get person; */ +/* tableHas_missing : t.has person; */ + +/* Function validation errors */ +/* each_no_function : each "not_a_function" table1; */ +/* each_mixed_errors : each @add "string" table1; */ + +/* Null/undefined handling */ +/* null_table : t.set null "key" "value"; */ +/* undefined_key : t.get person undefined; */ + +/* ===== FINAL VALIDATION ===== */ +..assert "All table enhancement tests completed successfully!" == "All table enhancement tests completed successfully!"; + +..out "=== TEST COMPLETION ==="; +..out "All table enhancement tests completed successfully!"; +..out "All assertions passed!"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_enhancements_comprehensive.txt b/js/scripting-lang/scratch_tests/test_table_enhancements_comprehensive.txt new file mode 100644 index 0000000..1464224 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_enhancements_comprehensive.txt @@ -0,0 +1,90 @@ +/* Comprehensive test for table enhancements */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; +person : {name: "Alice", age: 30, active: true}; + +/* Test enhanced map */ +double : x -> x * 2; +doubled : map @double numbers; + +/* Test enhanced filter */ +isEven : x -> x % 2 == 0; +even_numbers : filter @isEven numbers; + +/* Test enhanced reduce */ +sum : x y -> x + y; +total : reduce @sum 0 numbers; + +/* Test t.map */ +t_doubled : t.map @double numbers; + +/* Test t.filter */ +t_even_numbers : t.filter @isEven numbers; + +/* Test t.reduce */ +t_total : t.reduce @sum 0 numbers; + +/* Test t.set */ +updated_person : t.set person "age" 31; + +/* Test t.delete */ +without_age : t.delete person "age"; + +/* Test t.merge */ +merged : t.merge person {city: "New York", country: "USA"}; + +/* Test t.pairs, t.keys, t.values, t.length */ +all_pairs : t.pairs person; +all_keys : t.keys person; +all_values : t.values person; +table_size : t.length person; + +/* Test t.has and t.get */ +has_name : t.has person "name"; +has_email : t.has person "email"; +age_or_default : t.get person "age" 0; +email_or_default : t.get person "email" "unknown"; + +/* Test function composition with tables */ +transform : compose @t.map @double @t.filter @isEven; +transformed : transform numbers; + +/* Output results */ +..out "=== COMPREHENSIVE TABLE ENHANCEMENTS ==="; +..out "Enhanced map:"; +..out doubled; +..out "Enhanced filter:"; +..out even_numbers; +..out "Enhanced reduce:"; +..out total; +..out "t.map:"; +..out t_doubled; +..out "t.filter:"; +..out t_even_numbers; +..out "t.reduce:"; +..out t_total; +..out "t.set:"; +..out updated_person; +..out "t.delete:"; +..out without_age; +..out "t.merge:"; +..out merged; +..out "t.pairs:"; +..out all_pairs; +..out "t.keys:"; +..out all_keys; +..out "t.values:"; +..out all_values; +..out "t.length:"; +..out table_size; +..out "t.has name:"; +..out has_name; +..out "t.has email:"; +..out has_email; +..out "t.get age:"; +..out age_or_default; +..out "t.get email:"; +..out email_or_default; +..out "Function composition:"; +..out transformed; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_enhancements_final.txt b/js/scripting-lang/scratch_tests/test_table_enhancements_final.txt new file mode 100644 index 0000000..79ae100 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_enhancements_final.txt @@ -0,0 +1,84 @@ +/* Final comprehensive test for table enhancements */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; +person : {name: "Alice", age: 30, active: true}; + +/* Test enhanced map */ +double : x -> x * 2; +doubled : map @double numbers; + +/* Test enhanced filter */ +isEven : x -> x % 2 == 0; +even_numbers : filter @isEven numbers; + +/* Test enhanced reduce */ +sum : x y -> x + y; +total : reduce @sum 0 numbers; + +/* Test t.map */ +t_doubled : t.map @double numbers; + +/* Test t.filter */ +t_even_numbers : t.filter @isEven numbers; + +/* Test t.reduce */ +t_total : t.reduce @sum 0 numbers; + +/* Test t.set */ +updated_person : t.set person "age" 31; + +/* Test t.delete */ +without_age : t.delete person "age"; + +/* Test t.merge */ +merged : t.merge person {city: "New York", country: "USA"}; + +/* Test t.pairs, t.keys, t.values, t.length */ +all_pairs : t.pairs person; +all_keys : t.keys person; +all_values : t.values person; +table_size : t.length person; + +/* Test t.has and t.get */ +has_name : t.has person "name"; +has_email : t.has person "email"; +age_or_default : t.get person "age" 0; +email_or_default : t.get person "email" "unknown"; + +/* Output results */ +..out "=== FINAL TABLE ENHANCEMENTS ==="; +..out "Enhanced map:"; +..out doubled; +..out "Enhanced filter:"; +..out even_numbers; +..out "Enhanced reduce:"; +..out total; +..out "t.map:"; +..out t_doubled; +..out "t.filter:"; +..out t_even_numbers; +..out "t.reduce:"; +..out t_total; +..out "t.set:"; +..out updated_person; +..out "t.delete:"; +..out without_age; +..out "t.merge:"; +..out merged; +..out "t.pairs:"; +..out all_pairs; +..out "t.keys:"; +..out all_keys; +..out "t.values:"; +..out all_values; +..out "t.length:"; +..out table_size; +..out "t.has name:"; +..out has_name; +..out "t.has email:"; +..out has_email; +..out "t.get age:"; +..out age_or_default; +..out "t.get email:"; +..out email_or_default; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_enhancements_minimal.txt b/js/scripting-lang/scratch_tests/test_table_enhancements_minimal.txt new file mode 100644 index 0000000..d8d4e02 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_enhancements_minimal.txt @@ -0,0 +1,18 @@ +/* Minimal test for table enhancements */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; + +/* Test enhanced map */ +double : x -> x * 2; +doubled : map @double numbers; + +/* Test t.map */ +t_doubled : t.map @double numbers; + +/* Output results */ +..out "=== MINIMAL TABLE ENHANCEMENTS ==="; +..out "Enhanced map:"; +..out doubled; +..out "t.map:"; +..out t_doubled; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_enhancements_working.txt b/js/scripting-lang/scratch_tests/test_table_enhancements_working.txt new file mode 100644 index 0000000..e73a6df --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_enhancements_working.txt @@ -0,0 +1,102 @@ +/* Test working table enhancements */ + +/* Basic table creation */ +numbers : {1, 2, 3, 4, 5}; +person : {name: "Alice", age: 30, active: true}; +table1 : {a: 1, b: 2, c: 3}; +table2 : {a: 10, b: 20, c: 30}; + +/* Test enhanced map (working) */ +double : x -> x * 2; +doubled : map @double numbers; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */ + +/* Test enhanced filter (working) */ +isEven : x -> x % 2 == 0; +even_numbers : filter @isEven numbers; +/* Expected: {2: 2, 4: 4} */ + +/* Test enhanced reduce (working) */ +sum : x y -> x + y; +total : reduce @sum 0 numbers; +/* Expected: 15 */ + +/* Test t.map (working) */ +t_doubled : t.map @double numbers; +/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */ + +/* Test t.filter (working) */ +t_even_numbers : t.filter @isEven numbers; +/* Expected: {2: 2, 4: 4} */ + +/* Test t.reduce (working) */ +t_total : t.reduce @sum 0 numbers; +/* Expected: 15 */ + +/* Test t.set (working) */ +updated_person : t.set person "age" 31; +/* Expected: {name: "Alice", age: 31, active: true} */ + +/* Test t.delete (working) */ +without_age : t.delete person "age"; +/* Expected: {name: "Alice", active: true} */ + +/* Test t.merge (working) */ +merged : t.merge person {city: "New York", country: "USA"}; +/* Expected: {name: "Alice", age: 30, active: true, city: "New York", country: "USA"} */ + +/* Test t.pairs, t.keys, t.values, t.length (working) */ +all_pairs : t.pairs person; +all_keys : t.keys person; +all_values : t.values person; +table_size : t.length person; + +/* Test t.has and t.get (working) */ +has_name : t.has person "name"; +has_email : t.has person "email"; +age_or_default : t.get person "age" 0; +email_or_default : t.get person "email" "unknown"; + +/* Test function composition with tables (working) */ +transform : compose @t.map @double @t.filter @isEven; +transformed : transform numbers; +/* Expected: {2: 4, 4: 8} */ + +/* Output results */ +..out "=== WORKING TABLE ENHANCEMENTS ==="; +..out "Enhanced map:"; +..out doubled; +..out "Enhanced filter:"; +..out even_numbers; +..out "Enhanced reduce:"; +..out total; +..out "t.map:"; +..out t_doubled; +..out "t.filter:"; +..out t_even_numbers; +..out "t.reduce:"; +..out t_total; +..out "t.set:"; +..out updated_person; +..out "t.delete:"; +..out without_age; +..out "t.merge:"; +..out merged; +..out "t.pairs:"; +..out all_pairs; +..out "t.keys:"; +..out all_keys; +..out "t.values:"; +..out all_values; +..out "t.length:"; +..out table_size; +..out "t.has name:"; +..out has_name; +..out "t.has email:"; +..out has_email; +..out "t.get age:"; +..out age_or_default; +..out "t.get email:"; +..out email_or_default; +..out "Function composition:"; +..out transformed; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_function.txt b/js/scripting-lang/scratch_tests/test_table_function.txt new file mode 100644 index 0000000..8e019b8 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_function.txt @@ -0,0 +1,11 @@ +/* Test function in table */ + +// Just create a table with a function +table : { + func: x -> x +}; + +// Test it +..out "=== TABLE FUNCTION TEST ==="; +result : table.func 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_structure.txt b/js/scripting-lang/scratch_tests/test_table_structure.txt new file mode 100644 index 0000000..fc122eb --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_structure.txt @@ -0,0 +1,16 @@ +/* Test table structure */ + +numbers : {1, 2, 3, 4, 5}; +first : numbers[1]; +second : numbers[2]; +..assert first = 1; +..assert second = 2; + +double : x -> x * 2; +doubled : map @double numbers; +doubled_first : doubled[1]; +doubled_second : doubled[2]; +..assert doubled_first = 2; +..assert doubled_second = 4; + +..out "Table structure test completed"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_unary_minus.txt b/js/scripting-lang/scratch_tests/test_unary_minus.txt new file mode 100644 index 0000000..18f6a29 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_unary_minus.txt @@ -0,0 +1,8 @@ +/* Test unary minus parsing */ +x : -5; +y : -3.14; +z : -0; + +..out x; +..out y; +..out z; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_unary_plus.txt b/js/scripting-lang/scratch_tests/test_unary_plus.txt new file mode 100644 index 0000000..66d978c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_unary_plus.txt @@ -0,0 +1,3 @@ +/* Unary minus followed by addition test */ +result : -5 + 3; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_when_debug.txt b/js/scripting-lang/scratch_tests/test_when_debug.txt new file mode 100644 index 0000000..3a5f9cf --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_when_debug.txt @@ -0,0 +1,11 @@ +/* Simple when expression test */ + +grade : score -> + when score is + 90 then "A" + 80 then "B" + 70 then "C" + _ then "F"; + +result : grade 95; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_when_in_table.txt b/js/scripting-lang/scratch_tests/test_when_in_table.txt new file mode 100644 index 0000000..6d3591f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_when_in_table.txt @@ -0,0 +1,13 @@ +/* Test when expression in table */ + +// Simple when expression +classifier : { + classify: x -> when x is + 0 then "zero" + _ then "other" +}; + +// Test it +..out "=== WHEN IN TABLE TEST ==="; +result : classifier.classify 0; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_when_in_table_simple.txt b/js/scripting-lang/scratch_tests/test_when_in_table_simple.txt new file mode 100644 index 0000000..7ac89fc --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_when_in_table_simple.txt @@ -0,0 +1,13 @@ +/* Simple when expression in table test */ + +// Test when expression in table +test : { + classify: x -> when x is + 0 then "zero" + _ then "other" +}; + +// Test it +..out "=== WHEN IN TABLE SIMPLE TEST ==="; +result : test.classify 0; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_when_simple.txt b/js/scripting-lang/scratch_tests/test_when_simple.txt new file mode 100644 index 0000000..3180d51 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_when_simple.txt @@ -0,0 +1,7 @@ +/* Test simple when expression */ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +..out "when expression created successfully"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_when_string_debug.txt b/js/scripting-lang/scratch_tests/test_when_string_debug.txt new file mode 100644 index 0000000..247d3c0 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_when_string_debug.txt @@ -0,0 +1,12 @@ +getFunction : type -> + when type is + "double" then @double + "square" then @square + _ then @add1; + +double : x -> x * 2; +square : x -> x * x; +add1 : x -> x + 1; + +result : getFunction "double"; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_working_cases.txt b/js/scripting-lang/scratch_tests/test_working_cases.txt new file mode 100644 index 0000000..80c4b63 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_working_cases.txt @@ -0,0 +1,11 @@ +/* Test working precedence cases */ + +test1 : 5 + 3; +test2 : -5; +test3 : 5 * -3; +test4 : (-5) + 3; + +..out test1; +..out test2; +..out test3; +..out test4; \ No newline at end of file |