From a60af2d673ef6b3c7090e454a1edc59838f3540d Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 17 Dec 2016 15:28:36 -0400 Subject: - Added tests for lux/macro/poly/* --- stdlib/test/test/lux/macro/poly/eq.lux | 66 ++++++++++++++++++++++++ stdlib/test/test/lux/macro/poly/functor.lux | 44 ++++++++++++++++ stdlib/test/test/lux/macro/poly/text-encoder.lux | 63 ++++++++++++++++++++++ stdlib/test/tests.lux | 13 ++--- 4 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 stdlib/test/test/lux/macro/poly/eq.lux create mode 100644 stdlib/test/test/lux/macro/poly/functor.lux create mode 100644 stdlib/test/test/lux/macro/poly/text-encoder.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/macro/poly/eq.lux b/stdlib/test/test/lux/macro/poly/eq.lux new file mode 100644 index 000000000..983d2da69 --- /dev/null +++ b/stdlib/test/test/lux/macro/poly/eq.lux @@ -0,0 +1,66 @@ +## 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 + eq) + (data text/format + [bool] + [number "i/" Number] + [char] + [text]) + (math ["R" random]) + pipe + [macro] + (macro [poly #+ derived:] + ["&" poly/eq])) + lux/test) + +## [Utils] +(type: Variant + (#Case0 Bool) + (#Case1 Int) + (#Case2 Real)) + +(type: Record + {#unit Unit + #bool Bool + #int Int + #real Real + #char Char + #text Text + #maybe (Maybe Int) + #list (List Int) + #variant Variant + #tuple [Int Real Char]}) + +(def: gen-record + (R;Random Record) + (do R;Monad + [size (:: @ map (n.% +2) R;nat) + #let [gen-int (|> R;int (:: @ map (|>. i/abs (i.% 1_000_000))))]] + ($_ R;seq + (:: @ wrap []) + R;bool + gen-int + R;real + R;char + (R;text size) + (R;maybe gen-int) + (R;list size gen-int) + ($_ R;alt R;bool gen-int R;real) + ($_ R;seq gen-int R;real R;char) + ))) + +(derived: (&;Eq Record)) + +## [Tests] +(test: "Eq polytypism" + [sample gen-record + #let [(^open "&/") Eq]] + (assert "Every instance equals itself." + (&/= sample sample))) diff --git a/stdlib/test/test/lux/macro/poly/functor.lux b/stdlib/test/test/lux/macro/poly/functor.lux new file mode 100644 index 000000000..c25f536e9 --- /dev/null +++ b/stdlib/test/test/lux/macro/poly/functor.lux @@ -0,0 +1,44 @@ +## 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 + [functor] + eq) + (data text/format + [bool] + [number "i/" Number] + [char] + [text]) + (math ["R" random]) + pipe + [macro] + (macro [poly #+ derived:] + ["&" poly/functor])) + lux/test) + +## [Utils] +(type: (My-Maybe a) + #My-None + (#My-Some a)) + +(type: (My-List a) + #My-Nil + (#My-Cons [a (My-List a)])) + +(type: (My-State s a) + (-> s [s a])) + +(derived: (&;Functor My-Maybe)) + +(derived: (&;Functor My-List)) + +(derived: (&;Functor My-State)) + +## [Tests] +(test: "Functor polytypism" + (assert "" true)) diff --git a/stdlib/test/test/lux/macro/poly/text-encoder.lux b/stdlib/test/test/lux/macro/poly/text-encoder.lux new file mode 100644 index 000000000..e106162a3 --- /dev/null +++ b/stdlib/test/test/lux/macro/poly/text-encoder.lux @@ -0,0 +1,63 @@ +## 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 + eq) + (data text/format + [bool] + [number "i/" Number] + [char] + [text]) + (math ["R" random]) + pipe + [macro] + (macro [poly #+ derived:] + ["&" poly/text-encoder])) + lux/test) + +## [Utils] +(type: Variant + (#Case0 Bool) + (#Case1 Int) + (#Case2 Real)) + +(type: Record + {#unit Unit + #bool Bool + #int Int + #real Real + #char Char + #text Text + #maybe (Maybe Int) + #list (List Int) + #variant Variant + #tuple [Int Real Char]}) + +(def: gen-record + (R;Random Record) + (do R;Monad + [size (:: @ map (n.% +2) R;nat) + #let [gen-int (|> R;int (:: @ map (|>. i/abs (i.% 1_000_000))))]] + ($_ R;seq + (:: @ wrap []) + R;bool + gen-int + R;real + R;char + (R;text size) + (R;maybe gen-int) + (R;list size gen-int) + ($_ R;alt R;bool gen-int R;real) + ($_ R;seq gen-int R;real R;char) + ))) + +(derived: (&;Codec::encode Record)) + +## [Tests] +(test: "Text-encoding polytypism" + (assert "" true)) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 85cce3d9f..ebb6c6999 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -26,7 +26,6 @@ [frp] ["_;" promise] [stm]) - (data [bit] [bool] [char] @@ -60,18 +59,16 @@ ## [macro] (macro ["_;" ast] ["_;" syntax] - ["_;" template]) + ["_;" template] + (poly ["poly_;" eq] + ["poly_;" text-encoder] + ["poly_;" functor])) ["_;" type] (type ["_;" check] ["_;" auto]) ## (control [effect]) ) - ) - ## (lux (macro [poly] - ## (poly ["poly_;" eq] - ## ["poly_;" text-encoder] - ## ["poly_;" functor]))) - ) + )) ## [Program] (program: args -- cgit v1.2.3