diff options
author | Eduardo Julian | 2022-08-19 01:14:18 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-08-19 01:14:18 -0400 |
commit | a0517211a4e107f013995cd10e9693acad6885a9 (patch) | |
tree | 0aa162f48fb9ea317cf043b99b2a89c9887b8990 /stdlib/source/test | |
parent | 81b6e0d7038a99c66456033c8285f740a3b0c719 (diff) |
Added functions with named parameters.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/control/function.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/function/named.lux | 73 | ||||
-rw-r--r-- | stdlib/source/test/lux/meta/macro.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/meta/macro/context.lux | 103 |
4 files changed, 182 insertions, 2 deletions
diff --git a/stdlib/source/test/lux/control/function.lux b/stdlib/source/test/lux/control/function.lux index b3e79f47d..a2ac4a355 100644 --- a/stdlib/source/test/lux/control/function.lux +++ b/stdlib/source/test/lux/control/function.lux @@ -21,7 +21,8 @@ ["[1][0]" mutual] ["[1][0]" inline] ["[1][0]" predicate] - ["[1][0]" variadic]]) + ["[1][0]" variadic] + ["[1][0]" named]]) (def .public test Test @@ -69,4 +70,5 @@ /inline.test /predicate.test /variadic.test + /named.test )))) diff --git a/stdlib/source/test/lux/control/function/named.lux b/stdlib/source/test/lux/control/function/named.lux new file mode 100644 index 000000000..064e2e8ab --- /dev/null +++ b/stdlib/source/test/lux/control/function/named.lux @@ -0,0 +1,73 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [control + ["[0]" try] + ["[0]" exception]] + [data + ["[0]" text]] + [math + ["[0]" random] + [number + ["n" nat]]] + [meta + ["[0]" code (.only) + ["<[1]>" \\parser]] + [macro + [syntax (.only syntax)] + ["[0]" expansion]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(def macro_error + (syntax (_ [macro <code>.any]) + (function (_ compiler) + (when ((expansion.complete macro) compiler) + {try.#Failure error} + {try.#Success [compiler (list (code.text error))]} + + {try.#Success _} + {try.#Failure "OOPS!"})))) + +(/.def (+ left right) + (-> Nat Nat Nat) + (n.+ left right)) + +(def .public test + Test + (do [! random.monad] + [p0 random.nat + p1 random.nat] + (<| (_.covering /._) + (all _.and + (_.coverage [/.def] + (n.= (n.+ p0 p1) + (+ left p0 + right p1))) + (_.coverage [/.duplicate_parameters] + (text.contains? (the exception.#label /.duplicate_parameters) + (macro_error + (/.def .public (- _ _) + (-> Nat (List Nat) Nat) + (undefined))))) + (_.coverage [/.invalid_parameters] + (and (text.contains? (the exception.#label /.invalid_parameters) + (macro_error + (+ left p0))) + (text.contains? (the exception.#label /.invalid_parameters) + (macro_error + (+ right p1))) + (text.contains? (the exception.#label /.invalid_parameters) + (macro_error + (+ left p0 + right p1 + yolo p0))) + (text.contains? (the exception.#label /.invalid_parameters) + (macro_error + (+ left p0 + yolo p0))))) + )))) diff --git a/stdlib/source/test/lux/meta/macro.lux b/stdlib/source/test/lux/meta/macro.lux index b2b7e0eda..270040d6d 100644 --- a/stdlib/source/test/lux/meta/macro.lux +++ b/stdlib/source/test/lux/meta/macro.lux @@ -30,6 +30,7 @@ ["[0]" template] ["[0]" expansion]]] ["[0]" / + ["[1][0]" context] ["[1][0]" local] ["[1][0]" syntax] ["[1][0]" template] @@ -247,7 +248,8 @@ )) ..test|expansion - + + /context.test /local.test /syntax.test /template.test diff --git a/stdlib/source/test/lux/meta/macro/context.lux b/stdlib/source/test/lux/meta/macro/context.lux new file mode 100644 index 000000000..cbcdf60e0 --- /dev/null +++ b/stdlib/source/test/lux/meta/macro/context.lux @@ -0,0 +1,103 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [control + ["[0]" try] + ["[0]" exception]] + [data + ["[0]" text (.only) + ["%" \\format]]] + [math + [number + ["n" nat]]] + ["[0]" meta (.only) + ["[0]" static] + ["[0]" code (.only) + ["<[1]>" \\parser]] + [macro + [syntax (.only syntax)] + ["[0]" expansion]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(def macro_error + (syntax (_ [macro <code>.any]) + (function (_ compiler) + (when ((expansion.complete macro) compiler) + {try.#Failure error} + {try.#Success [compiler (list (code.text error))]} + + {try.#Success _} + {try.#Failure "OOPS!"})))) + +(/.def [stack expression declaration] Nat) + +(with_expansions [<top> (static.random_nat)] + (<| static.expansion + (declaration <top>) + (` (def (,' declaration!) true)))) + +(def .public test + Test + (<| (_.covering /._) + (all _.and + (_.coverage [/.def] + (and declaration! + (with_expansions [<top> (static.random_nat)] + (<| static.expansion + (do meta.monad + [it (expression <top> (` true))] + (in (list it))))))) + (_.coverage [/.peek /.peek' + /.push /.push'] + (with_expansions [<expected> (static.random_nat)] + (n.= <expected> + (<| static.expansion + (do meta.monad + [_ (/.push <expected> ..stack) + actual (/.peek ..stack) + _ (/.pop ..stack)] + (in (list (code.nat actual)))))))) + (_.coverage [/.no_active_context] + (<| (text.contains? (the exception.#label /.no_active_context)) + macro_error + static.expansion + (do meta.monad + [top (/.peek ..stack)] + (in (list (code.nat top)))))) + (_.coverage [/.pop /.pop' /.pop''] + (with_expansions [<dummy> (static.random_nat) + <expected> (static.nat (++ <dummy>))] + (n.= <expected> + (<| static.expansion + (do meta.monad + [_ (/.push <dummy> ..stack) + _ (/.pop ..stack) + _ (/.push <expected> ..stack) + actual (/.peek ..stack) + _ (/.pop ..stack)] + (in (list (code.nat actual)))))))) + (_.coverage [/.search /.search'] + (with_expansions [<expected> (static.random_nat)] + (n.= <expected> + (<| static.expansion + (do meta.monad + [_ (/.push <expected> ..stack) + actual (/.search (n.= <expected>) ..stack) + _ (/.pop ..stack)] + (in (list (code.nat actual)))))))) + (_.coverage [/.no_example] + (with_expansions [<expected> (static.random_nat)] + (<| (text.contains? (the exception.#label /.no_example)) + macro_error + static.expansion + (do meta.monad + [_ (/.push <expected> ..stack) + actual (/.search (|>> (n.= <expected>) not) ..stack) + _ (/.pop ..stack)] + (in (list (code.nat actual))))))) + ))) |