diff options
Diffstat (limited to 'stdlib/source/test/lux/control/concurrency/promise.lux')
-rw-r--r-- | stdlib/source/test/lux/control/concurrency/promise.lux | 111 |
1 files changed, 58 insertions, 53 deletions
diff --git a/stdlib/source/test/lux/control/concurrency/promise.lux b/stdlib/source/test/lux/control/concurrency/promise.lux index 295c26e20..952e8fb7a 100644 --- a/stdlib/source/test/lux/control/concurrency/promise.lux +++ b/stdlib/source/test/lux/control/concurrency/promise.lux @@ -1,68 +1,73 @@ (.module: [lux #* + ["_" test (#+ Test)] ["." io] [control - ["M" monad (#+ Monad do)] - pipe - [concurrency - ["&" promise ("&;." monad)]]] + [monad (#+ Monad do)] + pipe] + data/text/format [math ["r" random]]] - lux/test) + {1 + ["." / ("#@." monad)]}) -(context: "Promises" - ($_ seq - (wrap (do &.monad - [running? (&.future (io.io #1))] - (assert "Can run IO actions in separate threads." - running?))) +(def: #export test + Test + (do r.monad + [_ (wrap [])] + (<| (_.context (%name (name-of /.Promise))) + ($_ _.and + (wrap (do /.monad + [running? (/.future (io.io #1))] + (_.assert "Can run IO actions in separate threads." + running?))) - (wrap (do &.monad - [_ (&.wait 500)] - (assert "Can wait for a specified amount of time." - #1))) + (wrap (do /.monad + [_ (/.wait 500)] + (_.assert "Can wait for a specified amount of time." + #1))) - (wrap (do &.monad - [[left right] (&.and (&.future (io.io #1)) - (&.future (io.io #0)))] - (assert "Can combine promises sequentially." - (and left (not right))))) + (wrap (do /.monad + [[left right] (/.and (/.future (io.io #1)) + (/.future (io.io #0)))] + (_.assert "Can combine promises sequentially." + (and left (not right))))) - (wrap (do &.monad - [?left (&.or (&.delay 100 #1) - (&.delay 200 #0)) - ?right (&.or (&.delay 200 #1) - (&.delay 100 #0))] - (assert "Can combine promises alternatively." - (case [?left ?right] - [(#.Left #1) (#.Right #0)] - #1 + (wrap (do /.monad + [?left (/.or (/.delay 100 #1) + (/.delay 200 #0)) + ?right (/.or (/.delay 200 #1) + (/.delay 100 #0))] + (_.assert "Can combine promises alternatively." + (case [?left ?right] + [(#.Left #1) (#.Right #0)] + #1 - _ - #0)))) + _ + #0)))) - (wrap (do &.monad - [?left (&.either (&.delay 100 #1) - (&.delay 200 #0)) - ?right (&.either (&.delay 200 #1) - (&.delay 100 #0))] - (assert "Can combine promises alternatively [Part 2]." - (and ?left (not ?right))))) + (wrap (do /.monad + [?left (/.either (/.delay 100 #1) + (/.delay 200 #0)) + ?right (/.either (/.delay 200 #1) + (/.delay 100 #0))] + (_.assert "Can combine promises alternatively [Part 2]." + (and ?left (not ?right))))) - (test "Can poll a promise for its value." - (and (|> (&.poll (&;wrap #1)) - (case> (#.Some #1) #1 _ #0)) - (|> (&.poll (&.delay 200 #1)) - (case> #.None #1 _ #0)))) + (_.test "Can poll a promise for its value." + (and (|> (/.poll (/@wrap #1)) + (case> (#.Some #1) #1 _ #0)) + (|> (/.poll (/.delay 200 #1)) + (case> #.None #1 _ #0)))) - (wrap (do &.monad - [?none (&.time-out 100 (&.delay 200 #1)) - ?some (&.time-out 200 (&.delay 100 #1))] - (assert "Can establish maximum waiting times for promises to be fulfilled." - (case [?none ?some] - [#.None (#.Some #1)] - #1 + (wrap (do /.monad + [?none (/.time-out 100 (/.delay 200 #1)) + ?some (/.time-out 200 (/.delay 100 #1))] + (_.assert "Can establish maximum waiting times for promises to be fulfilled." + (case [?none ?some] + [#.None (#.Some #1)] + #1 - _ - #0)))) - )) + _ + #0)))) + )))) |