diff options
Diffstat (limited to 'js/scripting-lang/scratch_tests')
189 files changed, 4817 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/fizzbuzz_explorations.txt b/js/scripting-lang/scratch_tests/fizzbuzz_explorations.txt new file mode 100644 index 0000000..fc6c7d1 --- /dev/null +++ b/js/scripting-lang/scratch_tests/fizzbuzz_explorations.txt @@ -0,0 +1,7 @@ +predicates : n -> apply @logicalAnd (equals (n % 3) 0) (equals (n % 5) 0); +fizzbuzz : n -> + when predicates n is + true then "FizzBuzz" + _ then n; + +..out fizzbuzz 100; diff --git a/js/scripting-lang/scratch_tests/flatten_scrap.txt b/js/scripting-lang/scratch_tests/flatten_scrap.txt new file mode 100644 index 0000000..e5d5c96 --- /dev/null +++ b/js/scripting-lang/scratch_tests/flatten_scrap.txt @@ -0,0 +1,25 @@ +/* Problem: Flatten nested tables */ +nested : { + level1: { + a: {value: 1}, + b: {value: 2} + }, + level2: { + c: {value: 3} + } +}; + +/* Recursive flattening function */ +flatten : table -> + when (t.has table "value") is + true then table + _ then reduce @t.merge {} (map @flatten_entry table); + +flatten_entry : entry -> + when (t.has entry "value") is + true then entry + _ then flatten entry; + +/* Apply flattening */ +flat : flatten nested; +/* Result: {a: {value: 1}, b: {value: 2}, c: {value: 3}} */ 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_and_negative.txt b/js/scripting-lang/scratch_tests/test_and_negative.txt new file mode 100644 index 0000000..7aafd24 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_and_negative.txt @@ -0,0 +1,6 @@ +/* Test and operator with negative numbers */ + +/* Test the problematic expression */ +result1 : (-5 >= 0) and (-5 <= 120); + +..out result1; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_and_negative_fixed.txt b/js/scripting-lang/scratch_tests/test_and_negative_fixed.txt new file mode 100644 index 0000000..f10bd9b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_and_negative_fixed.txt @@ -0,0 +1,14 @@ +/* Test and operator with negative numbers - fixed syntax */ + +/* Test with proper parentheses */ +result1 : ((-5) >= 0) and ((-5) <= 120); + +/* Test step by step */ +step1 : (-5) >= 0; +step2 : (-5) <= 120; +result2 : step1 and step2; + +..out result1; +..out step1; +..out step2; +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_and_operator.txt b/js/scripting-lang/scratch_tests/test_and_operator.txt new file mode 100644 index 0000000..b4624ff --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_and_operator.txt @@ -0,0 +1,13 @@ +/* Test the and operator in complex expressions */ + +/* Test the complex expression directly */ +test_expr : age -> age >= 0 and age <= 120; + +/* Test with different values */ +result1 : test_expr 30; /* Should be true */ +result2 : test_expr 150; /* Should be false */ +result3 : test_expr -5; /* Should be false */ + +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_and_operator_simple.txt b/js/scripting-lang/scratch_tests/test_and_operator_simple.txt new file mode 100644 index 0000000..7d12e77 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_and_operator_simple.txt @@ -0,0 +1,26 @@ +/* Test and operator as infix operator */ + +/* Simple boolean values */ +true_val : true; +false_val : false; + +/* Test and operator with simple values */ +result1 : true_val and false_val; +result2 : false_val and true_val; +result3 : true_val and true_val; + +/* Test with comparisons */ +comp1 : (-5) >= 0; /* false */ +comp2 : (-5) <= 120; /* true */ +result4 : comp1 and comp2; /* false and true = false */ + +/* Test the original problematic expression */ +original : (-5 >= 0) and (-5 <= 120); + +..out result1; +..out result2; +..out result3; +..out comp1; +..out comp2; +..out result4; +..out original; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_and_parentheses.txt b/js/scripting-lang/scratch_tests/test_and_parentheses.txt new file mode 100644 index 0000000..f799e63 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_and_parentheses.txt @@ -0,0 +1,13 @@ +/* Test if parentheses can solve the and operator issue */ + +/* Test the complex expression with parentheses */ +test_expr_parens : age -> (age >= 0) and (age <= 120); + +/* Test with different values */ +result1 : test_expr_parens 30; /* Should be true */ +result2 : test_expr_parens 150; /* Should be false */ +result3 : test_expr_parens -5; /* Should be false */ + +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_and_simple.txt b/js/scripting-lang/scratch_tests/test_and_simple.txt new file mode 100644 index 0000000..c68d4c5 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_and_simple.txt @@ -0,0 +1,8 @@ +/* Test very simple and expression */ + +/* Test basic and */ +result1 : 1 and 1; +result2 : 1 and 0; + +..out result1; +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_ast_debug.txt b/js/scripting-lang/scratch_tests/test_ast_debug.txt new file mode 100644 index 0000000..e8a764c --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_ast_debug.txt @@ -0,0 +1,11 @@ +/* Debug test for AST structure */ +is_even : n -> n % 2 = 0; + +test_debug : n -> + when n is + is_even n then "should not match" + 4 then "four" + _ then "other"; + +result : test_debug 4; +..out result; \ 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_available_functions.txt b/js/scripting-lang/scratch_tests/test_available_functions.txt new file mode 100644 index 0000000..0274711 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_available_functions.txt @@ -0,0 +1,26 @@ +/* Test to see what functions are available */ + +/* Test basic arithmetic */ +result1 : 5 + 3; +..out "5 + 3:"; +..out result1; + +/* Test basic comparison */ +result2 : 5 = 3; +..out "5 = 3:"; +..out result2; + +result3 : 5 = 5; +..out "5 = 5:"; +..out result3; + +/* Test function definition */ +double : x -> x * 2; +result4 : double 5; +..out "double 5:"; +..out result4; + +/* Test table creation */ +table : {1, 2, 3}; +..out "table:"; +..out table; \ 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_bool_debug.txt b/js/scripting-lang/scratch_tests/test_bool_debug.txt new file mode 100644 index 0000000..8f05705 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_bool_debug.txt @@ -0,0 +1,15 @@ +/* Test boolean pattern matching more thoroughly */ + +/* Test with direct boolean values */ +test1 : when true is + true then "true matched" + false then "false matched" + _ then "wildcard matched"; + +test2 : when false is + true then "true matched" + false then "false matched" + _ then "wildcard matched"; + +..out test1; +..out test2; \ 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_debug.txt b/js/scripting-lang/scratch_tests/test_comparison_debug.txt new file mode 100644 index 0000000..c2d442e --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_comparison_debug.txt @@ -0,0 +1,10 @@ +/* Debug test for comparison logic */ +is_even : n -> n % 2 = 0; + +test_debug : n -> + when (is_even n) is + true then "even" + false then "odd"; + +result : test_debug 4; +..out result; \ 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_expr_debug.txt b/js/scripting-lang/scratch_tests/test_complex_expr_debug.txt new file mode 100644 index 0000000..0ca7265 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_complex_expr_debug.txt @@ -0,0 +1,16 @@ +/* Test complex expression in multi-value pattern */ + +/* Test the complex expression directly */ +test_expr : age -> age >= 0 and age <= 120; + +/* Test with complex expression */ +validate_user : name age -> + when (name != "") (test_expr age) is + true true then "valid user" + true false then "invalid age" + false true then "invalid name" + false false then "invalid user"; + +/* Test user validation */ +valid_user : validate_user "Alice" 30; +..out valid_user; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_complex_func_debug.txt b/js/scripting-lang/scratch_tests/test_complex_func_debug.txt new file mode 100644 index 0000000..dacb3ca --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_complex_func_debug.txt @@ -0,0 +1,13 @@ +/* Test complex validation function directly */ + +/* Complex function for testing */ +complex_validation : x y -> (x > 0) and (y > 0) and (x + y > 10); + +/* Test the function directly */ +test1 : complex_validation 5 8; /* Should be true */ +test2 : complex_validation 0 8; /* Should be false */ +test3 : complex_validation 5 3; /* Should be false */ + +..out test1; +..out test2; +..out test3; \ 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_complex_validation_debug.txt b/js/scripting-lang/scratch_tests/test_complex_validation_debug.txt new file mode 100644 index 0000000..7c22dad --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_complex_validation_debug.txt @@ -0,0 +1,21 @@ +/* Test complex validation part */ + +/* Complex function for testing */ +complex_validation : x y -> (x > 0) and (y > 0) and (x + y > 10); + +/* Using complex function in pattern */ +validate_pair : x y -> + when (complex_validation x y) is + true then "valid pair" + false then "invalid pair"; + +/* Test complex validation */ +valid_pair : validate_pair 5 8; /* 5>0, 8>0, 5+8>10 -> true */ +invalid_pair1 : validate_pair 0 8; /* 0>0 is false */ +invalid_pair2 : validate_pair 5 3; /* 5+3>10 is false */ + +/* Output complex validation results */ +..out "Complex Validation Results:"; +..out valid_pair; +..out invalid_pair1; +..out invalid_pair2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_complex_validation_only.txt b/js/scripting-lang/scratch_tests/test_complex_validation_only.txt new file mode 100644 index 0000000..d4e0a4a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_complex_validation_only.txt @@ -0,0 +1,14 @@ +/* Test just the complex validation part */ + +/* Complex function for testing */ +complex_validation : x y -> (x > 0) and (y > 0) and (x + y > 10); + +/* Using complex function in pattern */ +validate_pair : x y -> + when (complex_validation x y) is + true then "valid pair" + false then "invalid pair"; + +/* Test complex validation */ +valid_pair : validate_pair 5 8; +..out valid_pair; \ 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_control_only.txt b/js/scripting-lang/scratch_tests/test_control_only.txt new file mode 100644 index 0000000..5e4cc77 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_control_only.txt @@ -0,0 +1,25 @@ +/* Control tests that should work */ +test_simple : n -> + when n is + 0 then "zero" + 1 then "one" + _ then "other"; + +test_single_expr : n -> + when (n % 3) is + 0 then "divisible by 3" + _ then "not divisible by 3"; + +test_multi_simple : x y -> + when x y is + 0 0 then "both zero" + 0 _ then "x zero" + _ 0 then "y zero" + _ _ then "neither zero"; + +result1 : test_simple 5; +result2 : test_single_expr 15; +result3 : test_multi_simple 0 5; +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_coord_debug.txt b/js/scripting-lang/scratch_tests/test_coord_debug.txt new file mode 100644 index 0000000..8ef62d1 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_coord_debug.txt @@ -0,0 +1,13 @@ +/* Test complex coordinate classification */ + +/* Complex coordinate classification */ +classify_coordinates : x y -> + when ((x + 1) % 2) ((y - 1) % 2) is + 0 0 then "both transformed even" + 0 1 then "x transformed even, y transformed odd" + 1 0 then "x transformed odd, y transformed even" + 1 1 then "both transformed odd"; + +/* Test coordinate classification */ +coord1 : classify_coordinates 1 1; +..out coord1; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_coord_only.txt b/js/scripting-lang/scratch_tests/test_coord_only.txt new file mode 100644 index 0000000..390e843 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_coord_only.txt @@ -0,0 +1,13 @@ +/* Test just the complex coordinate classification */ + +/* Complex coordinate classification */ +classify_coordinates : x y -> + when ((x + 1) % 2) ((y - 1) % 2) is + 0 0 then "both transformed even" + 0 1 then "x transformed even, y transformed odd" + 1 0 then "x transformed odd, y transformed even" + 1 1 then "both transformed odd"; + +/* Test coordinate classification */ +coord1 : classify_coordinates 1 1; +..out coord1; \ 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_enhanced_case.txt b/js/scripting-lang/scratch_tests/test_debug_enhanced_case.txt new file mode 100644 index 0000000..2090669 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_enhanced_case.txt @@ -0,0 +1,19 @@ +/* Debug test for enhanced case statements */ + +/* Simple test first */ +mod3 : n -> n % 3; +mod5 : n -> n % 5; +is_zero : x -> x = 0; + +/* Test basic function calls */ +test1 : mod3 15; +test2 : mod5 15; +test3 : is_zero 0; + +..out test1; +..out test2; +..out test3; + +/* Test table with function calls */ +test_table : {mod3 15, mod5 15}; +..out test_table; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_equals.txt b/js/scripting-lang/scratch_tests/test_debug_equals.txt new file mode 100644 index 0000000..da3e0cd --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_equals.txt @@ -0,0 +1,26 @@ +/* Debug test for equals function */ + +/* Test equals directly */ +result1 : equals 5 3; +..out "equals 5 3:"; +..out result1; + +result2 : equals 0 0; +..out "equals 0 0:"; +..out result2; + +/* Test is_zero function */ +is_zero : x -> equals x 0; +result3 : is_zero 0; +..out "is_zero 0:"; +..out result3; + +result4 : is_zero 5; +..out "is_zero 5:"; +..out result4; + +/* Test map with is_zero */ +test_values : {0, 1, 2}; +zero_test : map @is_zero test_values; +..out "map @is_zero {0, 1, 2}:"; +..out zero_test; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_func_call.txt b/js/scripting-lang/scratch_tests/test_debug_func_call.txt new file mode 100644 index 0000000..5b3ae21 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_func_call.txt @@ -0,0 +1,13 @@ +/* Debug test for function calls */ +is_even : n -> n % 2 = 0; + +test_debug : n -> + when n is + 0 then "zero" + 1 then "one" + _ then "other"; + +result1 : test_debug 0; +result2 : is_even 4; +..out result1; +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_func_call_when.txt b/js/scripting-lang/scratch_tests/test_debug_func_call_when.txt new file mode 100644 index 0000000..8132d0b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_func_call_when.txt @@ -0,0 +1,17 @@ +/* Debug test for function calls in when expressions */ +is_even : n -> n % 2 = 0; + +test_debug : n -> + when is_even n is + true then "even" + false then "odd"; + +/* Test the function call separately */ +result1 : is_even 4; +result2 : is_even 5; + +/* Test the when expression */ +result3 : test_debug 4; +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_debug_map.txt b/js/scripting-lang/scratch_tests/test_debug_map.txt new file mode 100644 index 0000000..7d178f2 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_debug_map.txt @@ -0,0 +1,27 @@ +/* Debug test for map function */ + +/* Test basic map functionality */ +double : x -> x * 2; +numbers : {1, 2, 3}; +doubled : map @double numbers; +..out "Doubled numbers:"; +..out doubled; + +/* Test map with equals */ +is_zero : x -> equals x 0; +test_values : {0, 1, 2}; +zero_test : map @is_zero test_values; +..out "Zero test:"; +..out zero_test; + +/* Test with our specific case */ +mod3 : n -> n % 3; +mod5 : n -> n % 5; +div_15 : {mod3 15, mod5 15}; +..out "Div 15:"; +..out div_15; + +divisibility : n -> map @is_zero {mod3 n, mod5 n}; +result : divisibility 15; +..out "Divisibility result:"; +..out result; \ 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_direct_verification.txt b/js/scripting-lang/scratch_tests/test_direct_verification.txt new file mode 100644 index 0000000..6302c05 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_direct_verification.txt @@ -0,0 +1,63 @@ +/* Direct verification test for enhanced case statements */ + +/* Test 1: Basic table creation */ +basic : {1, 2, 3}; +..out "Basic table:"; +..out basic; + +/* Test 2: Auto-indexed table with expressions */ +/* Work around parser limitation by using variables */ +a : 5 % 3; +b : 5 % 5; +expr : {a, b}; +..out "Expression table:"; +..out expr; + +/* Test 3: Map with equals 0 */ +/* Work around parser limitation by using variables */ +c : 15 % 3; +d : 15 % 5; +is_zero : x -> equals x 0; +mapped : map @is_zero {c, d}; +..out "Mapped table:"; +..out mapped; + +/* Test 4: Simple table pattern matching */ +test_table : {1: true, 2: false}; +result : when test_table is + {1: true, 2: true} then "both true" + {1: true, 2: false} then "first true" + {1: false, 2: true} then "second true" + {1: false, 2: false} then "both false"; +..out "Pattern match result:"; +..out result; + +/* Test 5: FizzBuzz divisibility function */ +/* Work around parser limitation by using a helper function */ +mod3 : n -> n % 3; +mod5 : n -> n % 5; +is_zero : x -> equals x 0; +divisibility : n -> map @is_zero {mod3 n, mod5 n}; + +div_15 : divisibility 15; +..out "Divisibility for 15:"; +..out div_15; + +/* Test 6: Complete FizzBuzz */ +fizzbuzz : n -> + when divisibility n is + {1: true, 2: true} then "FizzBuzz" + {1: true, 2: false} then "Fizz" + {1: false, 2: true} then "Buzz" + {1: false, 2: false} then n; + +fizz_15 : fizzbuzz 15; +fizz_3 : fizzbuzz 3; +fizz_5 : fizzbuzz 5; +fizz_7 : fizzbuzz 7; + +..out "FizzBuzz results:"; +..out "15: " + fizz_15; +..out "3: " + fizz_3; +..out "5: " + fizz_5; +..out "7: " + fizz_7; \ 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_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_case_final.txt b/js/scripting-lang/scratch_tests/test_enhanced_case_final.txt new file mode 100644 index 0000000..4551122 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_enhanced_case_final.txt @@ -0,0 +1,62 @@ +/* Final verification test for enhanced case statements */ + +/* Test 1: Basic table creation */ +basic : {1, 2, 3}; +..out "Basic table:"; +..out basic; + +/* Test 2: Auto-indexed table with expressions */ +/* Work around parser limitation by using variables */ +a : 5 % 3; +b : 5 % 5; +expr : {a, b}; +..out "Expression table:"; +..out expr; + +/* Test 3: Map with equals 0 */ +/* Work around parser limitation by using variables */ +c : 15 % 3; +d : 15 % 5; +is_zero : x -> x = 0; +mapped : map @is_zero {c, d}; +..out "Mapped table:"; +..out mapped; + +/* Test 4: Simple table pattern matching */ +test_table : {1: true, 2: false}; +result : when test_table is + {1: true, 2: true} then "both true" + {1: true, 2: false} then "first true" + {1: false, 2: true} then "second true" + {1: false, 2: false} then "both false"; +..out "Pattern match result:"; +..out result; + +/* Test 5: FizzBuzz divisibility function */ +/* Work around parser limitation by using a helper function */ +mod3 : n -> n % 3; +mod5 : n -> n % 5; +divisibility : n -> map @is_zero {mod3 n, mod5 n}; + +div_15 : divisibility 15; +..out "Divisibility for 15:"; +..out div_15; + +/* Test 6: Complete FizzBuzz */ +fizzbuzz : n -> + when divisibility n is + {1: true, 2: true} then "FizzBuzz" + {1: true, 2: false} then "Fizz" + {1: false, 2: true} then "Buzz" + {1: false, 2: false} then n; + +fizz_15 : fizzbuzz 15; +fizz_3 : fizzbuzz 3; +fizz_5 : fizzbuzz 5; +fizz_7 : fizzbuzz 7; + +..out "FizzBuzz results:"; +..out "15: " + fizz_15; +..out "3: " + fizz_3; +..out "5: " + fizz_5; +..out "7: " + fizz_7; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_enhanced_case_verification.txt b/js/scripting-lang/scratch_tests/test_enhanced_case_verification.txt new file mode 100644 index 0000000..011a433 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_enhanced_case_verification.txt @@ -0,0 +1,229 @@ +/* Enhanced Case Statement Verification Tests */ +/* Testing core assumptions for FizzBuzz and tuple-like pattern matching */ + +/* ===== TEST 1: AUTO-INDEXED TABLE CREATION ===== */ +..out "=== TEST 1: AUTO-INDEXED TABLE CREATION ==="; + +/* Test basic auto-indexed table */ +basic_table : {1, 2, 3}; +..out "Basic table:"; +..out basic_table; + +/* Test auto-indexed table with expressions */ +expr_table : {5 % 3, 5 % 5, 5 % 2}; +..out "Expression table (5 % 3, 5 % 5, 5 % 2):"; +..out expr_table; + +/* Test with FizzBuzz-style expressions */ +n : 15; +fizzbuzz_expr : {n % 3, n % 5}; +..out "FizzBuzz expressions for n=15:"; +..out fizzbuzz_expr; + +/* ===== TEST 2: MAP WITH TABLE TRANSFORMATION ===== */ +..out "=== TEST 2: MAP WITH TABLE TRANSFORMATION ==="; + +/* Test map with equals 0 */ +test_map : map @(equals 0) {15 % 3, 15 % 5}; +..out "Map equals 0 on {15 % 3, 15 % 5}:"; +..out test_map; + +/* Test with different numbers */ +test_map_3 : map @(equals 0) {3 % 3, 3 % 5}; +..out "Map equals 0 on {3 % 3, 3 % 5}:"; +..out test_map_3; + +test_map_5 : map @(equals 0) {5 % 3, 5 % 5}; +..out "Map equals 0 on {5 % 3, 5 % 5}:"; +..out test_map_5; + +test_map_7 : map @(equals 0) {7 % 3, 7 % 5}; +..out "Map equals 0 on {7 % 3, 7 % 5}:"; +..out test_map_7; + +/* ===== TEST 3: TABLE PATTERN MATCHING ===== */ +..out "=== TEST 3: TABLE PATTERN MATCHING ==="; + +/* Test simple table pattern matching */ +simple_table : {1: true, 2: false}; +simple_result : when simple_table is + {1: true, 2: true} then "both true" + {1: true, 2: false} then "first true" + {1: false, 2: true} then "second true" + {1: false, 2: false} then "both false"; +..out "Simple table pattern matching:"; +..out simple_result; + +/* Test with actual FizzBuzz-style data */ +fizzbuzz_data : {1: true, 2: true}; +fizzbuzz_result : when fizzbuzz_data is + {1: true, 2: true} then "FizzBuzz" + {1: true, 2: false} then "Fizz" + {1: false, 2: true} then "Buzz" + {1: false, 2: false} then "neither"; +..out "FizzBuzz-style pattern matching:"; +..out fizzbuzz_result; + +/* Test with different combinations */ +fizz_data : {1: true, 2: false}; +fizz_result : when fizz_data is + {1: true, 2: true} then "FizzBuzz" + {1: true, 2: false} then "Fizz" + {1: false, 2: true} then "Buzz" + {1: false, 2: false} then "neither"; +..out "Fizz pattern matching:"; +..out fizz_result; + +/* ===== TEST 4: INTEGRATED FIZZBUZZ TEST ===== */ +..out "=== TEST 4: INTEGRATED FIZZBUZZ TEST ==="; + +/* Create the divisibility function */ +divisibility : n -> map @(equals 0) {n % 3, n % 5}; + +/* Test the function with different inputs */ +div_15 : divisibility 15; +div_3 : divisibility 3; +div_5 : divisibility 5; +div_7 : divisibility 7; + +..out "Divisibility results:"; +..out "15: " + div_15; +..out "3: " + div_3; +..out "5: " + div_5; +..out "7: " + div_7; + +/* Test the complete FizzBuzz function */ +fizzbuzz : n -> + when divisibility n is + {1: true, 2: true} then "FizzBuzz" + {1: true, 2: false} then "Fizz" + {1: false, 2: true} then "Buzz" + {1: false, 2: false} then n; + +/* Test FizzBuzz with various inputs */ +..out "FizzBuzz results:"; +..out "fizzbuzz 15: " + fizzbuzz 15; +..out "fizzbuzz 3: " + fizzbuzz 3; +..out "fizzbuzz 5: " + fizzbuzz 5; +..out "fizzbuzz 7: " + fizzbuzz 7; +..out "fizzbuzz 0: " + fizzbuzz 0; +..out "fizzbuzz 1: " + fizzbuzz 1; + +/* ===== TEST 5: ALTERNATIVE APPROACHES ===== */ +..out "=== TEST 5: ALTERNATIVE APPROACHES ==="; + +/* Option A: Multiple value patterns */ +fizzbuzz_option_a : n -> + when (equals (n % 3) 0) (equals (n % 5) 0) is + true true then "FizzBuzz" + true false then "Fizz" + false true then "Buzz" + false false then n; + +..out "Option A (multiple value patterns):"; +..out "fizzbuzz_option_a 15: " + fizzbuzz_option_a 15; +..out "fizzbuzz_option_a 3: " + fizzbuzz_option_a 3; +..out "fizzbuzz_option_a 5: " + fizzbuzz_option_a 5; +..out "fizzbuzz_option_a 7: " + fizzbuzz_option_a 7; + +/* Option B: Predicate functions with nested when */ +is_fizzbuzz : n -> apply @logicalAnd (equals (n % 3) 0) (equals (n % 5) 0); +is_fizz : n -> equals (n % 3) 0; +is_buzz : n -> equals (n % 5) 0; + +fizzbuzz_option_b : n -> + when is_fizzbuzz n is + true then "FizzBuzz" + _ then when is_fizz n is + true then "Fizz" + _ then when is_buzz n is + true then "Buzz" + _ then n; + +..out "Option B (predicate functions):"; +..out "fizzbuzz_option_b 15: " + fizzbuzz_option_b 15; +..out "fizzbuzz_option_b 3: " + fizzbuzz_option_b 3; +..out "fizzbuzz_option_b 5: " + fizzbuzz_option_b 5; +..out "fizzbuzz_option_b 7: " + fizzbuzz_option_b 7; + +/* ===== TEST 6: EDGE CASES AND ERROR CONDITIONS ===== */ +..out "=== TEST 6: EDGE CASES AND ERROR CONDITIONS ==="; + +/* Test with negative numbers */ +..out "Negative numbers:"; +..out "fizzbuzz -3: " + fizzbuzz -3; +..out "fizzbuzz -5: " + fizzbuzz -5; +..out "fizzbuzz -15: " + fizzbuzz -15; + +/* Test with large numbers */ +..out "Large numbers:"; +..out "fizzbuzz 30: " + fizzbuzz 30; +..out "fizzbuzz 45: " + fizzbuzz 45; +..out "fizzbuzz 60: " + fizzbuzz 60; + +/* ===== TEST 7: PERFORMANCE AND COMPLEXITY ===== */ +..out "=== TEST 7: PERFORMANCE AND COMPLEXITY ==="; + +/* Test with a range of numbers */ +test_range : 1; +test_result : fizzbuzz test_range; +..out "Range test (1-20):"; +..out "1: " + test_result; + +test_range : 2; +test_result : fizzbuzz test_range; +..out "2: " + test_result; + +test_range : 3; +test_result : fizzbuzz test_range; +..out "3: " + test_result; + +test_range : 4; +test_result : fizzbuzz test_range; +..out "4: " + test_result; + +test_range : 5; +test_result : fizzbuzz test_range; +..out "5: " + test_result; + +test_range : 6; +test_result : fizzbuzz test_range; +..out "6: " + test_result; + +test_range : 7; +test_result : fizzbuzz test_range; +..out "7: " + test_result; + +test_range : 8; +test_result : fizzbuzz test_range; +..out "8: " + test_result; + +test_range : 9; +test_result : fizzbuzz test_range; +..out "9: " + test_result; + +test_range : 10; +test_result : fizzbuzz test_range; +..out "10: " + test_result; + +test_range : 11; +test_result : fizzbuzz test_range; +..out "11: " + test_result; + +test_range : 12; +test_result : fizzbuzz test_range; +..out "12: " + test_result; + +test_range : 13; +test_result : fizzbuzz test_range; +..out "13: " + test_result; + +test_range : 14; +test_result : fizzbuzz test_range; +..out "14: " + test_result; + +test_range : 15; +test_result : fizzbuzz test_range; +..out "15: " + test_result; + +..out "=== VERIFICATION COMPLETE ==="; \ 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_enhanced_debug.txt b/js/scripting-lang/scratch_tests/test_enhanced_debug.txt new file mode 100644 index 0000000..5462858 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_enhanced_debug.txt @@ -0,0 +1,13 @@ +/* Simple test to debug enhanced case statements */ + +/* Test 1: Basic FizzBuzz */ +fizzbuzz : n -> + when (n % 3) (n % 5) is + 0 0 then "FizzBuzz" + 0 _ then "Fizz" + _ 0 then "Buzz" + _ _ then n; + +/* Test basic FizzBuzz */ +result1 : fizzbuzz 15; +..out result1; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_equals_function.txt b/js/scripting-lang/scratch_tests/test_equals_function.txt new file mode 100644 index 0000000..91e90fd --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_equals_function.txt @@ -0,0 +1,17 @@ +/* Test equals function */ + +/* Test basic equals */ +test1 : equals 5 5; +test2 : equals 5 3; +test3 : equals 0 0; + +..out test1; +..out test2; +..out test3; + +/* Test equals with modulo */ +test4 : equals (15 % 3) 0; +test5 : equals (15 % 5) 0; + +..out test4; +..out test5; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_exact_expr_debug.txt b/js/scripting-lang/scratch_tests/test_exact_expr_debug.txt new file mode 100644 index 0000000..8a6b3c5 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_exact_expr_debug.txt @@ -0,0 +1,13 @@ +/* Test exact expression from test file */ + +/* Multi-field validation using function calls */ +validate_user : name age -> + when (name != "") (age >= 0 and age <= 120) is + true true then "valid user" + true false then "invalid age" + false true then "invalid name" + false false then "invalid user"; + +/* Test user validation */ +valid_user : validate_user "Alice" 30; +..out valid_user; \ 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_first_part.txt b/js/scripting-lang/scratch_tests/test_first_part.txt new file mode 100644 index 0000000..61b2da1 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_first_part.txt @@ -0,0 +1,48 @@ +/* Test first part of enhanced case statements */ + +/* ===== FIZZBUZZ IMPLEMENTATION ===== */ + +/* Classic FizzBuzz using multi-value patterns with expressions */ +fizzbuzz : n -> + when (n % 3) (n % 5) is + 0 0 then "FizzBuzz" + 0 _ then "Fizz" + _ 0 then "Buzz" + _ _ then n; + +/* Test FizzBuzz implementation */ +fizzbuzz_15 : fizzbuzz 15; /* Should be "FizzBuzz" */ +fizzbuzz_3 : fizzbuzz 3; /* Should be "Fizz" */ +fizzbuzz_5 : fizzbuzz 5; /* Should be "Buzz" */ +fizzbuzz_7 : fizzbuzz 7; /* Should be 7 */ + +/* ===== TABLE ACCESS IN WHEN EXPRESSIONS ===== */ + +/* User data for testing */ +admin_user : {role: "admin", level: 5, name: "Alice"}; +user_user : {role: "user", level: 2, name: "Bob"}; +guest_user : {role: "guest", level: 0, name: "Charlie"}; + +/* Access control using table access in patterns */ +access_level : user -> + when user.role is + "admin" then "full access" + "user" then "limited access" + _ then "no access"; + +/* Test access control */ +admin_access : access_level admin_user; +user_access : access_level user_user; +guest_access : access_level guest_user; + +/* Output results */ +..out "FizzBuzz Results:"; +..out fizzbuzz_15; +..out fizzbuzz_3; +..out fizzbuzz_5; +..out fizzbuzz_7; + +..out "Access Control Results:"; +..out admin_access; +..out user_access; +..out guest_access; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_fizzbuzz.txt b/js/scripting-lang/scratch_tests/test_fizzbuzz.txt new file mode 100644 index 0000000..2529b73 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_fizzbuzz.txt @@ -0,0 +1,16 @@ +/* Test FizzBuzz-style patterns */ +fizzbuzz_test : n -> + when (n % 3) (n % 5) is + 0 0 then "FizzBuzz" + 0 _ then "Fizz" + _ 0 then "Buzz" + _ _ then n; + +result1 : fizzbuzz_test 15; +result2 : fizzbuzz_test 3; +result3 : fizzbuzz_test 5; +result4 : fizzbuzz_test 7; +..out result1; +..out result2; +..out result3; +..out result4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_fizzbuzz_only.txt b/js/scripting-lang/scratch_tests/test_fizzbuzz_only.txt new file mode 100644 index 0000000..2fd12ad --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_fizzbuzz_only.txt @@ -0,0 +1,13 @@ +/* Test just the FizzBuzz part */ + +/* Classic FizzBuzz using multi-value patterns with expressions */ +fizzbuzz : n -> + when (n % 3) (n % 5) is + 0 0 then "FizzBuzz" + 0 _ then "Fizz" + _ 0 then "Buzz" + _ _ then n; + +/* Test FizzBuzz implementation */ +fizzbuzz_15 : fizzbuzz 15; +..out fizzbuzz_15; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_call_debug.txt b/js/scripting-lang/scratch_tests/test_func_call_debug.txt new file mode 100644 index 0000000..33f39a7 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_call_debug.txt @@ -0,0 +1,22 @@ +/* Debug test for function call evaluation */ +is_even : n -> n % 2 = 0; + +test_debug : n -> + when is_even n is + true then "even" + false then "odd"; + +/* Test the function call separately */ +result1 : is_even 4; +result2 : is_even 5; + +/* Test with explicit boolean comparison */ +test_explicit : n -> + when (is_even n = true) is + true then "even" + false then "odd"; + +result3 : test_explicit 4; +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_call_debug2.txt b/js/scripting-lang/scratch_tests/test_func_call_debug2.txt new file mode 100644 index 0000000..e272479 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_call_debug2.txt @@ -0,0 +1,11 @@ +/* Debug test for function call evaluation in patterns */ +is_even : n -> n % 2 = 0; + +test_debug : n -> + when n is + is_even n then "function call result" + 4 then "four" + _ then "other"; + +result : test_debug 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_call_only.txt b/js/scripting-lang/scratch_tests/test_func_call_only.txt new file mode 100644 index 0000000..b5bdf75 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_call_only.txt @@ -0,0 +1,10 @@ +/* Function call test */ +is_even : n -> n % 2 = 0; + +test_func_call : n -> + when is_even n is + true then "even number" + false then "odd number"; + +result : test_func_call 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_call_original.txt b/js/scripting-lang/scratch_tests/test_func_call_original.txt new file mode 100644 index 0000000..0d4e8d0 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_call_original.txt @@ -0,0 +1,10 @@ +/* Test the original failing case */ +is_even : n -> n % 2 = 0; + +test_original : n -> + when is_even n is + true then "even" + false then "odd"; + +result : test_original 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_call_value.txt b/js/scripting-lang/scratch_tests/test_func_call_value.txt new file mode 100644 index 0000000..1f222d8 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_call_value.txt @@ -0,0 +1,12 @@ +/* Test what the function call evaluates to */ +is_even : n -> n % 2 = 0; + +test_value : n -> + when is_even n is + is_even n then "same value" + true then "true" + false then "false" + _ then "other"; + +result : test_value 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_call_when.txt b/js/scripting-lang/scratch_tests/test_func_call_when.txt new file mode 100644 index 0000000..469440a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_call_when.txt @@ -0,0 +1,10 @@ +/* Test function calls in when expressions */ +is_even : n -> n % 2 = 0; + +test_func_call : n -> + when is_even n is + true then "even number" + false then "odd number"; + +result : test_func_call 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_calls_debug.txt b/js/scripting-lang/scratch_tests/test_func_calls_debug.txt new file mode 100644 index 0000000..40f3437 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_calls_debug.txt @@ -0,0 +1,17 @@ +/* Test function calls in when expressions */ + +/* Helper functions for testing */ +is_even : n -> n % 2 = 0; + +/* Number classification using function calls in patterns */ +classify_number : n -> + when (is_even n) is + true then "even number" + false then "odd number"; + +/* Test number classification */ +even_class : classify_number 4; +odd_class : classify_number 7; + +..out even_class; +..out odd_class; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_calls_only.txt b/js/scripting-lang/scratch_tests/test_func_calls_only.txt new file mode 100644 index 0000000..f217d60 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_calls_only.txt @@ -0,0 +1,17 @@ +/* Test just the function calls section */ + +/* Helper functions for testing */ +is_even : n -> n % 2 = 0; + +/* Number classification using function calls in patterns */ +classify_number : n -> + when (is_even n) is + true then "even number" + false then "odd number"; + +/* Test number classification */ +even_class : classify_number 4; +odd_class : classify_number 7; + +..out even_class; +..out odd_class; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_debug_detailed.txt b/js/scripting-lang/scratch_tests/test_func_debug_detailed.txt new file mode 100644 index 0000000..fb96ce5 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_debug_detailed.txt @@ -0,0 +1,24 @@ +/* Detailed debugging of function calls in when expressions */ + +/* Helper functions for testing */ +is_even : n -> n % 2 = 0; + +/* Test the function directly */ +test1 : is_even 4; +test2 : is_even 7; +..out test1; +..out test2; + +/* Number classification using function calls in patterns */ +classify_number : n -> + when (is_even n) is + true then "even number" + false then "odd number"; + +/* Test number classification */ +even_class : classify_number 4; +odd_class : classify_number 7; + +..out "Classification results:"; +..out even_class; +..out odd_class; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_eval.txt b/js/scripting-lang/scratch_tests/test_func_eval.txt new file mode 100644 index 0000000..8944b1f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_eval.txt @@ -0,0 +1,9 @@ +/* Test function call evaluation */ +is_even : n -> n % 2 = 0; + +result1 : is_even 4; +result2 : is_even 5; +result3 : is_even 0; +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_no_match.txt b/js/scripting-lang/scratch_tests/test_func_no_match.txt new file mode 100644 index 0000000..ff55185 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_no_match.txt @@ -0,0 +1,11 @@ +/* Test function call that should not match */ +is_even : n -> n % 2 = 0; + +test_no_match : n -> + when n is + is_even n then "function call result" + 5 then "five" + _ then "other"; + +result : test_no_match 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_pattern.txt b/js/scripting-lang/scratch_tests/test_func_pattern.txt new file mode 100644 index 0000000..23f2888 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_pattern.txt @@ -0,0 +1,11 @@ +/* Test function calls in patterns */ +is_even : n -> n % 2 = 0; + +test_func_pattern : n -> + when n is + (is_even n) then "function call result" + 4 then "four" + _ then "other"; + +result : test_func_pattern 4; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_func_return.txt b/js/scripting-lang/scratch_tests/test_func_return.txt new file mode 100644 index 0000000..3a4bd5f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_func_return.txt @@ -0,0 +1,9 @@ +/* Test function call return value */ +is_even : n -> n % 2 = 0; + +result1 : is_even 4; +result2 : is_even 5; +result3 : is_even 0; +..out result1; +..out result2; +..out result3; \ 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_body.txt b/js/scripting-lang/scratch_tests/test_function_body.txt new file mode 100644 index 0000000..7af35e5 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_function_body.txt @@ -0,0 +1,15 @@ +/* Test multiple statements in function bodies */ + +/* Test simple function */ +simple_func : n -> n; + +/* Test function with multiple statements */ +multi_func : n -> + a : n + 1; + b : a * 2; + b; + +result1 : simple_func 5; +result2 : multi_func 5; +..out result1; +..out result2; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_function_calls_in_tables.txt b/js/scripting-lang/scratch_tests/test_function_calls_in_tables.txt new file mode 100644 index 0000000..a7c991a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_function_calls_in_tables.txt @@ -0,0 +1,28 @@ +/* Test function calls in table literals */ + +/* Test basic function calls */ +mod3 : n -> n % 3; +mod5 : n -> n % 5; + +/* Test individual function calls */ +result1 : mod3 15; +result2 : mod5 15; +..out "mod3 15: " + result1; +..out "mod5 15: " + result2; + +/* Test function calls in table */ +table1 : {mod3 15, mod5 15}; +..out "Table with function calls:"; +..out table1; + +/* Test with map */ +is_zero : x -> x = 0; +mapped : map @is_zero table1; +..out "Mapped table:"; +..out mapped; + +/* Test the complete divisibility function */ +divisibility : n -> map @is_zero {mod3 n, mod5 n}; +result : divisibility 15; +..out "Divisibility result:"; +..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_listen_emit_basic.txt b/js/scripting-lang/scratch_tests/test_listen_emit_basic.txt new file mode 100644 index 0000000..b135908 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_listen_emit_basic.txt @@ -0,0 +1,16 @@ +/* Test basic ..listen and ..emit functionality */ + +/* Test ..listen - should return placeholder state */ +state : ..listen; +..out state; + +/* Test ..emit with simple value */ +..emit "Hello from script"; + +/* Test ..emit with table */ +data : { message: "Test message", value: 42 }; +..emit data; + +/* Test ..emit with computed value */ +computed : 10 + 20; +..emit computed; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_listen_emit_comprehensive.txt b/js/scripting-lang/scratch_tests/test_listen_emit_comprehensive.txt new file mode 100644 index 0000000..79f1a98 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_listen_emit_comprehensive.txt @@ -0,0 +1,48 @@ +/* Comprehensive test for ..listen and ..emit functionality */ + +/* Test 1: Basic ..listen in assignment */ +state : ..listen; +..out "State received:"; +..out state; + +/* Test 2: ..listen in when expression */ +result : when ..listen is + { status: "placeholder" } then "Placeholder state detected" + { status: "active" } then "Active state detected" + _ then "Unknown state"; + +..out result; + +/* Test 3: ..emit with different data types */ +..emit "String value"; +..emit 42; +..emit true; +..emit { key: "value", number: 123 }; + +/* Test 4: ..emit with computed expressions */ +computed_table : { a: 10, b: 20 }; +sum : computed_table.a + computed_table.b; +..emit sum; + +/* Test 5: ..emit with function calls */ +doubled : t.map { 1, 2, 3, 4, 5 } (x -> x * 2); +..emit doubled; + +/* Test 6: ..emit with conditional logic */ +condition : 10 > 5; +message : when condition is + true then "Condition is true" + false then "Condition is false"; +..emit message; + +/* Test 7: ..emit with nested tables */ +nested : { + user: { name: "Alice", age: 30 }, + settings: { theme: "dark", notifications: true } +}; +..emit nested; + +/* Test 8: Test that ..emit doesn't interfere with ..out */ +..out "This should appear via ..out"; +..emit "This should appear via ..emit"; +..out "Another ..out message"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_listen_emit_final.txt b/js/scripting-lang/scratch_tests/test_listen_emit_final.txt new file mode 100644 index 0000000..c735ab2 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_listen_emit_final.txt @@ -0,0 +1,44 @@ +/* Final test for ..listen and ..emit functionality */ + +/* Test 1: Basic ..listen in assignment */ +state : ..listen; +..out "State received:"; +..out state; + +/* Test 2: ..listen in when expression with simple patterns */ +result : when ..listen is + "placeholder" then "Got placeholder" + "active" then "Got active" + _ then "Got something else"; + +..out result; + +/* Test 3: ..emit with different data types */ +..emit "String value"; +..emit 42; +..emit true; +..emit { key: "value", number: 123 }; + +/* Test 4: ..emit with computed expressions */ +computed_table : { a: 10, b: 20 }; +sum : computed_table.a + computed_table.b; +..emit sum; + +/* Test 5: ..emit with conditional logic */ +condition : 10 > 5; +message : when condition is + true then "Condition is true" + false then "Condition is false"; +..emit message; + +/* Test 6: ..emit with nested tables */ +nested : { + user: { name: "Alice", age: 30 }, + settings: { theme: "dark", notifications: true } +}; +..emit nested; + +/* Test 7: Test that ..emit doesn't interfere with ..out */ +..out "This should appear via ..out"; +..emit "This should appear via ..emit"; +..out "Another ..out message"; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_listen_emit_simple.txt b/js/scripting-lang/scratch_tests/test_listen_emit_simple.txt new file mode 100644 index 0000000..fce87da --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_listen_emit_simple.txt @@ -0,0 +1,16 @@ +/* Simple test for ..listen and ..emit */ + +/* Test 1: Basic ..listen */ +state : ..listen; +..out state; + +/* Test 2: Basic ..emit */ +..emit "Hello"; + +/* Test 3: ..listen in when expression with simple patterns */ +result : when ..listen is + "placeholder" then "Got placeholder" + "active" then "Got active" + _ then "Got something else"; + +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_logical_and_debug.txt b/js/scripting-lang/scratch_tests/test_logical_and_debug.txt new file mode 100644 index 0000000..97251b7 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_logical_and_debug.txt @@ -0,0 +1,26 @@ +/* Test logicalAnd function directly */ + +/* Test individual comparisons */ +test1 : (-5) >= 0; /* Should be false */ +test2 : (-5) <= 120; /* Should be true */ + +/* Test logicalAnd with these values */ +result1 : logicalAnd test1 test2; /* false && true = false */ +result2 : logicalAnd test2 test1; /* true && false = false */ + +/* Test the original expression step by step */ +step1 : (-5) >= 0; /* false */ +step2 : (-5) <= 120; /* true */ +step3 : logicalAnd step1 step2; /* false && true = false */ + +/* Test with parentheses */ +parens_test : logicalAnd ((-5) >= 0) ((-5) <= 120); + +..out test1; +..out test2; +..out result1; +..out result2; +..out step1; +..out step2; +..out step3; +..out parens_test; \ 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_minimal_enhanced.txt b/js/scripting-lang/scratch_tests/test_minimal_enhanced.txt new file mode 100644 index 0000000..e4fe6d2 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_minimal_enhanced.txt @@ -0,0 +1,32 @@ +/* Minimal enhanced case statements test */ + +/* FizzBuzz */ +fizzbuzz : n -> + when (n % 3) (n % 5) is + 0 0 then "FizzBuzz" + 0 _ then "Fizz" + _ 0 then "Buzz" + _ _ then n; + +/* Table access */ +admin_user : {role: "admin"}; +access_level : user -> + when user.role is + "admin" then "full access" + _ then "no access"; + +/* Function calls */ +is_even : n -> n % 2 = 0; +classify_number : n -> + when (is_even n) is + true then "even" + false then "odd"; + +/* Test and output */ +result1 : fizzbuzz 15; +result2 : access_level admin_user; +result3 : classify_number 4; + +..out result1; +..out result2; +..out result3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_minimal_enhanced_case.txt b/js/scripting-lang/scratch_tests/test_minimal_enhanced_case.txt new file mode 100644 index 0000000..082c194 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_minimal_enhanced_case.txt @@ -0,0 +1,11 @@ +/* Minimal test for enhanced case statements */ + +/* Test basic function */ +fizzbuzz : n -> n; + +/* Test basic when expression */ +result : when fizzbuzz 5 is + 5 then "works" + _ then "fail"; + +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_minimal_when.txt b/js/scripting-lang/scratch_tests/test_minimal_when.txt new file mode 100644 index 0000000..fdb5d33 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_minimal_when.txt @@ -0,0 +1,9 @@ +/* Minimal test for when expression */ +test_minimal : n -> + when n is + 0 then "zero" + 1 then "one" + _ then "other"; + +result : test_minimal 5; +..out 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_modulo_in_when.txt b/js/scripting-lang/scratch_tests/test_modulo_in_when.txt new file mode 100644 index 0000000..4b2b023 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_modulo_in_when.txt @@ -0,0 +1,30 @@ +/* Test modulo operator in when expressions */ + +/* Test basic modulo */ +test1 : 15 % 3; +..out test1; + +/* Test modulo in when expression */ +test2 : when 15 % 3 is + 0 then "divisible by 3" + _ then "not divisible by 3"; + +..out test2; + +/* Test multiple values in when expression */ +test3 : when 15 % 3 15 % 5 is + 0 0 then "divisible by both" + 0 _ then "divisible by 3 only" + _ 0 then "divisible by 5 only" + _ _ then "divisible by neither"; + +..out test3; + +/* Test modulo with equals function in when expression */ +test4 : when equals (15 % 3) 0 equals (15 % 5) 0 is + true true then "divisible by both" + true false then "divisible by 3 only" + false true then "divisible by 5 only" + false false then "divisible by neither"; + +..out test4; \ 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_multi_validation_debug.txt b/js/scripting-lang/scratch_tests/test_multi_validation_debug.txt new file mode 100644 index 0000000..c252b54 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_multi_validation_debug.txt @@ -0,0 +1,13 @@ +/* Test multi-value validation pattern */ + +/* Multi-field validation using function calls */ +validate_user : name age -> + when (name != "") (age >= 0 and age <= 120) is + true true then "valid user" + true false then "invalid age" + false true then "invalid name" + false false then "invalid user"; + +/* Test user validation */ +valid_user : validate_user "Alice" 30; +..out valid_user; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_multi_validation_only.txt b/js/scripting-lang/scratch_tests/test_multi_validation_only.txt new file mode 100644 index 0000000..f330ffe --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_multi_validation_only.txt @@ -0,0 +1,13 @@ +/* Test just the multi-value validation pattern */ + +/* Multi-field validation using function calls */ +validate_user : name age -> + when (name != "") (age >= 0 and age <= 120) is + true true then "valid user" + true false then "invalid age" + false true then "invalid name" + false false then "invalid user"; + +/* Test user validation */ +valid_user : validate_user "Alice" 30; +..out valid_user; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_multi_validation_simple.txt b/js/scripting-lang/scratch_tests/test_multi_validation_simple.txt new file mode 100644 index 0000000..a26a72a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_multi_validation_simple.txt @@ -0,0 +1,13 @@ +/* Test simpler multi-value validation pattern */ + +/* Test with simple boolean expressions */ +validate_user : name age -> + when (name != "") (age > 0) is + true true then "valid user" + true false then "invalid age" + false true then "invalid name" + false false then "invalid user"; + +/* Test user validation */ +valid_user : validate_user "Alice" 30; +..out valid_user; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_multi_value_expr.txt b/js/scripting-lang/scratch_tests/test_multi_value_expr.txt new file mode 100644 index 0000000..cbc3233 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_multi_value_expr.txt @@ -0,0 +1,10 @@ +/* Test multi-value patterns with expressions */ +test_multi_expr : x y -> + when (x % 2) (y % 2) is + 0 0 then "both even" + 0 1 then "x even, y odd" + 1 0 then "x odd, y even" + 1 1 then "both odd"; + +result : test_multi_expr 4 6; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_multiple_values_parens.txt b/js/scripting-lang/scratch_tests/test_multiple_values_parens.txt new file mode 100644 index 0000000..601ca43 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_multiple_values_parens.txt @@ -0,0 +1,29 @@ +/* Test multiple values with parentheses in when expressions */ + +/* Test simple multiple values */ +test1 : when 5 3 is + 5 3 then "simple multiple values work" + _ _ then "simple multiple values don't work"; + +..out test1; + +/* Test multiple values with parentheses */ +test2 : when (5) (3) is + 5 3 then "parenthesized multiple values work" + _ _ then "parenthesized multiple values don't work"; + +..out test2; + +/* Test multiple values with expressions in parentheses */ +test3 : when (5 + 2) (3 + 0) is + 7 3 then "expressions in parentheses work" + _ _ then "expressions in parentheses don't work"; + +..out test3; + +/* Test FizzBuzz-style multiple values */ +test4 : when (15 % 3) (15 % 5) is + 0 0 then "FizzBuzz-style multiple values work" + _ _ then "FizzBuzz-style multiple values don't work"; + +..out test4; \ 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_only.txt b/js/scripting-lang/scratch_tests/test_nested_only.txt new file mode 100644 index 0000000..f3857fc --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_nested_only.txt @@ -0,0 +1,15 @@ +/* Test just the nested when expressions */ + +/* Ensure backward compatibility with nested when expressions */ +nested_classify : x y -> + when x is + 0 then when y is + 0 then "origin" + _ then "on y-axis" + _ then when y is + 0 then "on x-axis" + _ then "general position"; + +/* Test nested when expressions */ +nested1 : nested_classify 0 0; +..out nested1; \ 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_parens_disambiguation.txt b/js/scripting-lang/scratch_tests/test_parens_disambiguation.txt new file mode 100644 index 0000000..8863d8b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_parens_disambiguation.txt @@ -0,0 +1,29 @@ +/* Test if parentheses can help disambiguate complex expressions */ + +/* Test modulo with parentheses */ +test1 : when (15 % 3) is + 0 then "modulo in parentheses works" + _ then "modulo in parentheses doesn't work"; + +..out test1; + +/* Test equals with parentheses */ +test2 : when (5 = 5) is + true then "equals in parentheses works" + _ then "equals in parentheses doesn't work"; + +..out test2; + +/* Test complex expression with parentheses */ +test3 : when ((15 % 3) = 0) is + true then "complex expression in parentheses works" + _ then "complex expression in parentheses doesn't work"; + +..out test3; + +/* Test multiple values with parentheses */ +test4 : when (15 % 3) (15 % 5) is + 0 0 then "multiple values with parentheses work" + _ _ then "multiple values with parentheses don't work"; + +..out test4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_parens_in_when.txt b/js/scripting-lang/scratch_tests/test_parens_in_when.txt new file mode 100644 index 0000000..4b441b4 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_parens_in_when.txt @@ -0,0 +1,22 @@ +/* Test parentheses in when expressions */ + +/* Test simple parentheses */ +test1 : when (5) is + 5 then "parentheses work" + _ then "parentheses don't work"; + +..out test1; + +/* Test parentheses with arithmetic */ +test2 : when (5 + 3) is + 8 then "arithmetic in parentheses works" + _ then "arithmetic in parentheses doesn't work"; + +..out test2; + +/* Test parentheses with function calls */ +test3 : when (equals 5 5) is + true then "function call in parentheses works" + _ then "function call in parentheses doesn't work"; + +..out test3; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_parens_multiple.txt b/js/scripting-lang/scratch_tests/test_parens_multiple.txt new file mode 100644 index 0000000..84592b7 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_parens_multiple.txt @@ -0,0 +1,37 @@ +/* Test parentheses with multiple values in when expressions */ + +/* Test with parentheses around expressions */ +compare_parens : x y -> + when (x) (y) is + 0 0 then "both zero" + 0 _ then "x is zero" + _ 0 then "y is zero" + _ _ then "neither zero"; + +test1 : compare_parens 0 0; +test2 : compare_parens 0 5; +test3 : compare_parens 5 0; +test4 : compare_parens 5 5; + +..out test1; +..out test2; +..out test3; +..out test4; + +/* Test with arithmetic expressions in parentheses */ +compare_math : x y -> + when (x + 0) (y + 0) is + 0 0 then "both zero" + 0 _ then "x is zero" + _ 0 then "y is zero" + _ _ then "neither zero"; + +test5 : compare_math 0 0; +test6 : compare_math 0 5; +test7 : compare_math 5 0; +test8 : compare_math 5 5; + +..out test5; +..out test6; +..out test7; +..out test8; \ 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_debug.txt b/js/scripting-lang/scratch_tests/test_pattern_debug.txt new file mode 100644 index 0000000..ef8b676 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_pattern_debug.txt @@ -0,0 +1,14 @@ +/* Test pattern matching with boolean values */ + +/* Test direct boolean matching */ +test_bool : value -> + when value is + true then "true matched" + false then "false matched" + _ then "wildcard matched"; + +result1 : test_bool true; +result2 : test_bool false; + +..out result1; +..out result2; \ 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_predicate_functions.txt b/js/scripting-lang/scratch_tests/test_predicate_functions.txt new file mode 100644 index 0000000..e1cba80 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_predicate_functions.txt @@ -0,0 +1,35 @@ +/* Test predicate functions */ + +/* Test basic predicate functions */ +is_fizzbuzz : n -> (n % 3 = 0) and (n % 5 = 0); +is_fizz : n -> n % 3 = 0; +is_buzz : n -> n % 5 = 0; + +/* Test the functions */ +test1 : is_fizzbuzz 15; +test2 : is_fizz 3; +test3 : is_buzz 5; +test4 : is_fizzbuzz 7; + +..out test1; +..out test2; +..out test3; +..out test4; + +/* Test simple when with boolean */ +simple_test : n -> + when true is + true then "true" + _ then "false"; + +result1 : simple_test 15; +..out result1; + +/* Test function call in when */ +func_test : n -> + when is_fizzbuzz n is + true then "FizzBuzz" + _ then n; + +result2 : func_test 15; +..out result2; \ 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_run_function.js b/js/scripting-lang/scratch_tests/test_run_function.js new file mode 100644 index 0000000..c79f5e8 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_run_function.js @@ -0,0 +1,24 @@ +/** + * Test the run function directly + */ + +import { run } from '../lang.js'; + +const scriptContent = ` +/* Simple test script */ + +/* Get current state */ +state : ..listen; + +/* Emit the state */ +..emit state; +`; + +try { + console.log('Testing run function...'); + const result = run(scriptContent, {}, null); + console.log('Result:', result); +} catch (error) { + console.error('Error:', error); + console.error('Stack:', error.stack); +} \ 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_and.txt b/js/scripting-lang/scratch_tests/test_simple_and.txt new file mode 100644 index 0000000..fbf2edf --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_and.txt @@ -0,0 +1,14 @@ +/* Test simple logicalAnd */ + +/* Simple boolean values */ +true_val : true; +false_val : false; + +/* Test logicalAnd with simple values */ +result1 : logicalAnd true_val false_val; +result2 : logicalAnd false_val true_val; +result3 : logicalAnd true_val true_val; + +..out result1; +..out result2; +..out result3; \ 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_fizzbuzz.txt b/js/scripting-lang/scratch_tests/test_simple_fizzbuzz.txt new file mode 100644 index 0000000..0b6cf39 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_fizzbuzz.txt @@ -0,0 +1,43 @@ +/* Simple FizzBuzz test */ + +/* Test basic modulo */ +test1 : 15 % 3; +test2 : 15 % 5; +..out test1; +..out test2; + +/* Test basic when with modulo */ +test3 : when 15 % 3 is + 0 then "divisible by 3" + _ then "not divisible by 3"; +..out test3; + +/* Test simple function */ +simple_test : n -> n; + +result1 : simple_test 3; +..out result1; + +/* Test when inside function */ +when_test : n -> + when n is + 3 then "three" + _ then n; + +result2 : when_test 3; +..out result2; + +/* Test modulo in function */ +modulo_test : n -> n % 3; + +result3 : modulo_test 15; +..out result3; + +/* Test greater than in when */ +greater_test : n -> + when n > 0 is + true then "positive" + _ then "non-positive"; + +result4 : greater_test 5; +..out result4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_simple_func_call.txt b/js/scripting-lang/scratch_tests/test_simple_func_call.txt new file mode 100644 index 0000000..06ec7cd --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_func_call.txt @@ -0,0 +1,10 @@ +/* Test with a simpler function call */ +id : x -> x; + +test_simple : n -> + when id n is + n then "same" + _ then "different"; + +result : test_simple 4; +..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_harness.txt b/js/scripting-lang/scratch_tests/test_simple_harness.txt new file mode 100644 index 0000000..6d1381b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_harness.txt @@ -0,0 +1,7 @@ +/* Simple test script */ + +/* Get current state */ +state : ..listen; + +/* Emit the state */ +..emit state; \ 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_multiple.txt b/js/scripting-lang/scratch_tests/test_simple_multiple.txt new file mode 100644 index 0000000..fc3ee32 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_multiple.txt @@ -0,0 +1,8 @@ +/* Test simple multiple values in when expressions */ + +/* Test simple multiple values */ +test1 : when 5 3 is + 5 3 then "simple multiple values work" + _ _ then "simple multiple values don't work"; + +..out test1; \ 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_verification.txt b/js/scripting-lang/scratch_tests/test_simple_verification.txt new file mode 100644 index 0000000..2abdc0f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_verification.txt @@ -0,0 +1,51 @@ +/* Simple verification test for enhanced case statements */ + +/* Test 1: Basic table creation */ +basic : {1, 2, 3}; +..out "Basic table:"; +..out basic; + +/* Test 2: Auto-indexed table with expressions */ +expr : {5 % 3, 5 % 5}; +..out "Expression table:"; +..out expr; + +/* Test 3: Map with equals 0 */ +mapped : map @(equals 0) {15 % 3, 15 % 5}; +..out "Mapped table:"; +..out mapped; + +/* Test 4: Simple table pattern matching */ +test_table : {1: true, 2: false}; +result : when test_table is + {1: true, 2: true} then "both true" + {1: true, 2: false} then "first true" + {1: false, 2: true} then "second true" + {1: false, 2: false} then "both false"; +..out "Pattern match result:"; +..out result; + +/* Test 5: FizzBuzz divisibility function */ +divisibility : n -> map @(equals 0) {n % 3, n % 5}; +div_15 : divisibility 15; +..out "Divisibility for 15:"; +..out div_15; + +/* Test 6: Complete FizzBuzz */ +fizzbuzz : n -> + when divisibility n is + {1: true, 2: true} then "FizzBuzz" + {1: true, 2: false} then "Fizz" + {1: false, 2: true} then "Buzz" + {1: false, 2: false} then n; + +fizz_15 : fizzbuzz 15; +fizz_3 : fizzbuzz 3; +fizz_5 : fizzbuzz 5; +fizz_7 : fizzbuzz 7; + +..out "FizzBuzz results:"; +..out "15: " + fizz_15; +..out "3: " + fizz_3; +..out "5: " + fizz_5; +..out "7: " + fizz_7; \ 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_simple_when_equals.txt b/js/scripting-lang/scratch_tests/test_simple_when_equals.txt new file mode 100644 index 0000000..885091b --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_simple_when_equals.txt @@ -0,0 +1,17 @@ +/* Simple test for when expressions with equals */ + +/* Test basic when with equals */ +test1 : when 5 = 5 is + true then "equal" + _ then "not equal"; + +..out test1; + +/* Test multiple values with different patterns */ +test2 : when 5 = 5 3 = 3 is + 1 1 then "both equal" + 1 0 then "first equal" + 0 1 then "second equal" + 0 0 then "neither equal"; + +..out test2; \ 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_access_debug.txt b/js/scripting-lang/scratch_tests/test_table_access_debug.txt new file mode 100644 index 0000000..e4c613a --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_access_debug.txt @@ -0,0 +1,15 @@ +/* Test table access in when expressions */ + +/* User data for testing */ +admin_user : {role: "admin", level: 5, name: "Alice"}; + +/* Access control using table access in patterns */ +access_level : user -> + when user.role is + "admin" then "full access" + "user" then "limited access" + _ then "no access"; + +/* Test access control */ +admin_access : access_level admin_user; +..out admin_access; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_access_in_functions.txt b/js/scripting-lang/scratch_tests/test_table_access_in_functions.txt new file mode 100644 index 0000000..4817b23 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_access_in_functions.txt @@ -0,0 +1,22 @@ +/* Test table access in function definitions */ + +/* Test basic table access */ +user : {role: "admin", active: true}; +test1 : user.role; +test2 : user.active; +..out test1; +..out test2; + +/* Test table access in function */ +get_role : user -> user.role; +test3 : get_role user; +..out test3; + +/* Test table access inside when in function */ +classify_user : user -> + when user.role is + "admin" then "admin" + _ then "user"; + +test4 : classify_user user; +..out test4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_access_only.txt b/js/scripting-lang/scratch_tests/test_table_access_only.txt new file mode 100644 index 0000000..0874c0f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_access_only.txt @@ -0,0 +1,15 @@ +/* Test just the table access part */ + +/* User data for testing */ +admin_user : {role: "admin", level: 5, name: "Alice"}; + +/* Access control using table access in patterns */ +access_level : user -> + when user.role is + "admin" then "full access" + "user" then "limited access" + _ then "no access"; + +/* Test access control */ +admin_access : access_level admin_user; +..out admin_access; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/test_table_access_when.txt b/js/scripting-lang/scratch_tests/test_table_access_when.txt new file mode 100644 index 0000000..4161b19 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_table_access_when.txt @@ -0,0 +1,11 @@ +/* Test table access in when expressions */ +user : {role: "admin", level: 5}; + +test_table_access : u -> + when u.role is + "admin" then "admin user" + "user" then "regular user" + _ then "unknown role"; + +result : test_table_access user; +..out result; \ 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_pattern_matching.txt b/js/scripting-lang/scratch_tests/test_when_pattern_matching.txt new file mode 100644 index 0000000..a9efad0 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_when_pattern_matching.txt @@ -0,0 +1,25 @@ +/* Test when expression pattern matching with tables */ + +/* Test 1: Simple table pattern matching */ +test_value : { status: "placeholder", message: "test" }; + +result1 : when test_value is + { status: "placeholder" } then "Pattern 1 matched" + { status: "active" } then "Pattern 2 matched" + _ then "No pattern matched"; + +..out "Result 1:"; +..out result1; + +/* Test 2: ..listen pattern matching */ +state : ..listen; +..out "State:"; +..out state; + +result2 : when state is + { status: "placeholder" } then "Placeholder pattern matched" + { status: "active" } then "Active pattern matched" + _ then "No pattern matched"; + +..out "Result 2:"; +..out result2; \ 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 diff --git a/js/scripting-lang/scratch_tests/test_working_multiple.txt b/js/scripting-lang/scratch_tests/test_working_multiple.txt new file mode 100644 index 0000000..66c796f --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_working_multiple.txt @@ -0,0 +1,18 @@ +/* Test multiple values using working syntax */ + +compare : x y -> + when x y is + 0 0 then "both zero" + 0 _ then "x is zero" + _ 0 then "y is zero" + _ _ then "neither zero"; + +test1 : compare 0 0; +test2 : compare 0 5; +test3 : compare 5 0; +test4 : compare 5 5; + +..out test1; +..out test2; +..out test3; +..out test4; \ No newline at end of file diff --git a/js/scripting-lang/scratch_tests/validate_table_scrap.txt b/js/scripting-lang/scratch_tests/validate_table_scrap.txt new file mode 100644 index 0000000..0e937c9 --- /dev/null +++ b/js/scripting-lang/scratch_tests/validate_table_scrap.txt @@ -0,0 +1,21 @@ +/* Validate user input data */ +users : { + user1: {name: "Alice", email: "alice@example.com", age: 25}, + user2: {name: "", email: "invalid-email", age: -5}, + user3: {name: "Charlie", email: "charlie@test.com", age: 30} +}; + +/* Simple validation example */ +is_valid_name : user -> + when user.name = "" is + true then false + _ then true; + +is_valid_age : user -> + when user.age > 0 is + true then true + _ then false; + +/* Apply validation to all users */ +valid_names : map @is_valid_name users; +valid_ages : map @is_valid_age users; |