diff options
Diffstat (limited to 'js/scripting-lang/scratch_tests/test_embedded_functions_comprehensive.txt')
-rw-r--r-- | js/scripting-lang/scratch_tests/test_embedded_functions_comprehensive.txt | 162 |
1 files changed, 162 insertions, 0 deletions
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 |