blob: d886e09407513de8958530c010f9c035dc66490a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Test error handling patterns from the documentation
io.out "=== Testing Error Handling Patterns ===";
// Basic Result usage
divide : x y ->
when y is
0 then Err "Division by zero"
_ then Ok (x / y);
handleDivision : x y ->
when (divide x y) is
Ok result then result
Err message then 0;
io.out "Division results:";
io.out (handleDivision 10 2); // Should be 5
io.out (handleDivision 10 0); // Should print error and return 0
// Validation patterns
validateAge : age ->
when (validate.type "Int" age) is
false then Err "Age must be an integer"
true then
when (validate.range 0 150 age) is
false then Err "Age must be between 0 and 150"
true then Ok age;
io.out "";
io.out "Validation results:";
io.out (validateAge 25); // Should be Ok 25
io.out (validateAge 200); // Should be Err message
io.out (validateAge "not a number"); // Should be Err message
// Simple assertion example
io.out "";
io.out "Assertion example:";
assert (2 + 2 = 4) "Math works";
io.out "Assertion passed!";
// Debug example
io.out "";
io.out "Debug example:";
debug.print "Testing debug output" 42;
io.out "";
io.out "Error handling tests completed!";
|