blob: fde485472fb8e55dc1709135d8be7d4bccfee72e (
plain)
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
|
(.module:
[lux #*
[abstract/monad (#+ do)]
[data
[number
["n" nat]]
[text
["%" format (#+ format)]]]
[math
["r" random]]
["_" test (#+ Test)]]
{1
["." / (#+ exception:)]})
(exception: an-exception)
(exception: another-exception)
(def: #export test
(do r.monad
[right r.nat
wrong (r.filter (|>> (n.= right) not) r.nat)]
(<| (_.context (%.name (name-of /.Exception)))
($_ _.and
(_.test "Can catch exceptions."
(n.= right
(|> (/.throw an-exception [])
(/.catch an-exception (function (_ ex) right))
(/.otherwise (function (_ ex) wrong)))))
(_.test "Can catch multiple exceptions."
(n.= right
(|> (/.throw another-exception [])
(/.catch an-exception (function (_ ex) wrong))
(/.catch another-exception (function (_ ex) right))
(/.otherwise (function (_ ex) wrong)))))
(_.test "Can handle uncaught exceptions."
(n.= right
(|> (/.throw another-exception [])
(/.catch an-exception (function (_ ex) wrong))
(/.otherwise (function (_ ex) right)))))))))
|