From f7d06f791e618aed285b0ed92057f2270d622f8a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 26 Jan 2022 03:11:35 -0400 Subject: Fixes for the "with_expansions" macro. --- stdlib/source/test/lux/macro.lux | 115 +++++++++++++-------- stdlib/source/test/lux/static.lux | 20 +++- stdlib/source/test/lux/tool.lux | 10 +- .../test/lux/tool/compiler/meta/archive/module.lux | 21 ++++ 4 files changed, 119 insertions(+), 47 deletions(-) create mode 100644 stdlib/source/test/lux/tool/compiler/meta/archive/module.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/macro.lux b/stdlib/source/test/lux/macro.lux index 1f28f0e21..ef7463d4e 100644 --- a/stdlib/source/test/lux/macro.lux +++ b/stdlib/source/test/lux/macro.lux @@ -1,36 +1,37 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - [abstract - [monad {"+" do}]] - [control - ["[0]" try ("[1]#[0]" functor)] - [parser - ["<[0]>" code]]] - [data - ["[0]" bit ("[1]#[0]" equivalence)] - ["[0]" text - ["%" format {"+" format}]] - [collection - ["[0]" list]]] - [math - ["[0]" random {"+" Random}] - [number - ["[0]" nat]]] - ["[0]" meta - ["[0]" location] - ["[0]" symbol]]]] - [\\library - ["[0]" / - [syntax {"+" syntax:}] - ["[0]" code ("[1]#[0]" equivalence)] - ["[0]" template]]] - ["[0]" / "_" - ["[1][0]" code] - ["[1][0]" local] - ["[1][0]" syntax] - ["[1][0]" template]]) + [library + [lux "*" + ["_" test {"+" Test}] + ["[0]" static] + [abstract + [monad {"+" do}]] + [control + ["[0]" try ("[1]#[0]" functor)] + [parser + ["<[0]>" code]]] + [data + ["[0]" bit ("[1]#[0]" equivalence)] + ["[0]" text + ["%" format {"+" format}]] + [collection + ["[0]" list]]] + [math + ["[0]" random {"+" Random} ("[1]#[0]" functor)] + [number + ["n" nat]]] + ["[0]" meta + ["[0]" location] + ["[0]" symbol]]]] + [\\library + ["[0]" / + [syntax {"+" syntax:}] + ["[0]" code ("[1]#[0]" equivalence)] + ["[0]" template]]] + ["[0]" / "_" + ["[1][0]" code] + ["[1][0]" local] + ["[1][0]" syntax] + ["[1][0]" template]]) (template: (!expect ) [(case @@ -42,7 +43,7 @@ [(template.text []) {.#Definition [true .Macro ]}])]) (syntax: (pow/2 [number .any]) - (in (list (` (nat.* (~ number) (~ number)))))) + (in (list (` (n.* (~ number) (~ number)))))) (syntax: (pow/4 [number .any]) (in (list (` (..pow/2 (..pow/2 (~ number))))))) @@ -100,19 +101,25 @@ .#eval (:as (-> Type Code (Meta Any)) []) .#host []]]))) -(def: expander +(syntax: (iterated [cycle .nat + it .any]) + (in (list (case cycle + 0 it + _ (` (..iterated (~ (code.nat (-- cycle))) (~ it))))))) + +(def: test|expansion Test (do [! random.monad] [[seed symbol_prefix lux] ..random_lux pow/1 (# ! each code.nat random.nat) - repetitions (# ! each (nat.% 10) random.nat) + repetitions (# ! each (n.% 10) random.nat) .let [single_expansion (` (..pow/2 (..pow/2 (~ pow/1)))) - expansion (` (nat.* (..pow/2 (~ pow/1)) - (..pow/2 (~ pow/1)))) - full_expansion (` (nat.* (nat.* (~ pow/1) (~ pow/1)) - (nat.* (~ pow/1) (~ pow/1))))]] + expansion (` (n.* (..pow/2 (~ pow/1)) + (..pow/2 (~ pow/1)))) + full_expansion (` (n.* (n.* (~ pow/1) (~ pow/1)) + (n.* (~ pow/1) (~ pow/1))))]] (`` ($_ _.and (~~ (template [ ] [(_.cover [] @@ -137,10 +144,36 @@ [/.full_expansion /.log_full_expansion! full_expansion] )) (_.cover [/.one_expansion] - (bit#= (not (nat.= 1 repetitions)) + (bit#= (not (n.= 1 repetitions)) (|> (/.one_expansion (` (..repeated (~ (code.nat repetitions)) (~ pow/1)))) (meta.result lux) (!expect {try.#Failure _})))) + (_.cover [/.final] + (with_expansions [ (static.random_nat) + (static.random code.nat + (random#each (|>> (n.% 5) ++) random.nat)) + (/.final (..iterated ))] + (case (' ) + [_ {.#Nat actual}] + (n.= actual) + + _ + false))) + (_.cover [/.times] + (with_expansions [ (static.random_nat) + (static.random code.nat + (random#each (|>> (n.% 10) (n.+ 2)) random.nat)) + (static.random code.nat + (random#each (|>> (n.% ) ++) random.nat)) + (/.times (..iterated ))] + (let [expected_remaining (n.- )] + (case (` ) + (^code (..iterated (~ [_ {.#Nat actual_remaining}]) (~ [_ {.#Nat actual}]))) + (and (n.= expected_remaining actual_remaining) + (n.= actual)) + + _ + false)))) )))) (def: .public test @@ -173,7 +206,7 @@ actual)))))) )) - ..expander + ..test|expansion /code.test /local.test diff --git a/stdlib/source/test/lux/static.lux b/stdlib/source/test/lux/static.lux index c8425f21d..691749810 100644 --- a/stdlib/source/test/lux/static.lux +++ b/stdlib/source/test/lux/static.lux @@ -6,11 +6,13 @@ ["[0]" meta] [data ["[0]" text ("[1]#[0]" equivalence) - ["%" format {"+" format}]]] + ["%" format {"+" format}]] + [collection + ["[0]" list ("[1]#[0]" mix)]]] [macro ["[0]" code]] [math - ["[0]" random] + ["[0]" random ("[1]#[0]" functor)] [number ["n" nat] ["i" int] @@ -65,6 +67,13 @@ _ false))) + (_.cover [/.randoms] + (with_expansions [ (/.random code.nat + (random#each (|>> (n.% 10) ++) random.nat)) + l/* (/.randoms code.nat (random.list random.nat))] + (and (n.= (list.size (list l/*))) + (n.= (list#mix n.+ 0 (list l/*)) + ($_ n.+ l/*))))) (_.cover [/.literal] (with_expansions [ (/.random code.text (random.ascii/alpha_num 1)) (/.random code.text (random.ascii/alpha_num 1)) @@ -75,4 +84,11 @@ _ false))) + (_.cover [/.literals] + (with_expansions [l/0 (/.random_nat) + l/1 (/.random_nat) + l/2 (/.random_nat) + l/* (/.literals code.nat (list l/0 l/1 l/2))] + (n.= ($_ n.+ l/0 l/1 l/2) + ($_ n.+ l/*)))) )))) diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux index 25f869808..c0e7fd739 100644 --- a/stdlib/source/test/lux/tool.lux +++ b/stdlib/source/test/lux/tool.lux @@ -20,11 +20,12 @@ ]]] ["[1][0]" meta "_" ["[1]/[0]" archive "_" - ["[1]/[0]" artifact] ["[1]/[0]" signature] ["[1]/[0]" key] - ["[1]/[0]" document] + ["[1]/[0]" artifact] ["[1]/[0]" registry] + ["[1]/[0]" module] + ["[1]/[0]" document] ["[1]/[0]" descriptor]]] ]]) @@ -36,11 +37,12 @@ /reference.test /phase.test /analysis.test - /meta/archive/artifact.test /meta/archive/signature.test /meta/archive/key.test - /meta/archive/document.test + /meta/archive/artifact.test /meta/archive/registry.test + /meta/archive/module.test + /meta/archive/document.test /meta/archive/descriptor.test /phase/extension.test /phase/analysis/simple.test diff --git a/stdlib/source/test/lux/tool/compiler/meta/archive/module.lux b/stdlib/source/test/lux/tool/compiler/meta/archive/module.lux new file mode 100644 index 000000000..3d0bc262e --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/meta/archive/module.lux @@ -0,0 +1,21 @@ +(.using + [library + [lux "*" + ["_" test {"+" Test}] + [abstract + [monad {"+" do}]] + [math + ["[0]" random] + [number + ["n" nat]]]]] + [\\library + ["[0]" /]]) + +(def: .public test + Test + (<| (_.covering /._) + (_.for [/.Module]) + ($_ _.and + (_.cover [/.ID /.runtime] + (n.= 0 /.runtime)) + ))) -- cgit v1.2.3