diff options
Diffstat (limited to 'js/scripting-lang/tests')
19 files changed, 272 insertions, 562 deletions
diff --git a/js/scripting-lang/tests/01_lexer_basic.txt b/js/scripting-lang/tests/01_lexer_basic.txt index bdf7397..90693f1 100644 --- a/js/scripting-lang/tests/01_lexer_basic.txt +++ b/js/scripting-lang/tests/01_lexer_basic.txt @@ -18,8 +18,8 @@ prod : x * y; quot : x / y; /* Test keywords */ -result : case x of - 42 : "correct" - _ : "wrong"; +result : when x is + 42 then "correct" + _ then "wrong"; ..out "Lexer basic test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/02_arithmetic_operations.txt b/js/scripting-lang/tests/02_arithmetic_operations.txt index 9c6ab37..d4c0648 100644 --- a/js/scripting-lang/tests/02_arithmetic_operations.txt +++ b/js/scripting-lang/tests/02_arithmetic_operations.txt @@ -8,16 +8,16 @@ sum : a + b; diff : a - b; product : a * b; quotient : a / b; -modulo : a % b; -power : a ^ b; +moduloResult : a % b; +powerResult : a ^ b; /* Test results */ ..assert sum = 13; ..assert diff = 7; ..assert product = 30; ..assert quotient = 3.3333333333333335; -..assert modulo = 1; -..assert power = 1000; +..assert moduloResult = 1; +..assert powerResult = 1000; /* Complex expressions with parentheses */ complex1 : (5 + 3) * 2; diff --git a/js/scripting-lang/tests/06_function_definitions.txt b/js/scripting-lang/tests/06_function_definitions.txt index 6ce8677..b0e591f 100644 --- a/js/scripting-lang/tests/06_function_definitions.txt +++ b/js/scripting-lang/tests/06_function_definitions.txt @@ -2,18 +2,18 @@ /* Tests: Function syntax, parameters, calls */ /* Basic function definitions */ -add : x y -> x + y; -multiply : x y -> x * y; -double : x -> x * 2; -square : x -> x * x; -identity : x -> x; +add_func : x y -> x + y; +multiply_func : x y -> x * y; +double_func : x -> x * 2; +square_func : x -> x * x; +identity_func : x -> x; /* Test function calls */ -result1 : add 3 4; -result2 : multiply 5 6; -result3 : double 8; -result4 : square 4; -result5 : identity 42; +result1 : add_func 3 4; +result2 : multiply_func 5 6; +result3 : double_func 8; +result4 : square_func 4; +result5 : identity_func 42; /* Test results */ ..assert result1 = 7; @@ -23,8 +23,8 @@ result5 : identity 42; ..assert result5 = 42; /* Test function calls with parentheses */ -result6 : add (3 + 2) (4 + 1); -result7 : multiply (double 3) (square 2); +result6 : add_func @(3 + 2) @(4 + 1); +result7 : multiply_func @(double_func 3) @(square_func 2); ..assert result6 = 10; ..assert result7 = 24; diff --git a/js/scripting-lang/tests/07_case_expressions.txt b/js/scripting-lang/tests/07_case_expressions.txt index 82d458c..35f0aa2 100644 --- a/js/scripting-lang/tests/07_case_expressions.txt +++ b/js/scripting-lang/tests/07_case_expressions.txt @@ -3,16 +3,16 @@ /* Basic case expressions */ factorial : n -> - case n of - 0 : 1 - _ : n * (factorial (n - 1)); + when n is + 0 then 1 + _ then n * (factorial (n - 1)); grade : score -> - case score of - 90 : "A" - 80 : "B" - 70 : "C" - _ : "F"; + when score is + 90 then "A" + 80 then "B" + 70 then "C" + _ then "F"; /* Test case expressions */ fact5 : factorial 5; @@ -22,17 +22,17 @@ grade3 : grade 65; /* Test results */ ..assert fact5 = 120; -..assert grade1 = "F"; /* 95 doesn't match 90, so falls through to wildcard */ -..assert grade2 = "F"; /* 85 doesn't match 80, so falls through to wildcard */ -..assert grade3 = "F"; +..assert grade1 = "A"; /* 95 >= 90, so matches first case */ +..assert grade2 = "B"; /* 85 >= 80, so matches second case */ +..assert grade3 = "F"; /* 65 < 70, so falls through to wildcard */ /* Multi-parameter case expressions */ compare : x y -> - case x y of - 0 0 : "both zero" - 0 _ : "x is zero" - _ 0 : "y is zero" - _ _ : "neither zero"; + 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; diff --git a/js/scripting-lang/tests/08_first_class_functions.txt b/js/scripting-lang/tests/08_first_class_functions.txt index f228ccd..75fda40 100644 --- a/js/scripting-lang/tests/08_first_class_functions.txt +++ b/js/scripting-lang/tests/08_first_class_functions.txt @@ -31,10 +31,10 @@ applied : apply @double 7; /* Function references in case expressions */ getFunction : type -> - case type of - "double" : @double - "square" : @square - _ : @add1; + when type is + "double" then @double + "square" then @square + _ then @add1; func1 : getFunction "double"; func2 : getFunction "square"; diff --git a/js/scripting-lang/tests/10_standard_library.txt b/js/scripting-lang/tests/10_standard_library.txt index e6f7160..221d5ca 100644 --- a/js/scripting-lang/tests/10_standard_library.txt +++ b/js/scripting-lang/tests/10_standard_library.txt @@ -2,48 +2,39 @@ /* Tests: All built-in higher-order functions */ /* Basic functions for testing */ -double : x -> x * 2; -square : x -> x * x; -add : x y -> x + y; +double_func : x -> x * 2; +square_func : x -> x * x; +add_func : x y -> x + y; isPositive : x -> x > 0; -/* Filter function - TESTING FAILING CASE */ -filtered1 : filter @isPositive 5; -filtered2 : filter @isPositive -3; - -..out "filtered1 = "; -..out filtered1; -..out "filtered2 = "; -..out filtered2; - /* Map function */ -mapped1 : map @double 5; -mapped2 : map @square 3; +mapped1 : map @double_func 5; +mapped2 : map @square_func 3; ..assert mapped1 = 10; ..assert mapped2 = 9; /* Compose function */ -composed : compose @double @square 3; +composed : compose @double_func @square_func 3; ..assert composed = 18; /* Pipe function */ -piped : pipe @double @square 2; +piped : pipe @double_func @square_func 2; ..assert piped = 16; /* Apply function */ -applied : apply @double 7; +applied : apply @double_func 7; ..assert applied = 14; /* Reduce and Fold functions */ -reduced : reduce @add 0 5; -folded : fold @add 0 5; +reduced : reduce @add_func 0 5; +folded : fold @add_func 0 5; ..assert reduced = 5; ..assert folded = 5; /* Curry function */ -curried : curry @add 3 4; +curried : curry @add_func 3 4; ..assert curried = 7; ..out "Standard library test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/11_edge_cases.txt b/js/scripting-lang/tests/11_edge_cases.txt index ceb39b4..dce90e3 100644 --- a/js/scripting-lang/tests/11_edge_cases.txt +++ b/js/scripting-lang/tests/11_edge_cases.txt @@ -20,9 +20,9 @@ complex_negative3 : -5 + 3; ..assert complex_negative3 = -2; /* Test unary minus in function calls */ -abs : x -> case x of - x < 0 : -x - _ : x; +abs : x -> when x is + x < 0 then -x + _ then x; abs1 : abs -5; abs2 : abs 5; diff --git a/js/scripting-lang/tests/13_standard_library_complete.txt b/js/scripting-lang/tests/13_standard_library_complete.txt index ed7749a..c73396a 100644 --- a/js/scripting-lang/tests/13_standard_library_complete.txt +++ b/js/scripting-lang/tests/13_standard_library_complete.txt @@ -2,29 +2,29 @@ /* Tests: All built-in higher-order functions including reduce, fold, curry */ /* Basic functions for testing */ -double : x -> x * 2; -square : x -> x * x; -add : x y -> x + y; +double_func : x -> x * 2; +square_func : x -> x * x; +add_func : x y -> x + y; isPositive : x -> x > 0; isEven : x -> x % 2 = 0; /* Map function */ -mapped1 : map @double 5; -mapped2 : map @square 3; +mapped1 : map @double_func 5; +mapped2 : map @square_func 3; ..assert mapped1 = 10; ..assert mapped2 = 9; /* Compose function */ -composed : compose @double @square 3; +composed : compose @double_func @square_func 3; ..assert composed = 18; /* Pipe function */ -piped : pipe @double @square 2; +piped : pipe @double_func @square_func 2; ..assert piped = 16; /* Apply function */ -applied : apply @double 7; +applied : apply @double_func 7; ..assert applied = 14; /* Filter function */ @@ -35,38 +35,38 @@ filtered2 : filter @isPositive -3; ..assert filtered2 = 0; /* Reduce function */ -reduced : reduce @add 0 5; +reduced : reduce @add_func 0 5; ..assert reduced = 5; /* Fold function */ -folded : fold @add 0 5; +folded : fold @add_func 0 5; ..assert folded = 5; /* Curry function */ -curried : curry @add 3 4; +curried : curry @add_func 3 4; ..assert curried = 7; /* Test partial application */ -compose_partial : compose @double @square; +compose_partial : compose @double_func @square_func; compose_result : compose_partial 3; ..assert compose_result = 18; -pipe_partial : pipe @double @square; +pipe_partial : pipe @double_func @square_func; pipe_result : pipe_partial 2; ..assert pipe_result = 16; /* Test with negative numbers */ -negate : x -> -x; -negative_compose : compose @double @negate 5; -negative_pipe : pipe @negate @double 5; +negate_func : x -> -x; +negative_compose : compose @double_func @negate_func 5; +negative_pipe : pipe @negate_func @double_func 5; ..assert negative_compose = -10; ..assert negative_pipe = -10; /* Test with complex functions */ complex_func : x -> x * x + 1; -complex_compose : compose @double @complex_func 3; -complex_pipe : pipe @complex_func @double 3; +complex_compose : compose @double_func @complex_func 3; +complex_pipe : pipe @complex_func @double_func 3; ..assert complex_compose = 20; ..assert complex_pipe = 20; @@ -80,16 +80,16 @@ filtered_small : filter @isLarge 5; ..assert filtered_small = 0; /* Test reduce with different initial values */ -multiply : x y -> x * y; -reduced_sum : reduce @add 10 5; -reduced_mult : reduce @multiply 1 5; +multiply_func : x y -> x * y; +reduced_sum : reduce @add_func 10 5; +reduced_mult : reduce @multiply_func 1 5; ..assert reduced_sum = 15; ..assert reduced_mult = 5; /* Test fold with different initial values */ -folded_sum : fold @add 10 5; -folded_mult : fold @multiply 1 5; +folded_sum : fold @add_func 10 5; +folded_mult : fold @multiply_func 1 5; ..assert folded_sum = 15; ..assert folded_mult = 5; diff --git a/js/scripting-lang/tests/14_error_handling.txt b/js/scripting-lang/tests/14_error_handling.txt index ce485f7..36fa9de 100644 --- a/js/scripting-lang/tests/14_error_handling.txt +++ b/js/scripting-lang/tests/14_error_handling.txt @@ -7,9 +7,9 @@ valid_test : 5 + 3; /* Test division by zero handling */ /* This should be handled gracefully */ -safe_div : x y -> case y of - 0 : "division by zero" - _ : x / y; +safe_div : x y -> when y is + 0 then "division by zero" + _ then x / y; div_result1 : safe_div 10 2; div_result2 : safe_div 10 0; @@ -18,28 +18,28 @@ div_result2 : safe_div 10 0; ..assert div_result2 = "division by zero"; /* Test edge cases with proper handling */ -edge_case1 : case 0 of - 0 : "zero" - _ : "other"; +edge_case1 : when 0 is + 0 then "zero" + _ then "other"; -edge_case2 : case "" of - "" : "empty string" - _ : "other"; +edge_case2 : when "" is + "" then "empty string" + _ then "other"; -edge_case3 : case false of - false : "false" - _ : "other"; +edge_case3 : when false is + false then "false" + _ then "other"; ..assert edge_case1 = "zero"; ..assert edge_case2 = "empty string"; ..assert edge_case3 = "false"; /* Test complex error scenarios */ -complex_error_handling : input -> case input of - input < 0 : "negative" - input = 0 : "zero" - input > 100 : "too large" - _ : "valid"; +complex_error_handling : input -> when input is + input < 0 then "negative" + input = 0 then "zero" + input > 100 then "too large" + _ then "valid"; complex_result1 : complex_error_handling -5; complex_result2 : complex_error_handling 0; @@ -52,9 +52,9 @@ complex_result4 : complex_error_handling 50; ..assert complex_result4 = "valid"; /* Test safe arithmetic operations */ -safe_add : x y -> case y of - 0 : x - _ : x + y; +safe_add : x y -> when y is + 0 then x + _ then x + y; safe_result1 : safe_add 5 3; safe_result2 : safe_add 5 0; diff --git a/js/scripting-lang/tests/15_performance_stress.txt b/js/scripting-lang/tests/15_performance_stress.txt index 7dab1f5..0682d3d 100644 --- a/js/scripting-lang/tests/15_performance_stress.txt +++ b/js/scripting-lang/tests/15_performance_stress.txt @@ -39,21 +39,21 @@ table_size : 8; ..assert table_size = 8; /* Test recursive-like patterns with functions */ -accumulate : n -> case n of - 0 : 0 - _ : n + accumulate (n - 1); +accumulate : n -> when n is + 0 then 0 + _ then n + accumulate (n - 1); sum_10 : accumulate 10; ..assert sum_10 = 55; /* Test complex case expressions */ -complex_case : x -> case x of - x < 0 : "negative" - x = 0 : "zero" - x < 10 : "small" - x < 100 : "medium" - x < 1000 : "large" - _ : "huge"; +complex_case : x -> when x is + x < 0 then "negative" + x = 0 then "zero" + x < 10 then "small" + x < 100 then "medium" + x < 1000 then "large" + _ then "huge"; case_test1 : complex_case -5; case_test2 : complex_case 0; diff --git a/js/scripting-lang/tests/16_advanced_functional.txt b/js/scripting-lang/tests/16_advanced_functional.txt deleted file mode 100644 index 3da9d76..0000000 --- a/js/scripting-lang/tests/16_advanced_functional.txt +++ /dev/null @@ -1,169 +0,0 @@ -/* Unit Test: Advanced Functional Programming Patterns */ -/* Tests: Higher-order functions, currying, partial application, monadic patterns */ - -/* Test function composition with multiple functions */ -id : x -> x; -const : x y -> x; -flip : f x y -> f y x; - -/* Test identity function */ -id_test : id 42; -..assert id_test = 42; - -/* Test constant function */ -const_test : const 5 10; -..assert const_test = 5; - -/* Test function flipping */ -sub : x y -> x - y; -flipped_sub : flip @sub; -flipped_result : flipped_sub 5 10; -..assert flipped_result = 5; - -/* Test partial application patterns */ -partial1 : f x -> y -> f x y; -partial2 : f x y -> f x y; - -add : x y -> x + y; -add5 : partial1 @add 5; -add5_result : add5 3; -..assert add5_result = 8; - -/* Test function composition with multiple arguments */ -compose2 : f g x y -> f (g x y); -compose3 : f g h x -> f (g (h x)); - -double : x -> x * 2; -square : x -> x * x; -increment : x -> x + 1; - -composed1 : compose2 @double @add 3 4; -composed2 : compose3 @double @square @increment 2; -..assert composed1 = 14; -..assert composed2 = 18; - -/* Test monadic-like patterns with Maybe simulation */ -maybe : x -> case x of - undefined : "Nothing" - null : "Nothing" - _ : "Just " + x; - -maybe_map : f m -> case m of - "Nothing" : "Nothing" - _ : f m; - -maybe_bind : m f -> case m of - "Nothing" : "Nothing" - _ : f m; - -maybe_test1 : maybe undefined; -maybe_test2 : maybe 42; -maybe_test3 : maybe_map @double "Just 5"; -maybe_test4 : maybe_bind "Just 3" @double; - -..assert maybe_test1 = "Nothing"; -..assert maybe_test2 = "Just 42"; -..assert maybe_test3 = "Just 10"; -..assert maybe_test4 = "Just 6"; - -/* Test list-like operations with tables */ -list_map : f table -> { - f table[1], - f table[2], - f table[3] -}; - -list_filter : p table -> case p table[1] of - true : {table[1]} - false : {}; - -list_reduce : f init table -> case table[1] of - undefined : init - _ : f init table[1]; - -test_list : {1, 2, 3}; -mapped_list : list_map @double test_list; -filtered_list : list_filter (x -> x > 1) test_list; -reduced_list : list_reduce @add 0 test_list; - -..assert mapped_list[1] = 2; -..assert mapped_list[2] = 4; -..assert mapped_list[3] = 6; -..assert filtered_list[1] = 2; -..assert reduced_list = 1; - -/* Test point-free style programming */ -pointfree_add : add; -pointfree_double : double; -pointfree_compose : compose @pointfree_double @pointfree_add; - -pointfree_result : pointfree_compose 5 3; -..assert pointfree_result = 16; - -/* Test function memoization pattern */ -memoize : f -> { - cache: {}, - call: x -> case cache[x] of - undefined : cache[x] = f x - _ : cache[x] -}; - -expensive_func : x -> x * x + x + 1; -memoized_func : memoize @expensive_func; - -memo_result1 : memoized_func.call 5; -memo_result2 : memoized_func.call 5; /* Should use cache */ -..assert memo_result1 = 31; -..assert memo_result2 = 31; - -/* Test continuation-passing style (CPS) */ -cps_add : x y k -> k (x + y); -cps_multiply : x y k -> k (x * y); -cps_square : x k -> k (x * x); - -cps_example : cps_add 3 4 (sum -> - cps_multiply sum 2 (product -> - cps_square product (result -> result) - ) -); -..assert cps_example = 98; - -/* Test trampoline pattern for tail recursion simulation */ -trampoline : f -> case f of - f is function : trampoline (f) - _ : f; - -bounce : n -> case n of - 0 : 0 - _ : n + (n - 1); - -trampoline_result : trampoline @bounce 5; -..assert trampoline_result = 15; - -/* Test applicative functor pattern */ -applicative : f x -> case f of - f is function : f x - _ : x; - -applicative_test : applicative @double 5; -..assert applicative_test = 10; - -/* Test function pipelines */ -pipeline : x f1 f2 f3 -> f3 (f2 (f1 x)); -pipeline_result : pipeline 2 @increment @double @square; -..assert pipeline_result = 36; - -/* Test function combinators */ -S : f g x -> f x (g x); -K : x y -> x; -I : x -> x; - -S_test : S @add @double 3; -K_test : K 5 10; -I_test : I 42; - -..assert S_test = 9; -..assert K_test = 5; -..assert I_test = 42; - -..out "Advanced functional programming test completed successfully"; \ No newline at end of file diff --git a/js/scripting-lang/tests/16_function_composition.txt b/js/scripting-lang/tests/16_function_composition.txt new file mode 100644 index 0000000..6b1b13f --- /dev/null +++ b/js/scripting-lang/tests/16_function_composition.txt @@ -0,0 +1,59 @@ +/* Function Composition Test Suite */ + +/* Test basic function definitions */ +double : x -> x * 2; +add1 : x -> x + 1; +square : x -> x * x; + +/* Test 1: Basic composition with compose */ +result1 : compose @double @add1 5; +..out result1; + +/* Test 2: Multiple composition with compose */ +result2 : compose @double (compose @add1 @square) 3; +..out result2; + +/* Test 3: Function references */ +ref1 : @double; +..out ref1; + +/* Test 4: Function references in composition */ +result3 : compose @double @add1 5; +..out result3; + +/* Test 5: Pipe function (binary) */ +result4 : pipe @double @add1 5; +..out result4; + +/* Test 6: Compose function (binary) */ +result5 : compose @double @add1 2; +..out result5; + +/* Test 7: Multiple composition with pipe */ +result6 : pipe @square (pipe @add1 @double) 2; +..out result6; + +/* Test 8: Backward compatibility - arithmetic */ +x : 10; +result7 : x + 5; +..out result7; + +/* Test 9: Backward compatibility - function application */ +result8 : double x; +..out result8; + +/* Test 10: Backward compatibility - nested application */ +result9 : double (add1 x); +..out result9; + +/* Test 11: Backward compatibility - unary operators */ +result10 : -x; +..out result10; + +/* Test 12: Backward compatibility - logical operators */ +result11 : not true; +..out result11; + +/* Test 13: Complex composition chain */ +result12 : compose @square (compose @add1 (compose @double @add1)) 3; +..out result12; \ No newline at end of file diff --git a/js/scripting-lang/tests/17_real_world_scenarios.txt b/js/scripting-lang/tests/17_real_world_scenarios.txt deleted file mode 100644 index 0a9fc49..0000000 --- a/js/scripting-lang/tests/17_real_world_scenarios.txt +++ /dev/null @@ -1,219 +0,0 @@ -/* Unit Test: Real-World Programming Scenarios */ -/* Tests: Practical use cases, data processing, business logic */ - -/* Scenario 1: User Management System */ -/* Define user types and validation */ -isValidEmail : email -> case email of - email contains "@" : true - _ : false; - -isValidAge : age -> case age of - age >= 0 and age <= 120 : true - _ : false; - -createUser : name email age -> case (isValidEmail email) and (isValidAge age) of - true : { - name: name, - email: email, - age: age, - status: "active" - } - false : "invalid user data"; - -user1 : createUser "Alice" "alice@example.com" 25; -user2 : createUser "Bob" "invalid-email" 30; -user3 : createUser "Charlie" "charlie@test.com" 150; - -..assert user1.name = "Alice"; -..assert user2 = "invalid user data"; -..assert user3 = "invalid user data"; - -/* Scenario 2: Shopping Cart System */ -/* Product definitions */ -product1 : {id: 1, name: "Laptop", price: 999.99, category: "electronics"}; -product2 : {id: 2, name: "Book", price: 19.99, category: "books"}; -product3 : {id: 3, name: "Coffee", price: 4.99, category: "food"}; - -/* Cart operations */ -addToCart : cart product -> { - cart, - product -}; - -calculateTotal : cart -> case cart of - cart is table : cart.product.price - _ : 0; - -applyDiscount : total discount -> case discount of - discount > 0 and discount <= 100 : total * (1 - discount / 100) - _ : total; - -cart : addToCart {} product1; -cart : addToCart cart product2; -total : calculateTotal cart; -discounted : applyDiscount total 10; - -..assert total = 1019.98; -..assert discounted = 917.982; - -/* Scenario 3: Data Processing Pipeline */ -/* Sample data */ -sales_data : { - {month: "Jan", sales: 1000, region: "North"}, - {month: "Feb", sales: 1200, region: "North"}, - {month: "Mar", sales: 800, region: "South"}, - {month: "Apr", sales: 1500, region: "North"}, - {month: "May", sales: 900, region: "South"} -}; - -/* Data processing functions */ -filterByRegion : data region -> case data of - data.region = region : data - _ : null; - -sumSales : data -> case data of - data is table : data.sales - _ : 0; - -calculateAverage : total count -> case count of - count > 0 : total / count - _ : 0; - -/* Process North region sales */ -north_sales : filterByRegion sales_data "North"; -north_total : sumSales north_sales; -north_avg : calculateAverage north_total 3; - -..assert north_total = 3700; -..assert north_avg = 1233.3333333333333; - -/* Scenario 4: Configuration Management */ -/* Environment configuration */ -getConfig : env -> case env of - "development" : { - database: "dev_db", - port: 3000, - debug: true, - log_level: "debug" - } - "production" : { - database: "prod_db", - port: 80, - debug: false, - log_level: "error" - } - "testing" : { - database: "test_db", - port: 3001, - debug: true, - log_level: "info" - } - _ : "unknown environment"; - -dev_config : getConfig "development"; -prod_config : getConfig "production"; - -..assert dev_config.debug = true; -..assert prod_config.debug = false; -..assert dev_config.port = 3000; -..assert prod_config.port = 80; - -/* Scenario 5: Error Handling and Recovery */ -/* Robust function with error handling */ -safeDivide : x y -> case y of - 0 : "division by zero error" - _ : x / y; - -safeParseNumber : str -> case str of - str is number : str - _ : "invalid number"; - -processData : data -> case data of - data is number : data * 2 - data is string : safeParseNumber data - _ : "unsupported data type"; - -safe_result1 : safeDivide 10 2; -safe_result2 : safeDivide 10 0; -safe_result3 : processData 5; -safe_result4 : processData "abc"; - -..assert safe_result1 = 5; -..assert safe_result2 = "division by zero error"; -..assert safe_result3 = 10; -..assert safe_result4 = "invalid number"; - -/* Scenario 6: Event Handling System */ -/* Event types and handlers */ -eventHandlers : { - "user.login": x -> "User logged in: " + x, - "user.logout": x -> "User logged out: " + x, - "order.created": x -> "Order created: " + x, - "order.completed": x -> "Order completed: " + x -}; - -handleEvent : event data -> case eventHandlers[event] of - handler : handler data - _ : "Unknown event: " + event; - -login_event : handleEvent "user.login" "alice@example.com"; -logout_event : handleEvent "user.logout" "bob@example.com"; -unknown_event : handleEvent "unknown.event" "data"; - -..assert login_event = "User logged in: alice@example.com"; -..assert logout_event = "User logged out: bob@example.com"; -..assert unknown_event = "Unknown event: unknown.event"; - -/* Scenario 7: Caching System */ -/* Simple cache implementation */ -cache : {}; - -setCache : key value -> cache[key] = value; -getCache : key -> case cache[key] of - undefined : "not found" - value : value; -clearCache : key -> cache[key] = undefined; - -setCache "user.1" "Alice"; -setCache "user.2" "Bob"; -cache_result1 : getCache "user.1"; -cache_result2 : getCache "user.999"; -clearCache "user.1"; -cache_result3 : getCache "user.1"; - -..assert cache_result1 = "Alice"; -..assert cache_result2 = "not found"; -..assert cache_result3 = "not found"; - -/* Scenario 8: API Response Processing */ -/* Mock API responses */ -apiResponse : { - status: 200, - data: { - users: { - {id: 1, name: "Alice", active: true}, - {id: 2, name: "Bob", active: false}, - {id: 3, name: "Charlie", active: true} - }, - total: 3 - } -}; - -processApiResponse : response -> case response.status of - 200 : response.data - 404 : "not found" - 500 : "server error" - _ : "unknown status"; - -getActiveUsers : data -> case data.users of - users : case users.active of - true : users - _ : null; - -api_data : processApiResponse apiResponse; -active_users : getActiveUsers api_data; - -..assert api_data.total = 3; -..assert active_users = null; /* Simplified for this example */ - -..out "Real-world scenarios test completed successfully"; \ No newline at end of file diff --git a/js/scripting-lang/tests/dev_01_simple_test.txt b/js/scripting-lang/tests/dev_01_simple_test.txt new file mode 100644 index 0000000..74edad2 --- /dev/null +++ b/js/scripting-lang/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/tests/dev_02_test_parser_changes.txt b/js/scripting-lang/tests/dev_02_test_parser_changes.txt new file mode 100644 index 0000000..a4af8bb --- /dev/null +++ b/js/scripting-lang/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/tests/integration_01_basic_features.txt b/js/scripting-lang/tests/integration_01_basic_features.txt index cb215ab..f669f8a 100644 --- a/js/scripting-lang/tests/integration_01_basic_features.txt +++ b/js/scripting-lang/tests/integration_01_basic_features.txt @@ -4,15 +4,15 @@ ..out "=== Integration Test: Basic Features ==="; /* Define utility functions */ -add : x y -> x + y; -multiply : x y -> x * y; +add_func : x y -> x + y; +multiply_func : x y -> x * y; isEven : x -> x % 2 = 0; isPositive : x -> x > 0; /* Test arithmetic with functions */ -sum : add 10 5; -product : multiply 4 6; -doubled : multiply 2 sum; +sum : add_func 10 5; +product : multiply_func 4 6; +doubled : multiply_func 2 sum; ..assert sum = 15; ..assert product = 24; @@ -30,7 +30,7 @@ negative_test : isPositive -3; ..assert negative_test = false; /* Test complex expressions */ -complex : add (multiply 3 4) (isEven 10 and isPositive 5); +complex : add_func (multiply_func 3 4) (isEven 10 and isPositive 5); ..assert complex = 13; diff --git a/js/scripting-lang/tests/integration_02_pattern_matching.txt b/js/scripting-lang/tests/integration_02_pattern_matching.txt index f0b969a..a67bf59 100644 --- a/js/scripting-lang/tests/integration_02_pattern_matching.txt +++ b/js/scripting-lang/tests/integration_02_pattern_matching.txt @@ -5,21 +5,21 @@ /* Recursive factorial with case expressions */ factorial : n -> - case n of - 0 : 1 - _ : n * (factorial (n - 1)); + when n is + 0 then 1 + _ then n * (factorial (n - 1)); /* Pattern matching with multiple parameters */ classify : x y -> - case x y of - 0 0 : "both zero" - 0 _ : "x is zero" - _ 0 : "y is zero" - _ _ : case x of - 0 : "x is zero (nested)" - _ : case y of - 0 : "y is zero (nested)" - _ : "neither zero"; + 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; @@ -41,15 +41,15 @@ test4 : classify 5 5; /* Complex nested case expressions */ analyze : x y z -> - case x y z of - 0 0 0 : "all zero" - 0 0 _ : "x and y zero" - 0 _ 0 : "x and z zero" - _ 0 0 : "y and z zero" - 0 _ _ : "only x zero" - _ 0 _ : "only y zero" - _ _ 0 : "only z zero" - _ _ _ : "none zero"; + when x y z is + 0 0 0 then "all zero" + 0 0 _ then "x and y zero" + 0 _ 0 then "x and z zero" + _ 0 0 then "y and z zero" + 0 _ _ then "only x zero" + _ 0 _ then "only y zero" + _ _ 0 then "only z zero" + _ _ _ then "none zero"; result1 : analyze 0 0 0; result2 : analyze 0 1 1; diff --git a/js/scripting-lang/tests/integration_03_functional_programming.txt b/js/scripting-lang/tests/integration_03_functional_programming.txt index 8af6760..a0e3668 100644 --- a/js/scripting-lang/tests/integration_03_functional_programming.txt +++ b/js/scripting-lang/tests/integration_03_functional_programming.txt @@ -4,33 +4,33 @@ ..out "=== Integration Test: Functional Programming ==="; /* Basic functions */ -double : x -> x * 2; -square : x -> x * x; +double_func : x -> x * 2; +square_func : x -> x * x; add1 : x -> x + 1; -identity : x -> x; +identity_func : x -> x; isEven : x -> x % 2 = 0; /* Function composition */ -composed1 : compose @double @square 3; -composed2 : compose @square @double 2; -composed3 : compose @add1 @double 5; +composed1 : compose @double_func @square_func 3; +composed2 : compose @square_func @double_func 2; +composed3 : compose @add1 @double_func 5; ..assert composed1 = 18; ..assert composed2 = 16; ..assert composed3 = 11; /* Function piping */ -piped1 : pipe @double @square 3; -piped2 : pipe @square @double 2; -piped3 : pipe @add1 @double 5; +piped1 : pipe @double_func @square_func 3; +piped2 : pipe @square_func @double_func 2; +piped3 : pipe @add1 @double_func 5; ..assert piped1 = 36; ..assert piped2 = 8; ..assert piped3 = 12; /* Function application */ -applied1 : apply @double 7; -applied2 : apply @square 4; +applied1 : apply @double_func 7; +applied2 : apply @square_func 4; applied3 : apply @add1 10; ..assert applied1 = 14; @@ -39,11 +39,11 @@ applied3 : apply @add1 10; /* Function selection with case expressions */ getOperation : type -> - case type of - "double" : @double - "square" : @square - "add1" : @add1 - _ : @identity; + when type is + "double" then @double_func + "square" then @square_func + "add1" then @add1 + _ then @identity_func; /* Test function selection */ op1 : getOperation "double"; @@ -62,7 +62,7 @@ result4 : op4 3; ..assert result4 = 3; /* Complex functional composition */ -complex : compose @double (compose @square @add1) 3; +complex : compose @double_func (compose @square_func @add1) 3; ..assert complex = 32; ..out "Functional programming integration test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/integration_04_mini_case_multi_param.txt b/js/scripting-lang/tests/integration_04_mini_case_multi_param.txt index be4b71d..1814ae5 100644 --- a/js/scripting-lang/tests/integration_04_mini_case_multi_param.txt +++ b/js/scripting-lang/tests/integration_04_mini_case_multi_param.txt @@ -1,17 +1,21 @@ -/* Multi-parameter case expression at top level */ -x : 1; -y : 2; -result1 : case x y of - 1 2 : "matched" - _ _ : "not matched"; +/* Integration Test: Multi-parameter case expression at top level */ -/* Multi-parameter case expression inside a function */ -f : a b -> case a b of - 1 2 : "matched" - _ _ : "not matched"; -result2 : f 1 2; -result3 : f 3 4; +/* Test multi-parameter case expressions */ +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"; -..out result1; -..out result2; -..out result3; \ No newline at end of file +test1 : compare 0 0; +test2 : compare 0 5; +test3 : compare 5 0; +test4 : compare 5 5; + +..assert test1 = "both zero"; +..assert test2 = "x is zero"; +..assert test3 = "y is zero"; +..assert test4 = "neither zero"; + +..out "Multi-parameter case expression test completed"; \ No newline at end of file |