summary refs log tree commit diff
path: root/tests/test-err.scm
blob: 90ef00fc419f1315845467102df102be32a6782f (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
48
49
50
51
52
53
54
55
56
57
58
59
60
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)))))