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