blob: 2efef40504a87cd45220db71af6aff7128a96bf3 (
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
|
// Test some examples from the error handling documentation
io.out "Testing error handling documentation examples...";
// 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 test:";
io.out (handleDivision 10 2); // Should be 5
io.out (handleDivision 10 0); // Should be 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 "Validation test:";
io.out (validateAge 25); // Should be Ok 25
io.out (validateAge 200); // Should be error
// Simple assertion
assert (2 + 2 = 4) "Math works";
io.out "Assertion passed!";
// Debug example
debug.print "Debug test" 42;
io.out "Error handling documentation examples work!";
|