aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/writer.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-02-08 18:50:57 -0400
committerEduardo Julian2019-02-08 18:50:57 -0400
commitfe9748176371e55b279b965a2f03b3e01509a3c4 (patch)
tree684c843629a2f4f8d5fa4a4a3bc1c00841d93387 /stdlib/source/test/lux/control/writer.lux
parent3ade0e1af5a2ea05c58958ad8612691d60193d0d (diff)
Ported some modules to the new test format.
Diffstat (limited to 'stdlib/source/test/lux/control/writer.lux')
-rw-r--r--stdlib/source/test/lux/control/writer.lux84
1 files changed, 47 insertions, 37 deletions
diff --git a/stdlib/source/test/lux/control/writer.lux b/stdlib/source/test/lux/control/writer.lux
index b5fb372d8..5c2c47a3e 100644
--- a/stdlib/source/test/lux/control/writer.lux
+++ b/stdlib/source/test/lux/control/writer.lux
@@ -1,45 +1,55 @@
(.module:
[lux #*
+ ["_" test (#+ Test)]
["." io]
[control
- ["M" monad (#+ Monad do)]
- pipe
- ["&" writer]]
+ [equivalence (#+ Equivalence)]
+ [monoid (#+ Monoid)]
+ [monad (#+ do)]
+ {[0 #test]
+ [/
+ [".T" functor (#+ Injection Comparison)]
+ [".T" apply]
+ [".T" monad]]}]
[data
["." product]
- ["." text ("text/." equivalence)]]]
- lux/test)
+ ["." text ("text/." equivalence)
+ format]]
+ [math
+ ["r" random]]]
+ {1
+ ["." / (#+ Writer)]})
-(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"))))
- )))
+(def: (injection monoid value)
+ (All [w] (-> (Monoid w) (Injection (Writer w))))
+ [(:: monoid identity) value])
-(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)))
- ))
+(def: comparison
+ (All [w] (Comparison (Writer w)))
+ (function (_ == [_ left] [_ right])
+ (== left right)))
+
+(def: #export test
+ Test
+ (do r.monad
+ [log (r.ascii 1)]
+ (<| (_.context (%name (name-of /.Writer)))
+ ($_ _.and
+ (_.test "Can write any value."
+ (text/= log
+ (product.left (/.write log))))
+
+ (functorT.laws (..injection text.monoid) ..comparison /.functor)
+ (applyT.laws (..injection text.monoid) ..comparison (/.apply text.monoid))
+ (monadT.laws (..injection text.monoid) ..comparison (/.monad text.monoid))
+
+ (let [lift (/.lift text.monoid io.monad)
+ (^open "io/.") io.monad]
+ (_.test "Can add writer functionality to any monad."
+ (|> (io.run (do (/.with-writer text.monoid io.monad)
+ [a (lift (io/wrap 123))
+ b (wrap 456)]
+ (wrap (n/+ a b))))
+ product.right
+ (n/= 579))))
+ ))))