aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2022-08-25 21:31:54 -0400
committerEduardo Julian2022-08-25 21:31:54 -0400
commit3f010de748ffccf304c4be09863f77d4020d610d (patch)
tree0254c5f2909b3e5f76bf14faf86a03a1ecf05f81 /stdlib/source/test
parent156fac89df89669ee660bd075f516dd8d57abd19 (diff)
Added support for type-based polymorphism.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/control/function.lux5
-rw-r--r--stdlib/source/test/lux/control/function/polymorphism/type.lux41
-rw-r--r--stdlib/source/test/lux/meta/type.lux4
-rw-r--r--stdlib/source/test/lux/meta/type/poly.lux48
4 files changed, 96 insertions, 2 deletions
diff --git a/stdlib/source/test/lux/control/function.lux b/stdlib/source/test/lux/control/function.lux
index aad5f2ebf..d87f6f3cd 100644
--- a/stdlib/source/test/lux/control/function.lux
+++ b/stdlib/source/test/lux/control/function.lux
@@ -23,7 +23,9 @@
["[1][0]" predicate]
["[1][0]" variadic]
["[1][0]" named]
- ["[1][0]" trampoline]])
+ ["[1][0]" trampoline]
+ ["[1][0]" polymorphism
+ ["[1]/[0]" type]]])
(def .public test
Test
@@ -73,4 +75,5 @@
/variadic.test
/named.test
/trampoline.test
+ /polymorphism/type.test
))))
diff --git a/stdlib/source/test/lux/control/function/polymorphism/type.lux b/stdlib/source/test/lux/control/function/polymorphism/type.lux
new file mode 100644
index 000000000..a5ed74cca
--- /dev/null
+++ b/stdlib/source/test/lux/control/function/polymorphism/type.lux
@@ -0,0 +1,41 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [data
+ ["[0]" text (.use "[1]#[0]" equivalence)
+ ["%" \\format]]]
+ [math
+ ["[0]" random]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(/.def .public format
+ [a]
+ (-> a Text)
+
+ (/.method format
+ [Bit]
+ %.bit)
+
+ (/.method (format it)
+ [Nat]
+ (%.nat it))
+ )
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [bit random.bit
+ nat random.nat])
+ (all _.and
+ (_.coverage [/.def /.method]
+ (and (text#= (%.bit bit)
+ (format bit))
+ (text#= (%.nat nat)
+ (format nat))))
+ )))
diff --git a/stdlib/source/test/lux/meta/type.lux b/stdlib/source/test/lux/meta/type.lux
index 3c6872d26..67119dd60 100644
--- a/stdlib/source/test/lux/meta/type.lux
+++ b/stdlib/source/test/lux/meta/type.lux
@@ -41,7 +41,8 @@
["[1][0]" refinement]
["[1][0]" resource]
["[1][0]" unit]
- ["[1][0]" variance]])
+ ["[1][0]" variance]
+ ["[1][0]" poly]])
(def !expect
(template (_ <pattern> <value>)
@@ -570,4 +571,5 @@
/resource.test
/unit.test
/variance.test
+ /poly.test
)))
diff --git a/stdlib/source/test/lux/meta/type/poly.lux b/stdlib/source/test/lux/meta/type/poly.lux
new file mode 100644
index 000000000..e2aa7d03e
--- /dev/null
+++ b/stdlib/source/test/lux/meta/type/poly.lux
@@ -0,0 +1,48 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["?" parser]]
+ [data
+ ["[0]" bit (.use "[1]#[0]" equivalence)]]
+ [math
+ ["[0]" random]
+ [number
+ ["[0]" nat (.use "[1]#[0]" equivalence)]]]
+ [meta
+ ["[0]" static]
+ ["[0]" type
+ ["?[1]" \\parser]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(with_expansions [<bit> (static.random_bit)
+ <nat> (static.random_nat)]
+ (def constant
+ (/.polytypic constant
+ (`` (all ?.either
+ (,, (with_template [<type> <constant>]
+ [(do ?.monad
+ [_ (?type.sub <type>)]
+ (in (` (is <type>
+ <constant>))))]
+
+ [Bit <bit>]
+ [Nat <nat>]))
+ ))))
+
+ (def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [])
+ (all _.and
+ (_.coverage [/.polytypic]
+ (and (bit#= <bit> (constant Bit))
+ (nat#= <nat> (constant Nat))))
+ )))
+ )