From 664e02d1b5e5aa479869c4e17ec4128f5cfd04e2 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 29 Jun 2022 03:15:23 -0400 Subject: New "parser" hierarchy. [Part 6] --- stdlib/source/test/lux/control/parser.lux | 6 +- .../source/test/lux/control/parser/environment.lux | 53 ---------- stdlib/source/test/lux/world.lux | 4 +- stdlib/source/test/lux/world/environment.lux | 113 +++++++++++++++++++++ stdlib/source/test/lux/world/program.lux | 78 -------------- stdlib/source/test/lux/world/shell.lux | 8 +- 6 files changed, 120 insertions(+), 142 deletions(-) delete mode 100644 stdlib/source/test/lux/control/parser/environment.lux create mode 100644 stdlib/source/test/lux/world/environment.lux delete mode 100644 stdlib/source/test/lux/world/program.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index 624999201..aa083b543 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -25,9 +25,7 @@ ["[0]" code (.only) ["<[1]>" \\parser]]]]] [\\library - ["[0]" / (.only Parser)]] - ["[0]" / - ["[1][0]" environment]]) + ["[0]" / (.only Parser)]]) (def (should_fail expected input) (All (_ a) (-> Text (Try a) Bit)) @@ -374,6 +372,4 @@ ..combinators_0 ..combinators_1 ..combinators_2 - - /environment.test )))) diff --git a/stdlib/source/test/lux/control/parser/environment.lux b/stdlib/source/test/lux/control/parser/environment.lux deleted file mode 100644 index bc4d924b3..000000000 --- a/stdlib/source/test/lux/control/parser/environment.lux +++ /dev/null @@ -1,53 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)]] - [control - ["[0]" try] - ["[0]" exception]] - [data - ["[0]" text (.use "[1]#[0]" equivalence)] - [collection - ["[0]" dictionary]]] - [math - ["[0]" random] - [number - ["n" nat]]]]] - [\\library - ["[0]" / (.only) - ["/[1]" // (.use "[1]#[0]" monad)]]]) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Environment /.Parser]) - (all _.and - (_.coverage [/.empty] - (dictionary.empty? /.empty)) - (do random.monad - [expected random.nat] - (_.coverage [/.result] - (|> (/.result (//#in expected) /.empty) - (at try.functor each (n.= expected)) - (try.else false)))) - (do random.monad - [property (random.alphabetic 1) - expected (random.alphabetic 1)] - (_.coverage [/.Property /.property] - (|> /.empty - (dictionary.has property expected) - (/.result (/.property property)) - (at try.functor each (text#= expected)) - (try.else false)))) - (do random.monad - [property (random.alphabetic 1)] - (_.coverage [/.unknown_property] - (case (/.result (/.property property) /.empty) - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.unknown_property error)))) - ))) diff --git a/stdlib/source/test/lux/world.lux b/stdlib/source/test/lux/world.lux index 19576d27d..37b9d2892 100644 --- a/stdlib/source/test/lux/world.lux +++ b/stdlib/source/test/lux/world.lux @@ -6,7 +6,7 @@ ["[1][0]" file] ["[1][0]" shell] ["[1][0]" console] - ["[1][0]" program] + ["[1][0]" environment] ["[1][0]" input ["[1]/[0]" keyboard]] ["[1][0]" output @@ -23,7 +23,7 @@ /file.test /shell.test /console.test - /program.test + /environment.test /input/keyboard.test /output/video/resolution.test /net/http/client.test diff --git a/stdlib/source/test/lux/world/environment.lux b/stdlib/source/test/lux/world/environment.lux new file mode 100644 index 000000000..ee9879d21 --- /dev/null +++ b/stdlib/source/test/lux/world/environment.lux @@ -0,0 +1,113 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)]] + [control + ["//" parser (.use "[1]#[0]" monad)] + ["[0]" pipe] + ["[0]" io] + ["[0]" maybe (.use "[1]#[0]" functor)] + ["[0]" try] + ["[0]" exception]] + [data + ["[0]" text (.use "[1]#[0]" equivalence)] + [collection + ["[0]" dictionary] + ["[0]" list]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]]]] + ["[0]" \\parser (.only Environment)] + [\\library + ["[0]" / (.only) + [// + [file (.only Path)]]]] + [\\specification + ["$[0]" /]]) + +(def \\parser + Test + (<| (_.covering \\parser._) + (_.for [\\parser.Environment \\parser.Parser]) + (all _.and + (_.coverage [\\parser.empty] + (dictionary.empty? \\parser.empty)) + (do random.monad + [expected random.nat] + (_.coverage [\\parser.result] + (|> (\\parser.result (//#in expected) \\parser.empty) + (at try.functor each (n.= expected)) + (try.else false)))) + (do random.monad + [property (random.alphabetic 1) + expected (random.alphabetic 1)] + (_.coverage [\\parser.Property \\parser.property] + (|> \\parser.empty + (dictionary.has property expected) + (\\parser.result (\\parser.property property)) + (at try.functor each (text#= expected)) + (try.else false)))) + (do random.monad + [property (random.alphabetic 1)] + (_.coverage [\\parser.unknown_property] + (case (\\parser.result (\\parser.property property) \\parser.empty) + {try.#Success _} + false + + {try.#Failure error} + (exception.match? \\parser.unknown_property error)))) + ))) + +(def (environment env_size) + (-> Nat (Random Environment)) + (random.dictionary text.hash env_size + (random.alphabetic 5) + (random.alphabetic 5))) + +(def path + (Random Path) + (random.alphabetic 5)) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [env_size (at ! each (|>> (n.% 10) ++) random.nat) + environment (..environment env_size) + home ..path + directory ..path + + unknown (random.alphabetic 1)] + (all _.and + (_.for [/.mock /.async] + ($/.spec (/.async (/.mock environment home directory)))) + (_.coverage [/.environment] + (let [it (/.mock environment home directory)] + (io.run! + (do io.monad + [actual (/.environment io.monad it)] + (in (and (n.= (dictionary.size environment) + (dictionary.size actual)) + (|> actual + dictionary.entries + (list.every? (function (_ [key value]) + (|> environment + (dictionary.value key) + (maybe#each (text#= value)) + (maybe.else false))))))))))) + (_.coverage [/.unknown_environment_variable] + (let [it (/.mock environment home directory)] + (|> unknown + (at it variable) + io.run! + (pipe.case {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.unknown_environment_variable error))))) + + ..\\parser + )))) diff --git a/stdlib/source/test/lux/world/program.lux b/stdlib/source/test/lux/world/program.lux deleted file mode 100644 index 545401bee..000000000 --- a/stdlib/source/test/lux/world/program.lux +++ /dev/null @@ -1,78 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)]] - [control - ["[0]" pipe] - ["[0]" io] - ["[0]" maybe (.use "[1]#[0]" functor)] - ["[0]" try] - ["[0]" exception] - [parser - [environment (.only Environment)]]] - [data - ["[0]" text (.use "[1]#[0]" equivalence)] - [collection - ["[0]" dictionary] - ["[0]" list]]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat]]]]] - [\\library - ["[0]" / (.only) - [// - [file (.only Path)]]]] - [\\specification - ["$[0]" /]]) - -(def (environment env_size) - (-> Nat (Random Environment)) - (random.dictionary text.hash env_size - (random.alphabetic 5) - (random.alphabetic 5))) - -(def path - (Random Path) - (random.alphabetic 5)) - -(def .public test - Test - (<| (_.covering /._) - (do [! random.monad] - [env_size (at ! each (|>> (n.% 10) ++) random.nat) - environment (..environment env_size) - home ..path - directory ..path - - unknown (random.alphabetic 1)] - (all _.and - (_.for [/.mock /.async] - ($/.spec (/.async (/.mock environment home directory)))) - (_.coverage [/.environment] - (let [program (/.mock environment home directory)] - (io.run! - (do io.monad - [actual (/.environment io.monad program)] - (in (and (n.= (dictionary.size environment) - (dictionary.size actual)) - (|> actual - dictionary.entries - (list.every? (function (_ [key value]) - (|> environment - (dictionary.value key) - (maybe#each (text#= value)) - (maybe.else false))))))))))) - (_.coverage [/.unknown_environment_variable] - (let [program (/.mock environment home directory)] - (|> unknown - (at program variable) - io.run! - (pipe.case {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.unknown_environment_variable error))))) - )))) diff --git a/stdlib/source/test/lux/world/shell.lux b/stdlib/source/test/lux/world/shell.lux index c8738d3a3..09126a8a3 100644 --- a/stdlib/source/test/lux/world/shell.lux +++ b/stdlib/source/test/lux/world/shell.lux @@ -9,9 +9,7 @@ ["[0]" exception (.only exception)] ["[0]" io (.only IO)] [concurrency - ["[0]" async (.only Async)]] - [parser - ["[0]" environment (.only Environment)]]] + ["[0]" async (.only Async)]]] [data ["[0]" text (.use "[1]#[0]" equivalence)] [collection @@ -24,7 +22,9 @@ [\\library ["[0]" / (.only) [// - [file (.only Path)]]]] + [file (.only Path)] + ["[0]" environment + ["[1]" \\parser (.only Environment)]]]]] [\\specification ["$[0]" /]]) -- cgit v1.2.3