about summary refs log tree commit diff stats
path: root/js/scripting-lang/tests/14_error_handling.txt
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/tests/14_error_handling.txt')
-rw-r--r--js/scripting-lang/tests/14_error_handling.txt65
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..ce485f7
--- /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 -> case y of
+    0 : "division by zero"
+    _ : 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 : case 0 of
+    0 : "zero"
+    _ : "other";
+
+edge_case2 : case "" of
+    "" : "empty string"
+    _ : "other";
+
+edge_case3 : case false of
+    false : "false"
+    _ : "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_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 -> case y of
+    0 : x
+    _ : 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