aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2018-01-16 22:33:38 -0400
committerEduardo Julian2018-01-16 22:33:38 -0400
commit002ee0418195afccd1a1b500a36cc5b2adc44791 (patch)
treec144a4a1732195fcb42072937796bb153cca5d2a /stdlib/test
parent198834d3c3ff0cc70b0521a7341ae66040db2641 (diff)
- Added sub-structural types (for synchronous IO and asynchronous Promise).
Diffstat (limited to 'stdlib/test')
-rw-r--r--stdlib/test/test/lux/type/resource.lux46
1 files changed, 46 insertions, 0 deletions
diff --git a/stdlib/test/test/lux/type/resource.lux b/stdlib/test/test/lux/type/resource.lux
new file mode 100644
index 000000000..3681a7ce1
--- /dev/null
+++ b/stdlib/test/test/lux/type/resource.lux
@@ -0,0 +1,46 @@
+(.module:
+ lux
+ (lux (control (monad [indexed #+ do]))
+ [macro]
+ (type [resource #+ Res])
+ [io])
+ lux/test)
+
+(context: "Sub-structural typing."
+ ($_ seq
+ (test "Can produce and consume keys in an ordered manner."
+ (<| (n/= (n/+ +123 +456))
+ io.run
+ resource.sync
+ (do resource.IxMonad<Sync>
+ [res|left (resource.ordered +123)
+ res|right (resource.ordered +456)
+ right (resource.read res|right)
+ left (resource.read res|left)]
+ (wrap (n/+ left right)))))
+
+ (test "Can exchange commutative keys."
+ (<| (n/= (n/+ +123 +456))
+ io.run
+ resource.sync
+ (do resource.IxMonad<Sync>
+ [res|left (resource.commutative +123)
+ res|right (resource.commutative +456)
+ _ (resource.exchange [+1 +0])
+ left (resource.read res|left)
+ right (resource.read res|right)]
+ (wrap (n/+ left right)))))
+
+ (test "Can group and un-group keys."
+ (<| (n/= (n/+ +123 +456))
+ io.run
+ resource.sync
+ (do resource.IxMonad<Sync>
+ [res|left (resource.commutative +123)
+ res|right (resource.commutative +456)
+ _ (resource.group +2)
+ _ (resource.un-group +2)
+ right (resource.read res|right)
+ left (resource.read res|left)]
+ (wrap (n/+ left right)))))
+ ))