diff options
Diffstat (limited to 'stdlib/source/test/lux/control/writer.lux')
-rw-r--r-- | stdlib/source/test/lux/control/writer.lux | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/control/writer.lux b/stdlib/source/test/lux/control/writer.lux new file mode 100644 index 000000000..b5fb372d8 --- /dev/null +++ b/stdlib/source/test/lux/control/writer.lux @@ -0,0 +1,45 @@ +(.module: + [lux #* + ["." io] + [control + ["M" monad (#+ Monad do)] + pipe + ["&" writer]] + [data + ["." product] + ["." text ("text/." equivalence)]]] + lux/test) + +(context: "Writer." + (let [(^open "&/.") (&.monad text.monoid) + (^open "&/.") (&.apply text.monoid)] + ($_ seq + (test "Functor respects Writer." + (i/= +11 (product.right (&/map inc ["" +10])))) + + (test "Apply respects Writer." + (and (i/= +20 (product.right (&/wrap +20))) + (i/= +30 (product.right (&/apply (&/wrap (i/+ +10)) (&/wrap +20)))))) + + (test "Monad respects Writer." + (i/= +30 (product.right (do (&.monad text.monoid) + [f (wrap i/+) + a (wrap +10) + b (wrap +20)] + (wrap (f a b)))))) + + (test "Can log any value." + (text/= "YOLO" (product.left (&.log "YOLO")))) + ))) + +(context: "Monad transformer" + (let [lift (&.lift text.monoid io.monad) + (^open "io/.") io.monad] + (test "Can add writer functionality to any monad." + (|> (io.run (do (&.WriterT text.monoid io.monad) + [a (lift (io/wrap +123)) + b (wrap +456)] + (wrap (i/+ a b)))) + (case> ["" +579] #1 + _ #0))) + )) |