diff options
Diffstat (limited to 'js/scripting-lang/tests')
4 files changed, 362 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/21_enhanced_case_statements.txt b/js/scripting-lang/tests/21_enhanced_case_statements.txt new file mode 100644 index 0000000..79adb69 --- /dev/null +++ b/js/scripting-lang/tests/21_enhanced_case_statements.txt @@ -0,0 +1,98 @@ +/* Unit Test: Enhanced Case Statements - Fixed Version */ +/* Tests: FizzBuzz and advanced pattern matching with new capabilities */ + +/* ===== 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; +fizzbuzz_3 : fizzbuzz 3; +fizzbuzz_5 : fizzbuzz 5; +fizzbuzz_7 : fizzbuzz 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; + +/* ===== 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; + +/* ===== SIMPLIFIED MULTI-VALUE VALIDATION ===== */ + +/* Simplified validation - avoid complex and expressions */ +validate_name : name -> name != ""; +validate_age : age -> age >= 0; + +validate_user : name age -> + when (validate_name name) (validate_age 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; +invalid_age : validate_user "Bob" -5; +invalid_name : validate_user "" 25; + +/* ===== OUTPUT RESULTS ===== */ + +/* Output FizzBuzz results */ +..out "FizzBuzz Results:"; +..out fizzbuzz_15; +..out fizzbuzz_3; +..out fizzbuzz_5; +..out fizzbuzz_7; + +/* Output access control results */ +..out "Access Control Results:"; +..out admin_access; +..out user_access; +..out guest_access; + +/* Output number classification results */ +..out "Number Classification Results:"; +..out even_class; +..out odd_class; + +/* Output user validation results */ +..out "User Validation Results:"; +..out valid_user; +..out invalid_age; +..out invalid_name; + +..out "Enhanced case statements test completed successfully"; \ No newline at end of file diff --git a/js/scripting-lang/tests/21_enhanced_case_statements_fixed.txt b/js/scripting-lang/tests/21_enhanced_case_statements_fixed.txt new file mode 100644 index 0000000..79adb69 --- /dev/null +++ b/js/scripting-lang/tests/21_enhanced_case_statements_fixed.txt @@ -0,0 +1,98 @@ +/* Unit Test: Enhanced Case Statements - Fixed Version */ +/* Tests: FizzBuzz and advanced pattern matching with new capabilities */ + +/* ===== 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; +fizzbuzz_3 : fizzbuzz 3; +fizzbuzz_5 : fizzbuzz 5; +fizzbuzz_7 : fizzbuzz 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; + +/* ===== 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; + +/* ===== SIMPLIFIED MULTI-VALUE VALIDATION ===== */ + +/* Simplified validation - avoid complex and expressions */ +validate_name : name -> name != ""; +validate_age : age -> age >= 0; + +validate_user : name age -> + when (validate_name name) (validate_age 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; +invalid_age : validate_user "Bob" -5; +invalid_name : validate_user "" 25; + +/* ===== OUTPUT RESULTS ===== */ + +/* Output FizzBuzz results */ +..out "FizzBuzz Results:"; +..out fizzbuzz_15; +..out fizzbuzz_3; +..out fizzbuzz_5; +..out fizzbuzz_7; + +/* Output access control results */ +..out "Access Control Results:"; +..out admin_access; +..out user_access; +..out guest_access; + +/* Output number classification results */ +..out "Number Classification Results:"; +..out even_class; +..out odd_class; + +/* Output user validation results */ +..out "User Validation Results:"; +..out valid_user; +..out invalid_age; +..out invalid_name; + +..out "Enhanced case statements test completed successfully"; \ No newline at end of file diff --git a/js/scripting-lang/tests/22_parser_limitations.txt b/js/scripting-lang/tests/22_parser_limitations.txt new file mode 100644 index 0000000..6d267b8 --- /dev/null +++ b/js/scripting-lang/tests/22_parser_limitations.txt @@ -0,0 +1,115 @@ +/* Unit Test: Parser Limitations for Enhanced Case Statements */ +/* Tests: Multi-value patterns with expressions, table access, function calls */ + +/* ======================================== */ +/* MAIN BLOCKER: Multi-value patterns with expressions */ +/* ======================================== */ + +/* Test 1: Basic multi-value with expressions in parentheses */ +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"; + +/* Test 2: FizzBuzz-style multi-value patterns */ +fizzbuzz_test : n -> + when (n % 3) (n % 5) is + 0 0 then "FizzBuzz" + 0 _ then "Fizz" + _ 0 then "Buzz" + _ _ then n; + +/* Test 3: Complex expressions in multi-value patterns */ +complex_multi : 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 4: Function calls in multi-value patterns */ +is_even : n -> n % 2 = 0; +is_positive : n -> n > 0; + +test_func_multi : x y -> + when (is_even x) (is_positive y) is + true true then "x even and y positive" + true false then "x even and y not positive" + false true then "x odd and y positive" + false false then "x odd and y not positive"; + +/* ======================================== */ +/* SECONDARY LIMITATIONS: Table access and function calls */ +/* ======================================== */ + +/* Test 5: 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"; + +/* Test 6: Function calls in when expressions */ +test_func_call : n -> + when (is_even n) is + true then "even number" + false then "odd number"; + +/* Test 7: Complex function calls in when expressions */ +complex_func : n -> (n % 3 = 0) and (n % 5 = 0); +test_complex_func : n -> + when (complex_func n) is + true then "divisible by both 3 and 5" + false then "not divisible by both"; + +/* ======================================== */ +/* CONTROL TESTS: Should work with current parser */ +/* ======================================== */ + +/* Test 8: Simple value matching (control) */ +test_simple : n -> + when n is + 0 then "zero" + 1 then "one" + _ then "other"; + +/* Test 9: Single complex expressions with parentheses (control) */ +test_single_expr : n -> + when (n % 3) is + 0 then "divisible by 3" + _ then "not divisible by 3"; + +/* Test 10: Multiple simple values (control) */ +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"; + +/* ======================================== */ +/* TEST EXECUTION */ +/* ======================================== */ + +/* Execute tests that should work */ +result1 : test_simple 5; +result2 : test_single_expr 15; +result3 : test_multi_simple 0 5; + +/* These should fail with current parser */ +result4 : test_multi_expr 4 6; /* Should return "both even" */ +result5 : fizzbuzz_test 15; /* Should return "FizzBuzz" */ +result6 : test_table_access user; /* Should return "admin user" */ +result7 : test_func_call 4; /* Should return "even number" */ + +/* Output results */ +..out result1; +..out result2; +..out result3; +..out result4; +..out result5; +..out result6; +..out result7; \ No newline at end of file diff --git a/js/scripting-lang/tests/23_minus_operator_spacing.txt b/js/scripting-lang/tests/23_minus_operator_spacing.txt new file mode 100644 index 0000000..510b997 --- /dev/null +++ b/js/scripting-lang/tests/23_minus_operator_spacing.txt @@ -0,0 +1,51 @@ +/* Test file for minus operator spacing functionality */ +/* This tests the new spacing-based ambiguity resolution for minus operator */ + +..out "=== Minus Operator Spacing Tests ==="; + +/* Basic unary minus tests */ +test1 : -5; +test2 : -3.14; +test3 : -10; +test4 : -42; + +/* Basic binary minus tests */ +test5 : 5 - 3; +test6 : 10 - 5; +test7 : 15 - 7; +test8 : 10 - 2.5; + +/* Legacy syntax tests (should continue to work) */ +test9 : (-5); +test10 : (-3.14); +test11 : (-10); +test12 : 5-3; +test13 : 15-7; + +/* Complex negative expressions */ +test14 : -10 - -100; +test15 : -5 - -3; +test16 : -20 - -30; + +/* Assertions to validate behavior */ +..assert test1 = -5; /* Unary minus: -5 */ +..assert test2 = -3.14; /* Unary minus: -3.14 */ +..assert test3 = -10; /* Unary minus: -10 */ +..assert test4 = -42; /* Unary minus: -42 */ + +..assert test5 = 2; /* Binary minus: 5 - 3 = 2 */ +..assert test6 = 5; /* Binary minus: 10 - 5 = 5 */ +..assert test7 = 8; /* Binary minus: 15 - 7 = 8 */ +..assert test8 = 7.5; /* Binary minus: 10 - 2.5 = 7.5 */ + +..assert test9 = -5; /* Legacy: (-5) = -5 */ +..assert test10 = -3.14; /* Legacy: (-3.14) = -3.14 */ +..assert test11 = -10; /* Legacy: (-10) = -10 */ +..assert test12 = 2; /* Legacy: 5-3 = 2 */ +..assert test13 = 8; /* Legacy: 15-7 = 8 */ + +..assert test14 = 90; /* Complex: -10 - -100 = 90 */ +..assert test15 = -2; /* Complex: -5 - -3 = -2 */ +..assert test16 = 10; /* Complex: -20 - -30 = 10 */ + +..out "=== Basic Minus Operator Spacing Tests Passed ==="; \ No newline at end of file |