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