summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run.scm3
-rw-r--r--tests/test-err.scm61
-rw-r--r--tests/test.mew3
3 files changed, 64 insertions, 3 deletions
diff --git a/tests/run.scm b/tests/run.scm
index 63df004..4f50a31 100644
--- a/tests/run.scm
+++ b/tests/run.scm
@@ -1 +1,4 @@
 (load "test.mew")
+(load "test-err.scm")
+
+(test-exit)
diff --git a/tests/test-err.scm b/tests/test-err.scm
new file mode 100644
index 0000000..90ef00f
--- /dev/null
+++ b/tests/test-err.scm
@@ -0,0 +1,61 @@
+(import test
+        mew
+        err
+        (chicken condition))
+
+(test-group "basics"
+  (test #t (err? (err 42)))
+  (test #t (ok? 42))
+  (test #t (ok? #f))
+  (test #t (ok? (if #f #f)))
+  (test #t (ok? '()))
+  (test 42 (unerr (err 42)))
+  (test #t (void? (unerr 42))))
+
+(test-group "record-printer"
+  (test "#<err 42>" (format "~a" (err 42))))
+
+(test-group "ok/if"
+  (test 5 (ok/if 4 inc))
+  (test 5 (ok/if 4 inc dec))
+  (test 3 (ok/if (err 4) inc dec)))
+
+(test-group "ok=>"
+  (test 5 (ok=> 5))
+  (test 7 (ok=> 5 inc inc))
+  (test (err 5) (ok=> (err 5)))
+  (test (err 7) (ok=> 5 inc inc err inc inc)))
+
+(test-group "err=>"
+  (test 7 (err=> 7))
+  (test 7 (err=> (err 7)))
+  (test 7 (err=> 7 inc))
+  (test 9 (err=> (err 7) inc inc))
+  (test-error (err=> (err 7) err inc)))
+
+(test-group "ok"
+  (test 7 (ok 7))
+  (test-error (ok (err 7)))
+  (test #t (condition? (unerr (guard-err (ok (guard-err (/ 1 0))))))))
+
+(test-group "ok/or"
+  (test #t (err? (ok/or)))
+  (test 7 (ok/or 7))
+  (test #f (ok/or #f 7))
+  (test 7 (ok/or (err 6) 7))
+  (test 7 (ok/or (err 6) (err 8) 7))
+  (test 7 (ok/or (err 6) (err 8) 7 8))
+  (test 7 (ok/or 7 (error "not reached")))
+  (test-error (ok/or (err 7) (error "reached"))))
+
+(test-group "ok/and"
+  (test #t (ok/and))
+  (test 8 (ok/and 6 7 8))
+  (test 8 (ok/and #f 7 8))
+  (test (err 6) (ok/and (err 6) 7 8))
+  (test (err 7) (ok/and 6 (err 7) 8)))
+
+(test-group "guard-err"
+  (test #t (err? (guard-err (/ 1 0))))
+  (test 1/2 (guard-err (/ 1 2)))
+  (test-error (err? (guard-err (/ 1 0) (exn bounds)))))
diff --git a/tests/test.mew b/tests/test.mew
index 7782fb6..948837a 100644
--- a/tests/test.mew
+++ b/tests/test.mew
@@ -580,6 +580,3 @@
   (test 42 (imp #t #t #t 42))
   (test 42 (imp 39 40 41 42))
   (test #t (imp 39 #f 41 42)))
-
-
-(test-exit)