From 75102dcfa7c2c0afd32cb5bf5ac012df2db6a7a1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 5 Jan 2021 07:55:22 -0400 Subject: Added lexically-scoped templates. --- stdlib/source/test/aedifex/artifact.lux | 4 +- .../test/aedifex/artifact/time_stamp/time.lux | 31 +++++++ stdlib/source/test/lux/macro.lux | 4 +- stdlib/source/test/lux/macro/poly/json.lux | 4 +- .../source/test/lux/macro/syntax/annotations.lux | 53 ++++++++++++ stdlib/source/test/lux/macro/syntax/check.lux | 48 +++++++++++ stdlib/source/test/lux/macro/syntax/common.lux | 71 ---------------- .../test/lux/macro/syntax/common/annotations.lux | 53 ------------ .../source/test/lux/macro/syntax/common/check.lux | 48 ----------- .../test/lux/macro/syntax/common/declaration.lux | 47 ----------- .../test/lux/macro/syntax/common/definition.lux | 97 ---------------------- .../source/test/lux/macro/syntax/common/export.lux | 29 ------- .../test/lux/macro/syntax/common/type/variable.lux | 37 --------- .../source/test/lux/macro/syntax/declaration.lux | 47 +++++++++++ stdlib/source/test/lux/macro/syntax/definition.lux | 97 ++++++++++++++++++++++ stdlib/source/test/lux/macro/syntax/export.lux | 29 +++++++ stdlib/source/test/lux/macro/syntax/input.lux | 46 ++++++++++ .../source/test/lux/macro/syntax/type/variable.lux | 37 +++++++++ stdlib/source/test/lux/macro/template.lux | 38 +++++++++ stdlib/source/test/lux/time/date.lux | 94 ++++++++++++++++----- 20 files changed, 507 insertions(+), 407 deletions(-) create mode 100644 stdlib/source/test/aedifex/artifact/time_stamp/time.lux create mode 100644 stdlib/source/test/lux/macro/syntax/annotations.lux create mode 100644 stdlib/source/test/lux/macro/syntax/check.lux delete mode 100644 stdlib/source/test/lux/macro/syntax/common.lux delete mode 100644 stdlib/source/test/lux/macro/syntax/common/annotations.lux delete mode 100644 stdlib/source/test/lux/macro/syntax/common/check.lux delete mode 100644 stdlib/source/test/lux/macro/syntax/common/declaration.lux delete mode 100644 stdlib/source/test/lux/macro/syntax/common/definition.lux delete mode 100644 stdlib/source/test/lux/macro/syntax/common/export.lux delete mode 100644 stdlib/source/test/lux/macro/syntax/common/type/variable.lux create mode 100644 stdlib/source/test/lux/macro/syntax/declaration.lux create mode 100644 stdlib/source/test/lux/macro/syntax/definition.lux create mode 100644 stdlib/source/test/lux/macro/syntax/export.lux create mode 100644 stdlib/source/test/lux/macro/syntax/input.lux create mode 100644 stdlib/source/test/lux/macro/syntax/type/variable.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/aedifex/artifact.lux b/stdlib/source/test/aedifex/artifact.lux index 959b857dd..60619f78b 100644 --- a/stdlib/source/test/aedifex/artifact.lux +++ b/stdlib/source/test/aedifex/artifact.lux @@ -22,7 +22,8 @@ ["#." type] ["#." extension] ["#." time_stamp #_ - ["#/." date]]] + ["#/." date] + ["#/." time]]] {#program ["." /]}) @@ -45,4 +46,5 @@ /type.test /extension.test /time_stamp/date.test + /time_stamp/time.test )))) diff --git a/stdlib/source/test/aedifex/artifact/time_stamp/time.lux b/stdlib/source/test/aedifex/artifact/time_stamp/time.lux new file mode 100644 index 000000000..bd9bbe071 --- /dev/null +++ b/stdlib/source/test/aedifex/artifact/time_stamp/time.lux @@ -0,0 +1,31 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + ["." time (#+ Time)] + [abstract + [monad (#+ do)]] + [control + ["." try ("#\." functor)] + [parser + ["<.>" text]]] + [math + ["." random (#+ Random)] + [number + ["n" nat] + ["i" int]]]] + {#program + ["." /]}) + +(def: #export test + Test + (<| (_.covering /._) + ($_ _.and + (do random.monad + [expected random.time] + (_.cover [/.format /.parser] + (|> expected + /.format + (.run /.parser) + (try\map (\ time.equivalence = expected)) + (try.default false)))) + ))) diff --git a/stdlib/source/test/lux/macro.lux b/stdlib/source/test/lux/macro.lux index 35476eee0..54370efb9 100644 --- a/stdlib/source/test/lux/macro.lux +++ b/stdlib/source/test/lux/macro.lux @@ -5,8 +5,7 @@ ["#." code] ["#." template] ["#." poly] - ["#." syntax - ["#/." common]]]) + ["#." syntax]]) (def: #export test Test @@ -14,6 +13,5 @@ /code.test /template.test /syntax.test - /syntax/common.test /poly.test )) diff --git a/stdlib/source/test/lux/macro/poly/json.lux b/stdlib/source/test/lux/macro/poly/json.lux index 98b955af8..f69af1397 100644 --- a/stdlib/source/test/lux/macro/poly/json.lux +++ b/stdlib/source/test/lux/macro/poly/json.lux @@ -49,7 +49,7 @@ [time ["_." instant] ## ["_." duration] - ["_." date]]]]) + ]]]) (type: Variant (#Bit Bit) @@ -103,7 +103,7 @@ ..gen_recursive ## _instant.instant ## _duration.duration - _date.date + random.date ..qty ))) diff --git a/stdlib/source/test/lux/macro/syntax/annotations.lux b/stdlib/source/test/lux/macro/syntax/annotations.lux new file mode 100644 index 000000000..564af4ea1 --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/annotations.lux @@ -0,0 +1,53 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try] + [parser + ["<.>" code]]] + [data + [collection + ["." list]]] + [math + ["." random (#+ Random)] + [number + ["n" nat]]]] + {1 + ["." /]} + ["$." /// #_ + ["#." code]]) + +(def: #export random + (Random /.Annotations) + (let [word (random.ascii/alpha 10) + tag (random.and word word)] + (do {! random.monad} + [size (\ ! map (n.% 10) random.nat)] + (random.list size (random.and tag $///code.random))))) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Annotations]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (_.cover [/.empty] + (list.empty? /.empty)) + (do random.monad + [expected ..random] + (_.cover [/.write /.parser] + (case (.run /.parser + (list (/.write expected))) + (#try.Failure _) + false + + (#try.Success actual) + (\ /.equivalence = expected actual)))) + ))) diff --git a/stdlib/source/test/lux/macro/syntax/check.lux b/stdlib/source/test/lux/macro/syntax/check.lux new file mode 100644 index 000000000..898ad8abb --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/check.lux @@ -0,0 +1,48 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try] + ["<>" parser + ["<.>" code]]] + [math + ["." random (#+ Random)]] + [macro + ["." code ("#\." equivalence)]]] + {1 + ["." /]} + ["$." /// #_ + ["#." code]]) + +(def: #export random + (Random /.Check) + ($_ random.and + $///code.random + $///code.random + )) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Check]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [[type value] ..random] + (_.cover [/.write /.parser] + (case (.run /.parser + (list (/.write {#/.type type + #/.value value}))) + (#try.Failure _) + false + + (#try.Success check) + (and (code\= type (get@ #/.type check)) + (code\= value (get@ #/.value check))))))))) diff --git a/stdlib/source/test/lux/macro/syntax/common.lux b/stdlib/source/test/lux/macro/syntax/common.lux deleted file mode 100644 index 2929417e3..000000000 --- a/stdlib/source/test/lux/macro/syntax/common.lux +++ /dev/null @@ -1,71 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)] - [equivalence (#+ Equivalence)]] - [control - [pipe (#+ case>)] - ["." try] - ["<>" parser - ["" code]]] - [data - ["." product] - ["." bit ("#\." equivalence)] - ["." name] - ["." text] - [collection - ["." list]]] - [macro - ["." code]] - [math - ["." random (#+ Random)] - [number - ["n" nat]]]] - {1 - ["." / - ["#." reader] - ["#." writer]]} - ["." /// #_ - ["#." code]] - ["." / #_ - ["#." annotations] - ["#." check] - ["#." declaration] - ["#." definition] - ["#." export] - ["#." type #_ - ["#/." variable]]]) - -(def: random_text - (Random Text) - (random.ascii/alpha 10)) - -(def: #export test - Test - (<| (_.covering /._) - (_.covering /reader._) - (_.covering /writer._) - ($_ _.and - (do {! random.monad} - [expected (: (Random /.Typed_Input) - (random.and ///code.random - ///code.random))] - (_.cover [/.Typed_Input /reader.typed_input /writer.typed_input] - (|> expected - /writer.typed_input list - (.run /reader.typed_input) - (case> (#try.Success actual) - (let [equivalence (product.equivalence code.equivalence code.equivalence)] - (\ equivalence = expected actual)) - - (#try.Failure error) - false)))) - - /annotations.test - /check.test - /declaration.test - /definition.test - /export.test - /type/variable.test - ))) diff --git a/stdlib/source/test/lux/macro/syntax/common/annotations.lux b/stdlib/source/test/lux/macro/syntax/common/annotations.lux deleted file mode 100644 index b1369ef48..000000000 --- a/stdlib/source/test/lux/macro/syntax/common/annotations.lux +++ /dev/null @@ -1,53 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)] - {[0 #spec] - [/ - ["$." equivalence]]}] - [control - ["." try] - [parser - ["<.>" code]]] - [data - [collection - ["." list]]] - [math - ["." random (#+ Random)] - [number - ["n" nat]]]] - {1 - ["." /]} - ["$." //// #_ - ["#." code]]) - -(def: #export random - (Random /.Annotations) - (let [word (random.ascii/alpha 10) - tag (random.and word word)] - (do {! random.monad} - [size (\ ! map (n.% 10) random.nat)] - (random.list size (random.and tag $////code.random))))) - -(def: #export test - Test - (<| (_.covering /._) - (_.for [/.Annotations]) - ($_ _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - - (_.cover [/.empty] - (list.empty? /.empty)) - (do random.monad - [expected ..random] - (_.cover [/.write /.parser] - (case (.run /.parser - (list (/.write expected))) - (#try.Failure _) - false - - (#try.Success actual) - (\ /.equivalence = expected actual)))) - ))) diff --git a/stdlib/source/test/lux/macro/syntax/common/check.lux b/stdlib/source/test/lux/macro/syntax/common/check.lux deleted file mode 100644 index 6b4a4ab3d..000000000 --- a/stdlib/source/test/lux/macro/syntax/common/check.lux +++ /dev/null @@ -1,48 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)] - {[0 #spec] - [/ - ["$." equivalence]]}] - [control - ["." try] - ["<>" parser - ["<.>" code]]] - [math - ["." random (#+ Random)]] - [macro - ["." code ("#\." equivalence)]]] - {1 - ["." /]} - ["$." //// #_ - ["#." code]]) - -(def: #export random - (Random /.Check) - ($_ random.and - $////code.random - $////code.random - )) - -(def: #export test - Test - (<| (_.covering /._) - (_.for [/.Check]) - ($_ _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - - (do random.monad - [[type value] ..random] - (_.cover [/.write /.parser] - (case (.run /.parser - (list (/.write {#/.type type - #/.value value}))) - (#try.Failure _) - false - - (#try.Success check) - (and (code\= type (get@ #/.type check)) - (code\= value (get@ #/.value check))))))))) diff --git a/stdlib/source/test/lux/macro/syntax/common/declaration.lux b/stdlib/source/test/lux/macro/syntax/common/declaration.lux deleted file mode 100644 index a9bc23296..000000000 --- a/stdlib/source/test/lux/macro/syntax/common/declaration.lux +++ /dev/null @@ -1,47 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)] - {[0 #spec] - [/ - ["$." equivalence]]}] - [control - ["." try] - [parser - ["<.>" code]]] - [math - ["." random (#+ Random)] - [number - ["n" nat]]]] - {1 - ["." /]}) - -(def: #export random - (Random /.Declaration) - (let [word (random.ascii/alpha 10)] - ($_ random.and - word - (do {! random.monad} - [size (\ ! map (n.% 10) random.nat)] - (random.list size word)) - ))) - -(def: #export test - Test - (<| (_.covering /._) - (_.for [/.Declaration]) - ($_ _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - - (do random.monad - [expected ..random] - (_.cover [/.write /.parser] - (case (.run /.parser - (list (/.write expected))) - (#try.Failure _) - false - - (#try.Success actual) - (\ /.equivalence = expected actual))))))) diff --git a/stdlib/source/test/lux/macro/syntax/common/definition.lux b/stdlib/source/test/lux/macro/syntax/common/definition.lux deleted file mode 100644 index a769df641..000000000 --- a/stdlib/source/test/lux/macro/syntax/common/definition.lux +++ /dev/null @@ -1,97 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)] - {[0 #spec] - [/ - ["$." equivalence]]}] - [control - ["." try] - ["." exception] - ["<>" parser - ["<.>" code]]] - [math - ["." random (#+ Random)]] - [macro - ["." code ("#\." equivalence)]] - [meta - ["." location]]] - {1 - ["." /]} - ["$."// #_ - ["#." check] - ["#." annotations] - ["#//" /// #_ - ["#." code]]]) - -(def: #export random - (Random /.Definition) - ($_ random.and - (random.ascii/alpha 5) - (random.or $//check.random - $////code.random) - $//annotations.random - random.bit - )) - -(def: compiler - {#.info {#.target "FAKE" - #.version "0.0.0" - #.mode #.Build} - #.source [location.dummy 0 ""] - #.location location.dummy - #.current_module #.None - #.modules (list) - #.scopes (list) - #.type_context {#.ex_counter 0 - #.var_counter 0 - #.var_bindings (list)} - #.expected #.None - #.seed 0 - #.scope_type_vars (list) - #.extensions [] - #.host []}) - -(def: #export test - Test - (<| (_.covering /._) - (_.for [/.Definition]) - ($_ _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - - (do random.monad - [expected ..random - - type $////code.random - untyped_value $////code.random] - ($_ _.and - (_.cover [/.write /.parser] - (case (.run (/.parser compiler) - (list (/.write expected))) - (#try.Failure error) - false - - (#try.Success actual) - (\ /.equivalence = expected actual))) - (_.cover [/.typed] - (let [expected (set@ #/.value (#.Left [type untyped_value]) expected)] - (case (.run (/.typed compiler) - (list (/.write expected))) - (#try.Failure error) - false - - (#try.Success actual) - (\ /.equivalence = expected actual)))) - (_.cover [/.lacks_type!] - (let [expected (set@ #/.value (#.Right untyped_value) expected)] - (case (.run (/.typed compiler) - (list (/.write expected))) - (#try.Failure error) - (exception.match? /.lacks_type! error) - - (#try.Success actual) - false))) - ))) - )) diff --git a/stdlib/source/test/lux/macro/syntax/common/export.lux b/stdlib/source/test/lux/macro/syntax/common/export.lux deleted file mode 100644 index 59b72eb0f..000000000 --- a/stdlib/source/test/lux/macro/syntax/common/export.lux +++ /dev/null @@ -1,29 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)]] - [control - ["." try] - [parser - ["<.>" code]]] - [data - ["." bit ("#\." equivalence)]] - [math - ["." random]]] - {1 - ["." /]}) - -(def: #export test - Test - (<| (_.covering /._) - (do random.monad - [expected random.bit] - (_.cover [/.write /.parser] - (case (.run /.parser - (/.write expected)) - (#try.Failure _) - false - - (#try.Success actual) - (bit\= expected actual)))))) diff --git a/stdlib/source/test/lux/macro/syntax/common/type/variable.lux b/stdlib/source/test/lux/macro/syntax/common/type/variable.lux deleted file mode 100644 index 4701f5aef..000000000 --- a/stdlib/source/test/lux/macro/syntax/common/type/variable.lux +++ /dev/null @@ -1,37 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)] - {[0 #spec] - [/ - ["$." equivalence]]}] - [control - ["." try ("#\." functor)] - [parser - ["<.>" code]]] - [math - ["." random (#+ Random)]]] - {1 - ["." /]}) - -(def: #export random - (Random /.Variable) - (random.ascii/alpha 10)) - -(def: #export test - Test - (<| (_.covering /._) - (_.for [/.Variable]) - ($_ _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - - (do random.monad - [expected ..random] - (_.cover [/.format /.parser] - (|> (list (/.format expected)) - (.run /.parser) - (try\map (\ /.equivalence = expected)) - (try.default false)))) - ))) diff --git a/stdlib/source/test/lux/macro/syntax/declaration.lux b/stdlib/source/test/lux/macro/syntax/declaration.lux new file mode 100644 index 000000000..a9bc23296 --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/declaration.lux @@ -0,0 +1,47 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try] + [parser + ["<.>" code]]] + [math + ["." random (#+ Random)] + [number + ["n" nat]]]] + {1 + ["." /]}) + +(def: #export random + (Random /.Declaration) + (let [word (random.ascii/alpha 10)] + ($_ random.and + word + (do {! random.monad} + [size (\ ! map (n.% 10) random.nat)] + (random.list size word)) + ))) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Declaration]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [expected ..random] + (_.cover [/.write /.parser] + (case (.run /.parser + (list (/.write expected))) + (#try.Failure _) + false + + (#try.Success actual) + (\ /.equivalence = expected actual))))))) diff --git a/stdlib/source/test/lux/macro/syntax/definition.lux b/stdlib/source/test/lux/macro/syntax/definition.lux new file mode 100644 index 000000000..d6b101894 --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/definition.lux @@ -0,0 +1,97 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try] + ["." exception] + ["<>" parser + ["<.>" code]]] + [math + ["." random (#+ Random)]] + [macro + ["." code ("#\." equivalence)]] + [meta + ["." location]]] + {1 + ["." /]} + ["$."// #_ + ["#." check] + ["#." annotations] + ["#/" // #_ + ["#." code]]]) + +(def: #export random + (Random /.Definition) + ($_ random.and + (random.ascii/alpha 5) + (random.or $//check.random + $///code.random) + $//annotations.random + random.bit + )) + +(def: compiler + {#.info {#.target "FAKE" + #.version "0.0.0" + #.mode #.Build} + #.source [location.dummy 0 ""] + #.location location.dummy + #.current_module #.None + #.modules (list) + #.scopes (list) + #.type_context {#.ex_counter 0 + #.var_counter 0 + #.var_bindings (list)} + #.expected #.None + #.seed 0 + #.scope_type_vars (list) + #.extensions [] + #.host []}) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Definition]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [expected ..random + + type $///code.random + untyped_value $///code.random] + ($_ _.and + (_.cover [/.write /.parser] + (case (.run (/.parser compiler) + (list (/.write expected))) + (#try.Failure error) + false + + (#try.Success actual) + (\ /.equivalence = expected actual))) + (_.cover [/.typed] + (let [expected (set@ #/.value (#.Left [type untyped_value]) expected)] + (case (.run (/.typed compiler) + (list (/.write expected))) + (#try.Failure error) + false + + (#try.Success actual) + (\ /.equivalence = expected actual)))) + (_.cover [/.lacks_type!] + (let [expected (set@ #/.value (#.Right untyped_value) expected)] + (case (.run (/.typed compiler) + (list (/.write expected))) + (#try.Failure error) + (exception.match? /.lacks_type! error) + + (#try.Success actual) + false))) + ))) + )) diff --git a/stdlib/source/test/lux/macro/syntax/export.lux b/stdlib/source/test/lux/macro/syntax/export.lux new file mode 100644 index 000000000..59b72eb0f --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/export.lux @@ -0,0 +1,29 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)]] + [control + ["." try] + [parser + ["<.>" code]]] + [data + ["." bit ("#\." equivalence)]] + [math + ["." random]]] + {1 + ["." /]}) + +(def: #export test + Test + (<| (_.covering /._) + (do random.monad + [expected random.bit] + (_.cover [/.write /.parser] + (case (.run /.parser + (/.write expected)) + (#try.Failure _) + false + + (#try.Success actual) + (bit\= expected actual)))))) diff --git a/stdlib/source/test/lux/macro/syntax/input.lux b/stdlib/source/test/lux/macro/syntax/input.lux new file mode 100644 index 000000000..b0b642645 --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/input.lux @@ -0,0 +1,46 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try] + [parser + ["<.>" code]]] + [math + ["." random (#+ Random)] + [number + ["n" nat]]]] + {1 + ["." /]} + ["$." /// #_ + ["#." code]]) + +(def: #export random + (Random /.Input) + ($_ random.and + $///code.random + $///code.random + )) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Input]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [expected ..random] + (_.cover [/.format /.parser] + (case (.run /.parser + (list (/.format expected))) + (#try.Failure _) + false + + (#try.Success actual) + (\ /.equivalence = expected actual))))))) diff --git a/stdlib/source/test/lux/macro/syntax/type/variable.lux b/stdlib/source/test/lux/macro/syntax/type/variable.lux new file mode 100644 index 000000000..4701f5aef --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/type/variable.lux @@ -0,0 +1,37 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try ("#\." functor)] + [parser + ["<.>" code]]] + [math + ["." random (#+ Random)]]] + {1 + ["." /]}) + +(def: #export random + (Random /.Variable) + (random.ascii/alpha 10)) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Variable]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [expected ..random] + (_.cover [/.format /.parser] + (|> (list (/.format expected)) + (.run /.parser) + (try\map (\ /.equivalence = expected)) + (try.default false)))) + ))) diff --git a/stdlib/source/test/lux/macro/template.lux b/stdlib/source/test/lux/macro/template.lux index 5733f40ad..53d7d114e 100644 --- a/stdlib/source/test/lux/macro/template.lux +++ b/stdlib/source/test/lux/macro/template.lux @@ -13,6 +13,12 @@ {1 ["." /]}) +(/.with [(!pow/2 ) + (nat.* )] + (def: pow/2 + (-> Nat Nat) + (|>> !pow/2))) + (def: #export test Test (<| (_.covering /._) @@ -59,5 +65,37 @@ var1 right] (and (nat.= left var0) (nat.= right var1))))) + (do ! + [scalar random.nat] + (_.cover [/.with] + (let [can_use_with_statements! + (nat.= ($_ nat.* scalar scalar) + (..pow/2 scalar))] + (and can_use_with_statements! + (/.with [(pow/3 ) + ($_ nat.* ) + + (pow/9 ) + (pow/3 (pow/3 ))] + (let [can_use_with_expressions! + (nat.= ($_ nat.* scalar scalar scalar) + (pow/3 scalar)) + + can_refer! + (nat.= ($_ nat.* + scalar scalar scalar + scalar scalar scalar + scalar scalar scalar) + (pow/9 scalar)) + + can_shadow! + (let [pow/3 (function (_ scalar) + ($_ nat.+ scalar scalar scalar))] + (nat.= ($_ nat.+ scalar scalar scalar) + (pow/3 scalar)))] + (and can_use_with_expressions! + can_refer! + can_shadow!))) + )))) ))) )) diff --git a/stdlib/source/test/lux/time/date.lux b/stdlib/source/test/lux/time/date.lux index 7ad0e8ddc..1c569e476 100644 --- a/stdlib/source/test/lux/time/date.lux +++ b/stdlib/source/test/lux/time/date.lux @@ -1,35 +1,91 @@ (.module: [lux #* - ["%" data/text/format (#+ format)] ["_" test (#+ Test)] - [math - ["." random (#+ Random)]] [abstract - ["." monad (#+ do)] + [monad (#+ do)] {[0 #spec] [/ ["$." equivalence] ["$." order] + ["$." enum] ["$." codec]]}] [control - ["." try]]] - [// - ["_." instant]] + ["." try ("#\." functor)] + ["." exception] + [parser + ["<.>" text]]] + [data + [text + ["%" format (#+ format)]]] + [math + ["." random (#+ Random)] + [number + ["n" nat]]]] {1 - ["." / (#+ Date) - ["." // #_ - ["#." instant]]]}) - -(def: #export date - (Random Date) - (\ random.monad map //instant.date - _instant.instant)) + ["." /]}) (def: #export test Test - (<| (_.context (%.name (name_of /._))) + (<| (_.covering /._) + (_.for [/.Date]) ($_ _.and - ($equivalence.spec /.equivalence ..date) - ($order.spec /.order ..date) - ($codec.spec /.equivalence /.codec ..date) + (_.for [/.equivalence] + ($equivalence.spec /.equivalence random.date)) + (_.for [/.order] + ($order.spec /.order random.date)) + (_.for [/.enum] + ($enum.spec /.enum random.date)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec random.date)) + + (do random.monad + [expected random.date] + (_.cover [/.date /.year /.month /.day_of_month] + (|> (/.date (/.year expected) + (/.month expected) + (/.day_of_month expected)) + (try\map (\ /.equivalence = expected)) + (try.default false)))) + (do random.monad + [expected random.date] + (_.cover [/.invalid_day] + (case (/.date (/.year expected) + (/.month expected) + (n.+ 31 (/.day_of_month expected))) + (#try.Failure error) + (exception.match? /.invalid_day error) + + (#try.Success _) + false))) + (do random.monad + [expected random.date] + (_.cover [/.to_days /.from_days] + (|> expected + /.to_days + /.from_days + (\ /.equivalence = expected)))) + (do random.monad + [expected random.date] + (_.cover [/.parser] + (|> (\ /.codec encode expected) + (.run /.parser) + (try\map (\ /.equivalence = expected)) + (try.default false)))) + (do {! random.monad} + [year (\ ! map (|>> (n.% 10,000) inc) + random.nat) + month (\ ! map (|>> (n.% 10) (n.+ 13)) + random.nat) + day (\ ! map (|>> (n.% 10) (n.+ 10)) + random.nat) + #let [input (format (%.nat year) + "-" (%.nat month) + "-" (%.nat day))]] + (_.cover [/.invalid_month] + (case (.run /.parser input) + (#try.Failure error) + (exception.match? /.invalid_month error) + + (#try.Success _) + false))) ))) -- cgit v1.2.3