aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/test/test.lux9
-rw-r--r--stdlib/test/test/lux.lux5
-rw-r--r--stdlib/test/test/lux/control.lux11
-rw-r--r--stdlib/test/test/lux/control/exception.lux71
4 files changed, 47 insertions, 49 deletions
diff --git a/stdlib/test/test.lux b/stdlib/test/test.lux
index a28c38ce5..0985211f2 100644
--- a/stdlib/test/test.lux
+++ b/stdlib/test/test.lux
@@ -83,12 +83,7 @@
## TODO: Must have 100% coverage on tests.
[/
["/." lux
- ## [time
- ## [instant (#+)]
- ## [duration (#+)]
- ## [date (#+)]]
## [control
- ## ## [exception (#+)]
## ## [interval (#+)]
## ## [pipe (#+)]
## ## [continuation (#+)]
@@ -164,6 +159,10 @@
## ## [implicit (#+)] ## TODO: FIX Specially troublesome...
## ## [resource (#+)]
## [dynamic (#+)]]
+ ## [time
+ ## [instant (#+)]
+ ## [duration (#+)]
+ ## [date (#+)]]
## [compiler
## [default
## ["_default/." syntax]
diff --git a/stdlib/test/test/lux.lux b/stdlib/test/test/lux.lux
index 665a11e89..f47d9302f 100644
--- a/stdlib/test/test/lux.lux
+++ b/stdlib/test/test/lux.lux
@@ -14,7 +14,8 @@
["/." cli]
["/." io]
["/." host
- ["/." jvm]]])
+ ["/." jvm]]
+ ["/." control]])
(def: identity
Test
@@ -242,4 +243,6 @@
/host.test
(<| (_.context "/jvm JVM (Java Virtual Machine)")
/jvm.test)))
+ (<| (_.context "/control")
+ /control.test)
))
diff --git a/stdlib/test/test/lux/control.lux b/stdlib/test/test/lux/control.lux
new file mode 100644
index 000000000..f50bdf7a7
--- /dev/null
+++ b/stdlib/test/test/lux/control.lux
@@ -0,0 +1,11 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]]
+ [/
+ ["/." exception]])
+
+(def: #export test
+ Test
+ ($_ _.and
+ (<| (_.context "/exception Exception-handling.")
+ /exception.test)))
diff --git a/stdlib/test/test/lux/control/exception.lux b/stdlib/test/test/lux/control/exception.lux
index aa6c8bf09..434ffc5d0 100644
--- a/stdlib/test/test/lux/control/exception.lux
+++ b/stdlib/test/test/lux/control/exception.lux
@@ -1,50 +1,35 @@
(.module:
[lux #*
[control
- ["M" monad (#+ do Monad)]
- ["&" exception (#+ exception:)]]
- [data
- ["." error (#+ Error)]
- ["." text
- format]]
+ [monad (#+ do)]]
[math
- ["r" random]]]
- lux/test)
+ ["r" random]]
+ ["_" test (#+ Test)]]
+ {1
+ ["." / (#+ exception:)]})
-(exception: some-exception)
+(exception: (an-exception))
-(exception: another-exception)
+(exception: (another-exception))
-(exception: unknown-exception)
-
-(context: "Exceptions"
- (<| (times 100)
- (do @
- [should-throw? r.bit
- which? r.bit
- should-catch? r.bit
- default-val r.nat
- some-val r.nat
- another-val r.nat
- otherwise-val r.nat
- #let [this-ex (if should-catch?
- (if which?
- some-exception
- another-exception)
- unknown-exception)
- expected (if should-throw?
- (if should-catch?
- (if which?
- some-val
- another-val)
- otherwise-val)
- default-val)
- actual (|> (: (Error Nat)
- (if should-throw?
- (&.throw this-ex [])
- (&.return default-val)))
- (&.catch some-exception (function (_ ex) some-val))
- (&.catch another-exception (function (_ ex) another-val))
- (&.otherwise (function (_ ex) otherwise-val)))]]
- (test "Catch and otherwhise handlers can properly handle the flow of exception-handling."
- (n/= expected actual)))))
+(def: #export test
+ (do r.monad
+ [right r.nat
+ wrong (r.filter (|>> (n/= right) not) r.nat)]
+ ($_ _.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))))))))