aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2016-12-15 01:54:08 -0400
committerEduardo Julian2016-12-15 01:54:08 -0400
commit2feeb0f34d68326722f0f3a06199d1e75256a2cc (patch)
tree3ca09ead5f5e3b313bbf506b5643f0c7ec6c8829 /stdlib
parent35832f8e115e087a949cc5c7b0832cdef43f2d41 (diff)
- Added tests for lux/codata/cont.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/test/test/lux/codata/cont.lux45
-rw-r--r--stdlib/test/tests.lux11
2 files changed, 51 insertions, 5 deletions
diff --git a/stdlib/test/test/lux/codata/cont.lux b/stdlib/test/test/lux/codata/cont.lux
new file mode 100644
index 000000000..7e2daa823
--- /dev/null
+++ b/stdlib/test/test/lux/codata/cont.lux
@@ -0,0 +1,45 @@
+## Copyright (c) Eduardo Julian. All rights reserved.
+## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+## If a copy of the MPL was not distributed with this file,
+## You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(;module:
+ lux
+ (lux (codata [io])
+ (control monad)
+ (data [text "Text/" Monoid<Text>]
+ text/format
+ [number]
+ [product])
+ (codata function
+ ["&" cont])
+ (math ["R" random])
+ pipe)
+ lux/test)
+
+(test: "Continuations"
+ [sample R;nat
+ #let [(^open "&/") &;Monad<Cont>]]
+ ($_ seq
+ (assert "Can run continuations to compute their values."
+ (n.= sample (&;run (&;@lazy sample))))
+
+ (assert "Can use functor."
+ (n.= (n.inc sample) (&;run (&/map n.inc (&;@lazy sample)))))
+
+ (assert "Can use applicative."
+ (n.= (n.inc sample) (&;run (&/apply (&/wrap n.inc) (&/wrap sample)))))
+
+ (assert "Can use monad."
+ (n.= (n.inc sample) (&;run (do &;Monad<Cont>
+ [func (wrap n.inc)
+ arg (wrap sample)]
+ (wrap (func arg))))))
+
+ (assert "Can access current continuation."
+ (n.= (n.dec sample) (&;run (do &;Monad<Cont>
+ [func (wrap n.inc)
+ _ (&;call/cc (lambda [k] (k (n.dec sample))))
+ arg (wrap sample)]
+ (wrap (func arg))))))
+ ))
diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux
index ef94dca90..85cce3d9f 100644
--- a/stdlib/test/tests.lux
+++ b/stdlib/test/tests.lux
@@ -17,14 +17,16 @@
["_;" lexer]
["_;" regex]
(codata ["_;" io]
- [env]
- [state]
- (struct [stream]))
+ ["_;" env]
+ ["_;" state]
+ ["_;" cont]
+ (struct ["_;" stream]))
(concurrency [actor]
["_;" atom]
[frp]
["_;" promise]
[stm])
+
(data [bit]
[bool]
[char]
@@ -65,8 +67,7 @@
## (control [effect])
)
)
- ## (lux (codata [cont])
- ## (macro [poly]
+ ## (lux (macro [poly]
## (poly ["poly_;" eq]
## ["poly_;" text-encoder]
## ["poly_;" functor])))