From 964ec62d4fbcc1fb2336a3de355ce3554ef7eb04 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 8 Sep 2021 00:22:45 -0400 Subject: Now using eval to derive code for arbitrary types. --- stdlib/source/test/lux/type/poly.lux | 2 +- stdlib/source/test/lux/type/poly/equivalence.lux | 14 ++++++------ stdlib/source/test/lux/type/poly/functor.lux | 27 +++++++++++++++++------- stdlib/source/test/lux/type/poly/json.lux | 18 ++++++++++------ 4 files changed, 39 insertions(+), 22 deletions(-) (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/type/poly.lux b/stdlib/source/test/lux/type/poly.lux index eb4efeb9c..996a86320 100644 --- a/stdlib/source/test/lux/type/poly.lux +++ b/stdlib/source/test/lux/type/poly.lux @@ -12,7 +12,7 @@ (def: .public test Test (<| (_.covering /._) - (_.for [/.poly: /.derived: /.code]) + (_.for [/.poly: /.code]) ($_ _.and /equivalence.test /functor.test diff --git a/stdlib/source/test/lux/type/poly/equivalence.lux b/stdlib/source/test/lux/type/poly/equivalence.lux index ae73c44a7..5bfb8e39d 100644 --- a/stdlib/source/test/lux/type/poly/equivalence.lux +++ b/stdlib/source/test/lux/type/poly/equivalence.lux @@ -2,6 +2,7 @@ [library [lux {"-" [Variant Record]} ["_" test {"+" [Test]}] + ["@" target] [abstract [monad {"+" [do]}] [equivalence {"+" [Equivalence]} @@ -20,9 +21,7 @@ ["[0]" random {"+" [Random]}] [number ["n" nat] - ["i" int]]] - [type - [poly {"+" [derived:]}]]]]) + ["i" int]]]]]) (type: Variant (.Variant @@ -77,11 +76,14 @@ (random.unicode size)) gen_recursive))) -(derived: equivalence - (/.equivalence ..Record)) +(for {@.old (as_is)} + (as_is (def: equivalence + (Equivalence ..Record) + (/.equivalence ..Record)))) (def: .public test Test (<| (_.covering /._) (_.for [/.equivalence] - ($equivalence.spec ..equivalence ..random)))) + (for {@.old (_.test "PLACEHOLDER" true)} + ($equivalence.spec ..equivalence ..random))))) diff --git a/stdlib/source/test/lux/type/poly/functor.lux b/stdlib/source/test/lux/type/poly/functor.lux index e2cd1ad21..d9892b02c 100644 --- a/stdlib/source/test/lux/type/poly/functor.lux +++ b/stdlib/source/test/lux/type/poly/functor.lux @@ -1,9 +1,10 @@ (.module: [library [lux "*" + ["@" target] [abstract [monad {"+" [do]}] - [functor + [functor {"+" [Functor]} [\\poly ["[0]" /]]]] ["r" math/random {"+" [Random]}] @@ -11,14 +12,24 @@ [control ["[0]" state]] [data - ["[0]" identity]] - [type - [poly {"+" [derived:]}]]]]) + ["[0]" identity]]]]) -(derived: maybe_functor (/.functor .Maybe)) -(derived: list_functor (/.functor .List)) -(derived: state_functor (/.functor state.State)) -(derived: identity_functor (/.functor identity.Identity)) +(for {@.old (as_is)} + (as_is (def: maybe_functor + (Functor .Maybe) + (/.functor .Maybe)) + + (def: list_functor + (Functor .List) + (/.functor .List)) + + (def: state_functor + (All (_ s) (Functor (state.State s))) + (/.functor state.State)) + + (def: identity_functor + (Functor identity.Identity) + (/.functor identity.Identity)))) (def: .public test Test diff --git a/stdlib/source/test/lux/type/poly/json.lux b/stdlib/source/test/lux/type/poly/json.lux index 6abaa47f1..259a25b95 100644 --- a/stdlib/source/test/lux/type/poly/json.lux +++ b/stdlib/source/test/lux/type/poly/json.lux @@ -2,6 +2,7 @@ [library [lux {"-" [Variant Record]} ["_" test {"+" [Test]}] + ["@" target] ["[0]" debug] [abstract codec @@ -21,7 +22,7 @@ ["[0]" bit] ["[0]" text] [format - [json {"+" []} + [json {"+" [JSON]} [\\poly ["[0]" /]]]] [collection @@ -29,7 +30,6 @@ ["d" dictionary] ["[0]" list]]] [type - [poly {"+" [derived:]}] ["[0]" unit]] [math ["[0]" random {"+" [Random]}] @@ -108,14 +108,18 @@ ..qty ))) -(derived: equivalence - (poly/equivalence.equivalence Record)) +(for {@.old (as_is)} + (as_is (def: equivalence + (Equivalence Record) + (poly/equivalence.equivalence Record)) -(derived: codec - (/.codec Record)) + (def: codec + (Codec JSON Record) + (/.codec Record)))) (def: .public test Test (<| (_.covering /._) (_.for [/.codec] - ($codec.spec ..equivalence ..codec ..gen_record)))) + (for {@.old (_.test "PLACEHOLDER" true)} + ($codec.spec ..equivalence ..codec ..gen_record))))) -- cgit v1.2.3