diff options
Diffstat (limited to 'js/scripting-lang/tests')
22 files changed, 1093 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/01_lexer_basic.txt b/js/scripting-lang/tests/01_lexer_basic.txt new file mode 100644 index 0000000..90693f1 --- /dev/null +++ b/js/scripting-lang/tests/01_lexer_basic.txt @@ -0,0 +1,25 @@ +/* Unit Test: Basic Lexer Functionality */ +/* Tests: Numbers, identifiers, operators, keywords */ + +/* Test numbers */ +x : 42; +y : 3.14; +z : 0; + +/* Test identifiers */ +name : "test"; +flag : true; +value : false; + +/* Test basic operators */ +sum : x + y; +diff : x - y; +prod : x * y; +quot : x / y; + +/* Test keywords */ +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 new file mode 100644 index 0000000..d4c0648 --- /dev/null +++ b/js/scripting-lang/tests/02_arithmetic_operations.txt @@ -0,0 +1,31 @@ +/* Unit Test: Arithmetic Operations */ +/* Tests: All arithmetic operators and precedence */ + +/* Basic arithmetic */ +a : 10; +b : 3; +sum : a + b; +diff : a - b; +product : a * b; +quotient : a / b; +moduloResult : a % b; +powerResult : a ^ b; + +/* Test results */ +..assert sum = 13; +..assert diff = 7; +..assert product = 30; +..assert quotient = 3.3333333333333335; +..assert moduloResult = 1; +..assert powerResult = 1000; + +/* Complex expressions with parentheses */ +complex1 : (5 + 3) * 2; +complex2 : ((10 - 2) * 3) + 1; +complex3 : (2 ^ 3) % 5; + +..assert complex1 = 16; +..assert complex2 = 25; +..assert complex3 = 3; + +..out "Arithmetic operations test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/03_comparison_operators.txt b/js/scripting-lang/tests/03_comparison_operators.txt new file mode 100644 index 0000000..f122a84 --- /dev/null +++ b/js/scripting-lang/tests/03_comparison_operators.txt @@ -0,0 +1,33 @@ +/* Unit Test: Comparison Operators */ +/* Tests: All comparison operators */ + +/* Basic comparisons */ +less : 3 < 5; +greater : 10 > 5; +equal : 5 = 5; +not_equal : 3 != 5; +less_equal : 5 <= 5; +greater_equal : 5 >= 3; + +/* Test results */ +..assert less = true; +..assert greater = true; +..assert equal = true; +..assert not_equal = true; +..assert less_equal = true; +..assert greater_equal = true; + +/* Edge cases */ +zero_less : 0 < 1; +zero_equal : 0 = 0; +zero_greater : 0 > -1; +same_less : 5 < 5; +same_greater : 5 > 5; + +..assert zero_less = true; +..assert zero_equal = true; +..assert zero_greater = true; +..assert same_less = false; +..assert same_greater = false; + +..out "Comparison operators test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/04_logical_operators.txt b/js/scripting-lang/tests/04_logical_operators.txt new file mode 100644 index 0000000..591e04b --- /dev/null +++ b/js/scripting-lang/tests/04_logical_operators.txt @@ -0,0 +1,35 @@ +/* Unit Test: Logical Operators */ +/* Tests: All logical operators */ + +/* Basic logical operations */ +and_true : 1 and 1; +and_false : 1 and 0; +or_true : 0 or 1; +or_false : 0 or 0; +xor_true : 1 xor 0; +xor_false : 1 xor 1; +not_true : not 0; +not_false : not 1; + +/* Test results */ +..assert and_true = true; +..assert and_false = false; +..assert or_true = true; +..assert or_false = false; +..assert xor_true = true; +..assert xor_false = false; +..assert not_true = true; +..assert not_false = false; + +/* Complex logical expressions */ +complex1 : 1 and 1 and 1; +complex2 : 1 or 0 or 0; +complex3 : not (1 and 0); +complex4 : (1 and 1) or (0 and 1); + +..assert complex1 = true; +..assert complex2 = true; +..assert complex3 = true; +..assert complex4 = true; + +..out "Logical operators test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/05_io_operations.txt b/js/scripting-lang/tests/05_io_operations.txt new file mode 100644 index 0000000..a16bf94 --- /dev/null +++ b/js/scripting-lang/tests/05_io_operations.txt @@ -0,0 +1,28 @@ +/* Unit Test: IO Operations */ +/* Tests: ..out, ..assert operations */ + +/* Test basic output */ +..out "Testing IO operations"; + +/* Test assertions */ +x : 5; +y : 3; +sum : x + y; + +..assert x = 5; +..assert y = 3; +..assert sum = 8; +..assert x > 3; +..assert y < 10; +..assert sum != 0; + +/* Test string comparisons */ +..assert "hello" = "hello"; +..assert "world" != "hello"; + +/* Test complex assertions */ +..assert (x + y) = 8; +..assert (x * y) = 15; +..assert (x > y) = true; + +..out "IO operations test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/06_function_definitions.txt b/js/scripting-lang/tests/06_function_definitions.txt new file mode 100644 index 0000000..b0e591f --- /dev/null +++ b/js/scripting-lang/tests/06_function_definitions.txt @@ -0,0 +1,32 @@ +/* Unit Test: Function Definitions */ +/* Tests: Function syntax, parameters, calls */ + +/* Basic function definitions */ +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_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; +..assert result2 = 30; +..assert result3 = 16; +..assert result4 = 16; +..assert result5 = 42; + +/* Test function calls with parentheses */ +result6 : add_func @(3 + 2) @(4 + 1); +result7 : multiply_func @(double_func 3) @(square_func 2); + +..assert result6 = 10; +..assert result7 = 24; + +..out "Function definitions test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/07_case_expressions.txt b/js/scripting-lang/tests/07_case_expressions.txt new file mode 100644 index 0000000..35f0aa2 --- /dev/null +++ b/js/scripting-lang/tests/07_case_expressions.txt @@ -0,0 +1,47 @@ +/* Unit Test: Case Expressions */ +/* Tests: Pattern matching, wildcards, nested cases */ + +/* Basic case expressions */ +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +grade : score -> + when score is + 90 then "A" + 80 then "B" + 70 then "C" + _ then "F"; + +/* Test case expressions */ +fact5 : factorial 5; +grade1 : grade 95; +grade2 : grade 85; +grade3 : grade 65; + +/* Test results */ +..assert fact5 = 120; +..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 -> + 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; + +..assert test1 = "both zero"; +..assert test2 = "x is zero"; +..assert test3 = "y is zero"; +..assert test4 = "neither zero"; + +..out "Case expressions test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/08_first_class_functions.txt b/js/scripting-lang/tests/08_first_class_functions.txt new file mode 100644 index 0000000..75fda40 --- /dev/null +++ b/js/scripting-lang/tests/08_first_class_functions.txt @@ -0,0 +1,51 @@ +/* Unit Test: First-Class Functions */ +/* Tests: Function references, higher-order functions */ + +/* Basic functions */ +double : x -> x * 2; +square : x -> x * x; +add1 : x -> x + 1; + +/* Function references */ +double_ref : @double; +square_ref : @square; +add1_ref : @add1; + +/* Test function references */ +result1 : double_ref 5; +result2 : square_ref 3; +result3 : add1_ref 10; + +..assert result1 = 10; +..assert result2 = 9; +..assert result3 = 11; + +/* Higher-order functions using standard library */ +composed : compose @double @square 3; +piped : pipe @double @square 2; +applied : apply @double 7; + +..assert composed = 18; +..assert piped = 16; +..assert applied = 14; + +/* Function references in case expressions */ +getFunction : type -> + when type is + "double" then @double + "square" then @square + _ then @add1; + +func1 : getFunction "double"; +func2 : getFunction "square"; +func3 : getFunction "unknown"; + +result4 : func1 4; +result5 : func2 4; +result6 : func3 4; + +..assert result4 = 8; +..assert result5 = 16; +..assert result6 = 5; + +..out "First-class functions test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/09_tables.txt b/js/scripting-lang/tests/09_tables.txt new file mode 100644 index 0000000..3845903 --- /dev/null +++ b/js/scripting-lang/tests/09_tables.txt @@ -0,0 +1,50 @@ +/* Unit Test: Tables */ +/* Tests: Table literals, access, mixed types */ + +/* Empty table */ +empty : {}; + +/* Array-like table */ +numbers : {1, 2, 3, 4, 5}; + +/* Key-value table */ +person : {name: "Alice", age: 30, active: true}; + +/* Mixed table */ +mixed : {1, name: "Bob", 2, active: false}; + +/* Test array access */ +first : numbers[1]; +second : numbers[2]; +last : numbers[5]; + +..assert first = 1; +..assert second = 2; +..assert last = 5; + +/* Test object access */ +name : person.name; +age : person.age; +active : person.active; + +..assert name = "Alice"; +..assert age = 30; +..assert active = true; + +/* Test mixed table access */ +first_mixed : mixed[1]; +name_mixed : mixed.name; +second_mixed : mixed[2]; + +..assert first_mixed = 1; +..assert name_mixed = "Bob"; +..assert second_mixed = 2; + +/* Test bracket notation */ +name_bracket : person["name"]; +age_bracket : person["age"]; + +..assert name_bracket = "Alice"; +..assert age_bracket = 30; + +..out "Tables test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/10_standard_library.txt b/js/scripting-lang/tests/10_standard_library.txt new file mode 100644 index 0000000..221d5ca --- /dev/null +++ b/js/scripting-lang/tests/10_standard_library.txt @@ -0,0 +1,40 @@ +/* Unit Test: Standard Library */ +/* Tests: All built-in higher-order functions */ + +/* Basic functions for testing */ +double_func : x -> x * 2; +square_func : x -> x * x; +add_func : x y -> x + y; +isPositive : x -> x > 0; + +/* Map function */ +mapped1 : map @double_func 5; +mapped2 : map @square_func 3; + +..assert mapped1 = 10; +..assert mapped2 = 9; + +/* Compose function */ +composed : compose @double_func @square_func 3; +..assert composed = 18; + +/* Pipe function */ +piped : pipe @double_func @square_func 2; +..assert piped = 16; + +/* Apply function */ +applied : apply @double_func 7; +..assert applied = 14; + +/* Reduce and Fold functions */ +reduced : reduce @add_func 0 5; +folded : fold @add_func 0 5; + +..assert reduced = 5; +..assert folded = 5; + +/* Curry function */ +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 new file mode 100644 index 0000000..dce90e3 --- /dev/null +++ b/js/scripting-lang/tests/11_edge_cases.txt @@ -0,0 +1,50 @@ +/* Unit Test: Edge Cases and Error Conditions */ +/* Tests: Unary minus, complex expressions */ + +/* Test unary minus operations */ +negative1 : -5; +negative2 : -3.14; +negative3 : -0; + +..assert negative1 = -5; +..assert negative2 = -3.14; +..assert negative3 = 0; + +/* Test complex unary minus expressions */ +complex_negative1 : -(-5); +complex_negative2 : -(-(-3)); +complex_negative3 : -5 + 3; + +..assert complex_negative1 = 5; +..assert complex_negative2 = -3; +..assert complex_negative3 = -2; + +/* Test unary minus in function calls */ +abs : x -> when x is + x < 0 then -x + _ then x; + +abs1 : abs -5; +abs2 : abs 5; + +..assert abs1 = 5; +..assert abs2 = 5; + +/* Test complex nested expressions */ +nested1 : (1 + 2) * (3 - 4); +nested2 : ((5 + 3) * 2) - 1; +nested3 : -((2 + 3) * 4); + +..assert nested1 = -3; +..assert nested2 = 15; +..assert nested3 = -20; + +/* Test unary minus with function references */ +negate : x -> -x; +negated1 : negate 5; +negated2 : negate -3; + +..assert negated1 = -5; +..assert negated2 = 3; + +..out "Edge cases test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/12_advanced_tables.txt b/js/scripting-lang/tests/12_advanced_tables.txt new file mode 100644 index 0000000..3b2a326 --- /dev/null +++ b/js/scripting-lang/tests/12_advanced_tables.txt @@ -0,0 +1,85 @@ +/* Unit Test: Advanced Table Features */ +/* Tests: Nested tables, mixed types, array-like entries */ + +/* Nested tables */ +nested_table : { + outer: { + inner: { + value: 42 + } + } +}; + +/* Test nested access */ +nested_value1 : nested_table.outer.inner.value; +..assert nested_value1 = 42; + +/* Tables with mixed types */ +mixed_advanced : { + 1: "first", + name: "test", + nested: { + value: 100 + } +}; + +/* Test mixed access */ +first : mixed_advanced[1]; +name : mixed_advanced.name; +nested_value2 : mixed_advanced.nested.value; + +..assert first = "first"; +..assert name = "test"; +..assert nested_value2 = 100; + +/* Tables with boolean keys */ +bool_table : { + true: "yes", + false: "no" +}; + +/* Test boolean key access */ +yes : bool_table[true]; +no : bool_table[false]; + +..assert yes = "yes"; +..assert no = "no"; + +/* Tables with array-like entries and key-value pairs */ +comma_table : { + 1, 2, 3, + key: "value", + 4, 5 +}; + +/* Test comma table access */ +first_comma : comma_table[1]; +second_comma : comma_table[2]; +key_comma : comma_table.key; +fourth_comma : comma_table[4]; + +..assert first_comma = 1; +..assert second_comma = 2; +..assert key_comma = "value"; +..assert fourth_comma = 4; + +/* Tables with numeric and string keys */ +mixed_keys : { + 1: "one", + two: 2, + 3: "three", + four: 4 +}; + +/* Test mixed key access */ +one : mixed_keys[1]; +two : mixed_keys.two; +three : mixed_keys[3]; +four : mixed_keys.four; + +..assert one = "one"; +..assert two = 2; +..assert three = "three"; +..assert four = 4; + +..out "Advanced tables test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/13_standard_library_complete.txt b/js/scripting-lang/tests/13_standard_library_complete.txt new file mode 100644 index 0000000..c73396a --- /dev/null +++ b/js/scripting-lang/tests/13_standard_library_complete.txt @@ -0,0 +1,97 @@ +/* Unit Test: Complete Standard Library */ +/* Tests: All built-in higher-order functions including reduce, fold, curry */ + +/* Basic functions for testing */ +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_func 5; +mapped2 : map @square_func 3; + +..assert mapped1 = 10; +..assert mapped2 = 9; + +/* Compose function */ +composed : compose @double_func @square_func 3; +..assert composed = 18; + +/* Pipe function */ +piped : pipe @double_func @square_func 2; +..assert piped = 16; + +/* Apply function */ +applied : apply @double_func 7; +..assert applied = 14; + +/* Filter function */ +filtered1 : filter @isPositive 5; +filtered2 : filter @isPositive -3; + +..assert filtered1 = 5; +..assert filtered2 = 0; + +/* Reduce function */ +reduced : reduce @add_func 0 5; +..assert reduced = 5; + +/* Fold function */ +folded : fold @add_func 0 5; +..assert folded = 5; + +/* Curry function */ +curried : curry @add_func 3 4; +..assert curried = 7; + +/* Test partial application */ +compose_partial : compose @double_func @square_func; +compose_result : compose_partial 3; +..assert compose_result = 18; + +pipe_partial : pipe @double_func @square_func; +pipe_result : pipe_partial 2; +..assert pipe_result = 16; + +/* Test with negative numbers */ +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_func @complex_func 3; +complex_pipe : pipe @complex_func @double_func 3; + +..assert complex_compose = 20; +..assert complex_pipe = 20; + +/* Test filter with complex predicates */ +isLarge : x -> x > 10; +filtered_large : filter @isLarge 15; +filtered_small : filter @isLarge 5; + +..assert filtered_large = 15; +..assert filtered_small = 0; + +/* Test reduce with different initial values */ +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_func 10 5; +folded_mult : fold @multiply_func 1 5; + +..assert folded_sum = 15; +..assert folded_mult = 5; + +..out "Complete standard library test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/14_error_handling.txt b/js/scripting-lang/tests/14_error_handling.txt new file mode 100644 index 0000000..36fa9de --- /dev/null +++ b/js/scripting-lang/tests/14_error_handling.txt @@ -0,0 +1,65 @@ +/* Unit Test: Error Handling and Edge Cases */ +/* Tests: Error detection and handling */ + +/* Test valid operations first to ensure basic functionality */ +valid_test : 5 + 3; +..assert valid_test = 8; + +/* Test division by zero handling */ +/* This should be handled gracefully */ +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; + +..assert div_result1 = 5; +..assert div_result2 = "division by zero"; + +/* Test edge cases with proper handling */ +edge_case1 : when 0 is + 0 then "zero" + _ then "other"; + +edge_case2 : when "" is + "" then "empty string" + _ then "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 -> 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; +complex_result3 : complex_error_handling 150; +complex_result4 : complex_error_handling 50; + +..assert complex_result1 = "negative"; +..assert complex_result2 = "zero"; +..assert complex_result3 = "too large"; +..assert complex_result4 = "valid"; + +/* Test safe arithmetic operations */ +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; + +..assert safe_result1 = 8; +..assert safe_result2 = 5; + +..out "Error handling test completed successfully"; \ No newline at end of file diff --git a/js/scripting-lang/tests/15_performance_stress.txt b/js/scripting-lang/tests/15_performance_stress.txt new file mode 100644 index 0000000..0682d3d --- /dev/null +++ b/js/scripting-lang/tests/15_performance_stress.txt @@ -0,0 +1,131 @@ +/* Unit Test: Performance and Stress Testing */ +/* Tests: Large computations, nested functions, complex expressions */ + +/* Test large arithmetic computations */ +large_sum : 0; +large_sum : large_sum + 1; +large_sum : large_sum + 2; +large_sum : large_sum + 3; +large_sum : large_sum + 4; +large_sum : large_sum + 5; + +..assert large_sum = 15; + +/* Test nested function calls */ +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; +..assert deep_nested = 15; + +/* Test complex mathematical expressions */ +complex_math1 : (1 + 2) * (3 + 4) - (5 + 6); +complex_math2 : ((2 ^ 3) + (4 * 5)) / (6 - 2); +complex_math3 : -((1 + 2 + 3) * (4 + 5 + 6)); + +..assert complex_math1 = 10; +..assert complex_math2 = 7; +..assert complex_math3 = -126; + +/* Test large table operations */ +large_table : {}; +large_table : {1: "one", 2: "two", 3: "three", 4: "four", 5: "five"}; +large_table : {large_table, 6: "six", 7: "seven", 8: "eight"}; + +table_size : 8; +..assert table_size = 8; + +/* Test recursive-like patterns with functions */ +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 -> 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; +case_test3 : complex_case 5; +case_test4 : complex_case 50; +case_test5 : complex_case 500; +case_test6 : complex_case 5000; + +..assert case_test1 = "negative"; +..assert case_test2 = "zero"; +..assert case_test3 = "small"; +..assert case_test4 = "medium"; +..assert case_test5 = "large"; +..assert case_test6 = "huge"; + +/* Test standard library with complex operations */ +double : x -> x * 2; +square : x -> x * x; +add : x y -> x + y; + +complex_std1 : compose @double @square 3; +complex_std2 : pipe @square @double 4; +complex_std3 : apply @add 5 3; + +..assert complex_std1 = 18; +..assert complex_std2 = 32; +..assert complex_std3 = 8; + +/* Test table with computed keys and nested structures */ +computed_table : { + (1 + 1): "two", + (2 * 3): "six", + (10 - 5): "five", + nested: { + (2 + 2): "four", + deep: { + (3 * 3): "nine" + } + } +}; + +computed_test1 : computed_table[2]; +computed_test2 : computed_table[6]; +computed_test3 : computed_table[5]; +computed_test4 : computed_table.nested[4]; +computed_test5 : computed_table.nested.deep[9]; + +..assert computed_test1 = "two"; +..assert computed_test2 = "six"; +..assert computed_test3 = "five"; +..assert computed_test4 = "four"; +..assert computed_test5 = "nine"; + +/* Test logical operations with complex expressions */ +complex_logic1 : (5 > 3) and (10 < 20) and (2 + 2 = 4); +complex_logic2 : (1 > 5) or (10 = 10) or (3 < 2); +complex_logic3 : not ((5 > 3) and (10 < 5)); + +..assert complex_logic1 = true; +..assert complex_logic2 = true; +..assert complex_logic3 = true; + +/* 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 @f2 @f3 @f4 10; +composed2 : pipe @f4 @f3 @f2 @f1 10; + +..assert composed1 = 10; +..assert composed2 = 10; + +..out "Performance and stress 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/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 new file mode 100644 index 0000000..f669f8a --- /dev/null +++ b/js/scripting-lang/tests/integration_01_basic_features.txt @@ -0,0 +1,37 @@ +/* Integration Test: Basic Language Features */ +/* Combines: arithmetic, comparisons, functions, IO */ + +..out "=== Integration Test: Basic Features ==="; + +/* Define utility functions */ +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_func 10 5; +product : multiply_func 4 6; +doubled : multiply_func 2 sum; + +..assert sum = 15; +..assert product = 24; +..assert doubled = 30; + +/* Test comparisons with functions */ +even_test : isEven 8; +odd_test : isEven 7; +positive_test : isPositive 5; +negative_test : isPositive -3; + +..assert even_test = true; +..assert odd_test = false; +..assert positive_test = true; +..assert negative_test = false; + +/* Test complex expressions */ +complex : add_func (multiply_func 3 4) (isEven 10 and isPositive 5); + +..assert complex = 13; + +..out "Basic features integration test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/integration_02_pattern_matching.txt b/js/scripting-lang/tests/integration_02_pattern_matching.txt new file mode 100644 index 0000000..a67bf59 --- /dev/null +++ b/js/scripting-lang/tests/integration_02_pattern_matching.txt @@ -0,0 +1,64 @@ +/* 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; + +..assert fact5 = 120; +..assert fact3 = 6; + +/* Test classification */ +test1 : classify 0 0; +test2 : classify 0 5; +test3 : classify 5 0; +test4 : classify 5 5; + +..assert test1 = "both zero"; +..assert test2 = "x is zero"; +..assert test3 = "y is zero"; +..assert test4 = "neither zero"; + +/* Complex nested case expressions */ +analyze : x y z -> + 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; +result3 : analyze 1 0 1; +result4 : analyze 1 1 1; + +..assert result1 = "all zero"; +..assert result2 = "only x zero"; +..assert result3 = "only y zero"; +..assert result4 = "none zero"; + +..out "Pattern matching integration test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/integration_03_functional_programming.txt b/js/scripting-lang/tests/integration_03_functional_programming.txt new file mode 100644 index 0000000..a0e3668 --- /dev/null +++ b/js/scripting-lang/tests/integration_03_functional_programming.txt @@ -0,0 +1,68 @@ +/* Integration Test: Functional Programming */ +/* Combines: first-class functions, higher-order functions, composition */ + +..out "=== Integration Test: Functional Programming ==="; + +/* Basic functions */ +double_func : x -> x * 2; +square_func : x -> x * x; +add1 : x -> x + 1; +identity_func : x -> x; +isEven : x -> x % 2 = 0; + +/* Function composition */ +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_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_func 7; +applied2 : apply @square_func 4; +applied3 : apply @add1 10; + +..assert applied1 = 14; +..assert applied2 = 16; +..assert applied3 = 11; + +/* Function selection with case expressions */ +getOperation : type -> + when type is + "double" then @double_func + "square" then @square_func + "add1" then @add1 + _ then @identity_func; + +/* Test function selection */ +op1 : getOperation "double"; +op2 : getOperation "square"; +op3 : getOperation "add1"; +op4 : getOperation "unknown"; + +result1 : op1 5; +result2 : op2 4; +result3 : op3 7; +result4 : op4 3; + +..assert result1 = 10; +..assert result2 = 16; +..assert result3 = 8; +..assert result4 = 3; + +/* Complex functional composition */ +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 new file mode 100644 index 0000000..1814ae5 --- /dev/null +++ b/js/scripting-lang/tests/integration_04_mini_case_multi_param.txt @@ -0,0 +1,21 @@ +/* Integration Test: Multi-parameter case expression at top level */ + +/* 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"; + +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 |