diff options
Diffstat (limited to 'js/baba-yaga/scratch/baba/test_error_docs.baba')
-rw-r--r-- | js/baba-yaga/scratch/baba/test_error_docs.baba | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/js/baba-yaga/scratch/baba/test_error_docs.baba b/js/baba-yaga/scratch/baba/test_error_docs.baba new file mode 100644 index 0000000..2efef40 --- /dev/null +++ b/js/baba-yaga/scratch/baba/test_error_docs.baba @@ -0,0 +1,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!"; |