diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/spec/lux/world/console.lux | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/stdlib/source/spec/lux/world/console.lux b/stdlib/source/spec/lux/world/console.lux new file mode 100644 index 000000000..b9e1c0720 --- /dev/null +++ b/stdlib/source/spec/lux/world/console.lux @@ -0,0 +1,49 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)]] + [control + ["." try] + [security + ["!" capability]] + [concurrency + ["." promise (#+ Promise)]]] + [math + ["." random]]] + {1 + ["." /]}) + +(def: #export (spec console) + (-> (/.Console Promise) Test) + (<| (_.with-cover [/.Console]) + (do {! random.monad} + [message (random.ascii/alpha 10)] + (wrap (do promise.monad + [?read (!.use (:: console read) []) + ?read-line (!.use (:: console read-line) []) + ?write (!.use (:: console write) [message]) + ?close/good (!.use (:: console close) []) + ?close/bad (!.use (:: console close) [])] + ($_ _.and' + (_.claim [/.Can-Read] + (case [?read ?read-line] + [(#try.Success _) (#try.Success _)] + true + + _ + false)) + (_.claim [/.Can-Write] + (case ?write + (#try.Success _) + true + + _ + false)) + (_.claim [/.Can-Close] + (case [?close/good ?close/bad] + [(#try.Success _) (#try.Failure _)] + true + + _ + false)))))))) |