aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2016-12-18 18:40:28 -0400
committerEduardo Julian2016-12-18 18:40:28 -0400
commit0df1d8855ab54abea8c729a3575b30c8499cc7e0 (patch)
treeaaf1a71d48aa887bd4fefdcc77e6e66c4a716480 /stdlib/test
parentc3d1a9e971c2b4ca56b1b8f444e8f7aeb6063c2a (diff)
- Added tests for the monad transformers for Error, Maybe, State, List and Env.
Diffstat (limited to '')
-rw-r--r--stdlib/test/test/lux/codata/env.lux16
-rw-r--r--stdlib/test/test/lux/codata/state.lux18
-rw-r--r--stdlib/test/test/lux/data/log.lux15
-rw-r--r--stdlib/test/test/lux/data/maybe.lux11
-rw-r--r--stdlib/test/test/lux/data/struct/list.lux12
5 files changed, 69 insertions, 3 deletions
diff --git a/stdlib/test/test/lux/codata/env.lux b/stdlib/test/test/lux/codata/env.lux
index a2a90a3af..4f5a37de9 100644
--- a/stdlib/test/test/lux/codata/env.lux
+++ b/stdlib/test/test/lux/codata/env.lux
@@ -11,7 +11,8 @@
text/format
[number])
(codata function
- ["&" env]))
+ ["&" env])
+ pipe)
lux/test)
(test: "Envs"
@@ -27,3 +28,16 @@
x (wrap 10)
y (wrap 20)]
(wrap (f x y))))))))
+
+(test: "Monad transformer"
+ (let [(^open "io/") io;Monad<IO>]
+ (assert "Can add env functionality to any monad."
+ (|> (do (&;EnvT io;Monad<IO>)
+ [a (&;lift-env (io/wrap 123))
+ b (wrap 456)]
+ (wrap (i.+ a b)))
+ (&;run "")
+ io;run
+ (case> 579 true
+ _ false)))
+ ))
diff --git a/stdlib/test/test/lux/codata/state.lux b/stdlib/test/test/lux/codata/state.lux
index 4c4b808b3..79a458cc0 100644
--- a/stdlib/test/test/lux/codata/state.lux
+++ b/stdlib/test/test/lux/codata/state.lux
@@ -12,7 +12,8 @@
[number]
[product])
(codata function
- ["&" state]))
+ ["&" state])
+ pipe)
lux/test)
(test: "State"
@@ -37,3 +38,18 @@
y (wrap 20)]
(wrap (f x y))))))))
))
+
+(test: "Monad transformer"
+ (let [lift (&;lift-state io;Monad<IO>)
+ (^open "io/") io;Monad<IO>]
+ (assert "Can add state functionality to any monad."
+ (|> (: (&;State' io;IO Text Int)
+ (do (&;StateT io;Monad<IO>)
+ [a (lift (io/wrap 123))
+ b (wrap 456)]
+ (wrap (i.+ a b))))
+ (&;run' "")
+ io;run
+ (case> ["" 579] true
+ _ false)))
+ ))
diff --git a/stdlib/test/test/lux/data/log.lux b/stdlib/test/test/lux/data/log.lux
index 2075e0232..dd94b1efa 100644
--- a/stdlib/test/test/lux/data/log.lux
+++ b/stdlib/test/test/lux/data/log.lux
@@ -11,7 +11,8 @@
[text "Text/" Monoid<Text> Eq<Text>]
[number]
[product])
- (codata function))
+ (codata function)
+ pipe)
lux/test)
(test: "Logs"
@@ -34,3 +35,15 @@
(assert "Can log any value."
(Text/= "YOLO" (product;left (&;log "YOLO"))))
)))
+
+(test: "Monad transformer"
+ (let [lift (&;lift-log text;Monoid<Text> io;Monad<IO>)
+ (^open "io/") io;Monad<IO>]
+ (assert "Can add log functionality to any monad."
+ (|> (io;run (do (&;LogT text;Monoid<Text> io;Monad<IO>)
+ [a (lift (io/wrap 123))
+ b (wrap 456)]
+ (wrap (i.+ a b))))
+ (case> ["" 579] true
+ _ false)))
+ ))
diff --git a/stdlib/test/test/lux/data/maybe.lux b/stdlib/test/test/lux/data/maybe.lux
index d5f20c489..b0f2b411c 100644
--- a/stdlib/test/test/lux/data/maybe.lux
+++ b/stdlib/test/test/lux/data/maybe.lux
@@ -48,3 +48,14 @@
b (wrap "lol")]
(wrap (f a b)))))
)))
+
+(test: "Monad transformer"
+ (let [lift (&;lift-maybe io;Monad<IO>)
+ (^open "io/") io;Monad<IO>]
+ (assert "Can add maybe functionality to any monad."
+ (|> (io;run (do (&;MaybeT io;Monad<IO>)
+ [a (lift (io/wrap 123))
+ b (wrap 456)]
+ (wrap (i.+ a b))))
+ (case> (#;Some 579) true
+ _ false)))))
diff --git a/stdlib/test/test/lux/data/struct/list.lux b/stdlib/test/test/lux/data/struct/list.lux
index aa269988b..db0a14f56 100644
--- a/stdlib/test/test/lux/data/struct/list.lux
+++ b/stdlib/test/test/lux/data/struct/list.lux
@@ -212,3 +212,15 @@
(= sample
(&/map product;right enum-sample)))))
))
+
+(test: "Monad transformer"
+ (let [lift (&;lift-list io;Monad<IO>)
+ (^open "io/") io;Monad<IO>]
+ (assert "Can add list functionality to any monad."
+ (|> (io;run (do (&;ListT io;Monad<IO>)
+ [a (lift (io/wrap 123))
+ b (wrap 456)]
+ (wrap (i.+ a b))))
+ (case> (^ (list 579)) true
+ _ false)))
+ ))