aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/type/resource.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-06-30 22:53:23 -0400
committerEduardo Julian2022-06-30 22:53:23 -0400
commita8d76e48df01d0f5326faa8456797f91cb2cbeba (patch)
tree7a7a3d1e934a694e1cc4e3246dc21c2fe3093cf3 /stdlib/source/test/lux/meta/type/resource.lux
parent565fe5a2e60ff3c6b612031d1c3bb89f330751da (diff)
Alternative names for (un)quoting macros.
Diffstat (limited to 'stdlib/source/test/lux/meta/type/resource.lux')
-rw-r--r--stdlib/source/test/lux/meta/type/resource.lux191
1 files changed, 191 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/meta/type/resource.lux b/stdlib/source/test/lux/meta/type/resource.lux
new file mode 100644
index 000000000..a23f1cacf
--- /dev/null
+++ b/stdlib/source/test/lux/meta/type/resource.lux
@@ -0,0 +1,191 @@
+(.require
+ [library
+ [lux (.except)
+ ["_" test (.only Test)]
+ ["[0]" meta]
+ [abstract
+ ["[0]" monad (.only)
+ [indexed (.only do)]]]
+ [control
+ ["[0]" io (.only IO)]
+ ["[0]" try]
+ ["[0]" exception (.only Exception)]
+ [concurrency
+ ["[0]" async (.only Async)]]]
+ [data
+ ["[0]" identity (.only Identity)]
+ ["[0]" text (.use "[1]#[0]" equivalence)
+ ["%" \\format (.only format)]]]
+ ["[0]" macro (.only)
+ [syntax (.only syntax)]
+ ["[0]" code (.only)
+ ["<[1]>" \\parser]]]
+ [math
+ ["[0]" random]]]]
+ [\\library
+ ["[0]" / (.only Res)]])
+
+(def pure
+ Test
+ (monad.do [! random.monad]
+ [pre (at ! each %.nat random.nat)
+ post (at ! each %.nat random.nat)
+ .let [! identity.monad]]
+ (_.for [/.Linear /.run! /.monad]
+ (`` (all _.and
+ (~~ (with_template [<coverage> <bindings>]
+ [(_.coverage <coverage>
+ (<| (text#= (format pre post))
+ (is (Identity Text))
+ (/.run! !)
+ (do (/.monad !)
+ <bindings>
+ (in (format left right)))))]
+
+ [[/.Affine /.Key /.Res /.Ordered /.ordered
+ /.Relevant /.read]
+ [res|left (/.ordered ! pre)
+ res|right (/.ordered ! post)
+ right (/.read ! res|right)
+ left (/.read ! res|left)]]
+ [[/.Commutative /.commutative /.exchange]
+ [res|left (/.commutative ! pre)
+ res|right (/.commutative ! post)
+ _ ((/.exchange [1 0]) !)
+ left (/.read ! res|left)
+ right (/.read ! res|right)]]
+ [[/.group /.un_group]
+ [res|left (/.commutative ! pre)
+ res|right (/.commutative ! post)
+ _ ((/.group 2) !)
+ _ ((/.un_group 2) !)
+ right (/.read ! res|right)
+ left (/.read ! res|left)]]
+ [[/.lifted]
+ [left (/.lifted ! pre)
+ right (/.lifted ! post)]]
+ ))
+ )))))
+
+(def sync
+ Test
+ (monad.do [! random.monad]
+ [pre (at ! each %.nat random.nat)
+ post (at ! each %.nat random.nat)
+ .let [! io.monad]]
+ (_.for [/.Linear /.run! /.monad]
+ (`` (all _.and
+ (~~ (with_template [<coverage> <bindings>]
+ [(_.coverage <coverage>
+ (<| (text#= (format pre post))
+ io.run!
+ (is (IO Text))
+ (/.run! !)
+ (do (/.monad !)
+ <bindings>
+ (in (format left right)))))]
+
+ [[/.Affine /.Key /.Res /.Ordered /.ordered
+ /.Relevant /.read]
+ [res|left (/.ordered ! pre)
+ res|right (/.ordered ! post)
+ right (/.read ! res|right)
+ left (/.read ! res|left)]]
+ [[/.Commutative /.commutative /.exchange]
+ [res|left (/.commutative ! pre)
+ res|right (/.commutative ! post)
+ _ ((/.exchange [1 0]) !)
+ left (/.read ! res|left)
+ right (/.read ! res|right)]]
+ [[/.group /.un_group]
+ [res|left (/.commutative ! pre)
+ res|right (/.commutative ! post)
+ _ ((/.group 2) !)
+ _ ((/.un_group 2) !)
+ right (/.read ! res|right)
+ left (/.read ! res|left)]]
+ [[/.lifted]
+ [left (/.lifted ! (io.io pre))
+ right (/.lifted ! (io.io post))]]
+ ))
+ )))))
+
+(def async
+ Test
+ (monad.do [! random.monad]
+ [pre (at ! each %.nat random.nat)
+ post (at ! each %.nat random.nat)
+ .let [! async.monad]]
+ (_.for [/.Linear /.run! /.monad]
+ (`` (all _.and
+ (~~ (with_template [<coverage> <bindings>]
+ [(in (monad.do !
+ [outcome (<| (is (Async Text))
+ (/.run! !)
+ (do (/.monad !)
+ <bindings>
+ (in (format left right))))]
+ (_.coverage' <coverage>
+ (text#= (format pre post)
+ outcome))))]
+
+ [[/.Affine /.Key /.Res /.Ordered /.ordered
+ /.Relevant /.read]
+ [res|left (/.ordered ! pre)
+ res|right (/.ordered ! post)
+ right (/.read ! res|right)
+ left (/.read ! res|left)]]
+ [[/.Commutative /.commutative /.exchange]
+ [res|left (/.commutative ! pre)
+ res|right (/.commutative ! post)
+ _ ((/.exchange [1 0]) !)
+ left (/.read ! res|left)
+ right (/.read ! res|right)]]
+ [[/.group /.un_group]
+ [res|left (/.commutative ! pre)
+ res|right (/.commutative ! post)
+ _ ((/.group 2) !)
+ _ ((/.un_group 2) !)
+ right (/.read ! res|right)
+ left (/.read ! res|left)]]
+ [[/.lifted]
+ [left (/.lifted ! (async.resolved pre))
+ right (/.lifted ! (async.resolved post))]]
+ ))
+ )))))
+
+(def with_error
+ (syntax (_ [exception <code>.symbol
+ to_expand <code>.any])
+ (monad.do meta.monad
+ [[_ _ exception] (meta.export exception)]
+ (function (_ compiler)
+ {.#Right [compiler
+ (list (code.bit (case ((macro.single_expansion to_expand) compiler)
+ {try.#Success _}
+ false
+
+ {try.#Failure error}
+ true)))]}))))
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Procedure])
+ (all _.and
+ ..pure
+ ..sync
+ ..async
+
+ (_.coverage [/.amount_cannot_be_zero]
+ (`` (and (~~ (with_template [<group|un_group>]
+ [(with_error /.amount_cannot_be_zero
+ (<group|un_group> 0))]
+
+ [/.group]
+ [/.un_group]
+ )))))
+ (_.coverage [/.index_cannot_be_repeated]
+ (with_error /.index_cannot_be_repeated
+ (/.exchange [0 0])))
+ )))