diff options
Diffstat (limited to '')
24 files changed, 827 insertions, 938 deletions
diff --git a/stdlib/source/test/aedifex/artifact/snapshot/time.lux b/stdlib/source/test/aedifex/artifact/snapshot/time.lux index d93d9070c..a26532ce1 100644 --- a/stdlib/source/test/aedifex/artifact/snapshot/time.lux +++ b/stdlib/source/test/aedifex/artifact/snapshot/time.lux @@ -7,9 +7,10 @@ [\\specification ["$[0]" equivalence]]] [control - ["[0]" try (.open: "[1]#[0]" functor)] - [parser - ["<[0]>" text]]] + ["[0]" try (.open: "[1]#[0]" functor)]] + [data + ["[0]" text + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random)]]]] [\\program diff --git a/stdlib/source/test/aedifex/artifact/snapshot/version/value.lux b/stdlib/source/test/aedifex/artifact/snapshot/version/value.lux index 27ef6062c..34599cf81 100644 --- a/stdlib/source/test/aedifex/artifact/snapshot/version/value.lux +++ b/stdlib/source/test/aedifex/artifact/snapshot/version/value.lux @@ -7,12 +7,11 @@ [\\specification ["$[0]" equivalence]]] [control - ["[0]" try (.open: "[1]#[0]" functor)] - [parser - ["<[0]>" text]]] + ["[0]" try (.open: "[1]#[0]" functor)]] [data ["[0]" text (.open: "[1]#[0]" equivalence) - ["%" format (.only format)]]] + ["%" format (.only format)] + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random) (.open: "[1]#[0]" monad)] [number diff --git a/stdlib/source/test/aedifex/artifact/time.lux b/stdlib/source/test/aedifex/artifact/time.lux index 56ffe1ea1..8ee637360 100644 --- a/stdlib/source/test/aedifex/artifact/time.lux +++ b/stdlib/source/test/aedifex/artifact/time.lux @@ -7,9 +7,10 @@ [\\specification ["$[0]" equivalence]]] [control - ["[0]" try (.open: "[1]#[0]" functor)] - [parser - ["<[0]>" text]]] + ["[0]" try (.open: "[1]#[0]" functor)]] + [data + ["[0]" text + ["<[1]>" \\parser]]] [time ["[0]" instant (.open: "[1]#[0]" equivalence)]] [math diff --git a/stdlib/source/test/aedifex/artifact/time/date.lux b/stdlib/source/test/aedifex/artifact/time/date.lux index ca23a1d2a..b53420e0a 100644 --- a/stdlib/source/test/aedifex/artifact/time/date.lux +++ b/stdlib/source/test/aedifex/artifact/time/date.lux @@ -8,9 +8,10 @@ ["$[0]" equivalence]]] [control ["[0]" try (.open: "[1]#[0]" functor)] - ["[0]" exception] - [parser - ["<[0]>" text]]] + ["[0]" exception]] + [data + ["[0]" text + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random)] [number diff --git a/stdlib/source/test/aedifex/artifact/time/time.lux b/stdlib/source/test/aedifex/artifact/time/time.lux index a242ae3a4..9a7189e33 100644 --- a/stdlib/source/test/aedifex/artifact/time/time.lux +++ b/stdlib/source/test/aedifex/artifact/time/time.lux @@ -6,9 +6,10 @@ [abstract [monad (.only do)]] [control - ["[0]" try (.open: "[1]#[0]" functor)] - [parser - ["<[0]>" text]]] + ["[0]" try (.open: "[1]#[0]" functor)]] + [data + ["[0]" text + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random)] [number diff --git a/stdlib/source/test/lux/abstract/equivalence.lux b/stdlib/source/test/lux/abstract/equivalence.lux index f3be4cd4a..7740565ed 100644 --- a/stdlib/source/test/lux/abstract/equivalence.lux +++ b/stdlib/source/test/lux/abstract/equivalence.lux @@ -1,22 +1,95 @@ (.using [library - [lux (.except) + [lux (.except Variant Record) ["_" test (.only Test)] + ["@" target] [abstract [monad (.only do)] [\\specification [functor ["$[0]" contravariant]]]] + [control + ["[0]" maybe]] [data - ["[0]" bit (.open: "[1]#[0]" equivalence)]] + ["[0]" bit (.open: "[1]#[0]" equivalence)] + ["[0]" text] + [collection + ["[0]" list]]] [math ["[0]" random (.only Random)] [number ["n" nat] ["i" int]]]]] + ["[0]" \\polytypic] + ["[0]" \\specification] [\\library ["[0]" / (.only Equivalence)]]) +(type: Variant + (.Variant + {#Case0 Bit} + {#Case1 Int} + {#Case2 Frac})) + +(type: Recursive + (Rec Recursive + (.Variant + {#Number Frac} + {#Addition Frac Recursive}))) + +(type: Record + (.Record + [#bit Bit + #int Int + #frac Frac + #text Text + #maybe (Maybe Int) + #list (List Int) + #variant Variant + #tuple [Int Frac Text] + #recursive Recursive])) + +(def: gen_recursive + (Random Recursive) + (random.rec (function (_ gen_recursive) + (random.or random.safe_frac + (random.and random.safe_frac + gen_recursive))))) + +(def: random + (Random Record) + (do [! random.monad] + [size (at ! each (n.% 2) random.nat) + .let [gen_int (|> random.int (at ! each (|>> i.abs (i.% +1,000,000))))]] + (all random.and + random.bit + gen_int + random.safe_frac + (random.unicode size) + (random.maybe gen_int) + (random.list size gen_int) + (all random.or + random.bit + gen_int + random.safe_frac) + (all random.and + gen_int + random.safe_frac + (random.unicode size)) + gen_recursive))) + +(for @.old (these) + (these (def: equivalence + (Equivalence ..Record) + (\\polytypic.equivalence ..Record)))) + +(def: \\polytypic + Test + (<| (_.covering \\polytypic._) + (_.for [\\polytypic.equivalence] + (for @.old (_.property "PLACEHOLDER" true) + (\\specification.spec ..equivalence ..random))))) + (def: .public test Test (do random.monad @@ -57,4 +130,6 @@ (and (at equivalence = (list sample sample) (list sample sample)) (not (at equivalence = (list sample sample) (list sample))) (not (at equivalence = (list sample sample) (list different different)))))) + + ..\\polytypic )))) diff --git a/stdlib/source/test/lux/abstract/functor.lux b/stdlib/source/test/lux/abstract/functor.lux index 9249ba171..5bef11061 100644 --- a/stdlib/source/test/lux/abstract/functor.lux +++ b/stdlib/source/test/lux/abstract/functor.lux @@ -2,20 +2,47 @@ [library [lux (.except) ["_" test (.only Test)] + ["@" target] [abstract [monad (.only do)]] [control - ["[0]" maybe]] + ["[0]" maybe] + ["[0]" state]] [data + ["[0]" identity] [collection ["[0]" list]]] [math ["[0]" random] [number ["n" nat]]]]] + ["[0]" \\polytypic] [\\library ["[0]" / (.only Functor)]]) +(for @.old (these) + (these (def: maybe_functor + (Functor .Maybe) + (\\polytypic.functor .Maybe)) + + (def: list_functor + (Functor .List) + (\\polytypic.functor .List)) + + (def: state_functor + (All (_ s) (Functor (state.State s))) + (\\polytypic.functor state.State)) + + (def: identity_functor + (Functor identity.Identity) + (\\polytypic.functor identity.Identity)))) + +(def: \\polytypic + Test + (<| (_.covering \\polytypic._) + (_.coverage [\\polytypic.functor] + true))) + (def: .public test Test (do random.monad @@ -60,4 +87,6 @@ _ false)) + + ..\\polytypic )))) diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index 656c8b988..8995346a9 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -28,14 +28,12 @@ [\\library ["[0]" / (.only Parser)]] ["[0]" / - ["[1][0]" analysis] ["[1][0]" binary] ["[1][0]" cli] ["[1][0]" code] ["[1][0]" environment] ["[1][0]" json] ["[1][0]" synthesis] - ["[1][0]" text] ["[1][0]" tree] ["[1][0]" type] ["[1][0]" xml]]) @@ -386,14 +384,12 @@ ..combinators_1 ..combinators_2 - /analysis.test /binary.test /cli.test /code.test /environment.test /json.test /synthesis.test - /text.test /tree.test /type.test /xml.test diff --git a/stdlib/source/test/lux/control/parser/analysis.lux b/stdlib/source/test/lux/control/parser/analysis.lux deleted file mode 100644 index 41b24f031..000000000 --- a/stdlib/source/test/lux/control/parser/analysis.lux +++ /dev/null @@ -1,156 +0,0 @@ -(.using - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)]] - [control - ["[0]" pipe] - ["[0]" try] - ["[0]" exception] - ["<>" parser]] - [data - ["[0]" bit (.open: "[1]#[0]" equivalence)] - ["[0]" text (.open: "[1]#[0]" equivalence)] - [collection - ["[0]" list]]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["i" int] - ["f" frac] - ["r" rev]]] - [meta - ["[0]" symbol (.open: "[1]#[0]" equivalence)]] - [tool - [compiler - [reference (.only Constant) - [variable (.only)]] - [language - [lux - ["[0]" analysis]]]]]]] - [\\library - ["[0]" /]]) - -(def: !expect - (template (_ <expectation> <computation>) - [(case <computation> - <expectation> - true - - _ - false)])) - -(def: constant - (Random Constant) - (random.and (random.unicode 10) - (random.unicode 10))) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.Parser]) - (do [! random.monad] - [] - (`` (all _.and - (do [! random.monad] - [expected (at ! each (|>> analysis.bit) random.bit)] - (_.coverage [/.result /.any] - (|> (list expected) - (/.result /.any) - (pipe.case - {try.#Success actual} - (at analysis.equivalence = expected actual) - - {try.#Failure _} - false)))) - (~~ (with_template [<query> <check> <random> <analysis> <=>] - [(do [! random.monad] - [expected <random>] - (_.coverage [<query>] - (|> (list (<analysis> expected)) - (/.result <query>) - (pipe.case - {try.#Success actual} - (<=> expected actual) - - {try.#Failure _} - false)))) - (do [! random.monad] - [expected <random>] - (_.coverage [<check>] - (|> (list (<analysis> expected)) - (/.result (<check> expected)) - (!expect {try.#Success _}))))] - - [/.bit /.this_bit random.bit analysis.bit bit#=] - [/.nat /.this_nat random.nat analysis.nat n.=] - [/.int /.this_int random.int analysis.int i.=] - [/.frac /.this_frac random.safe_frac analysis.frac f.=] - [/.rev /.this_rev random.rev analysis.rev r.=] - [/.text /.this_text (random.unicode 10) analysis.text text#=] - [/.local /.this_local random.nat analysis.local n.=] - [/.foreign /.this_foreign random.nat analysis.foreign n.=] - [/.constant /.this_constant ..constant analysis.constant symbol#=] - )) - (do [! random.monad] - [expected random.bit] - (_.coverage [/.tuple] - (|> (list (analysis.tuple (list (analysis.bit expected)))) - (/.result (/.tuple /.bit)) - (pipe.case - {try.#Success actual} - (bit#= expected actual) - - {try.#Failure _} - false)))) - (do [! random.monad] - [dummy random.bit] - (_.coverage [/.end?] - (and (|> (/.result /.end? (list)) - (!expect {try.#Success #1})) - (|> (/.result (do <>.monad - [verdict /.end? - _ /.bit] - (in verdict)) - (list (analysis.bit dummy))) - (!expect {try.#Success #0}))))) - (do [! random.monad] - [dummy random.bit] - (_.coverage [/.end] - (and (|> (/.result /.end (list)) - (!expect {try.#Success _})) - (|> (/.result /.end (list (analysis.bit dummy))) - (!expect {try.#Failure _}))))) - (do [! random.monad] - [expected random.bit] - (_.coverage [/.cannot_parse] - (and (|> (list (analysis.bit expected)) - (/.result /.nat) - (pipe.case - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.cannot_parse error))) - (|> (list) - (/.result /.bit) - (pipe.case - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.cannot_parse error)))))) - (do [! random.monad] - [expected random.bit] - (_.coverage [/.unconsumed_input] - (|> (list (analysis.bit expected) (analysis.bit expected)) - (/.result /.bit) - (pipe.case - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.unconsumed_input error))))) - ))))) diff --git a/stdlib/source/test/lux/control/parser/text.lux b/stdlib/source/test/lux/control/parser/text.lux deleted file mode 100644 index 1c8390cfc..000000000 --- a/stdlib/source/test/lux/control/parser/text.lux +++ /dev/null @@ -1,444 +0,0 @@ -(.using - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)]] - [control - ["[0]" maybe] - ["[0]" try (.only Try)] - ["[0]" exception (.only Exception)] - ["[0]" function]] - [data - ["[0]" text (.open: "[1]#[0]" equivalence) - ["%" format (.only format)] - ["[0]" unicode - ["[1]" set] - ["[1]/[0]" block]]] - [collection - ["[0]" set] - ["[0]" list (.open: "[1]#[0]" functor)] - [tree - ["[0]" finger]]]] - [math - ["[0]" random] - [number (.only hex) - ["n" nat]]] - [macro - ["^" pattern] - ["[0]" code]]]] - [\\library - ["[0]" / (.only) - ["<>" // (.only) - ["<c>" code]]]]) - -(def: !expect - (template (_ <pattern> <value>) - [(case <value> - <pattern> - true - - _ - false)])) - -(def: (should_fail' sample parser exception) - (All (_ a e) (-> Text (/.Parser a) (Exception e) Bit)) - (case (/.result parser sample) - {try.#Failure error} - (exception.match? exception error) - - _ - false)) - -(def: (should_fail sample parser) - (All (_ a) (-> Text (/.Parser a) Bit)) - (case (/.result parser sample) - {try.#Failure _} - true - - _ - false)) - -(def: (should_pass expected parser) - (-> Text (/.Parser Text) Bit) - (|> expected - (/.result parser) - (at try.functor each (text#= expected)) - (try.else false))) - -(def: (should_pass! expected parser) - (-> Text (/.Parser /.Slice) Bit) - (..should_pass expected (/.slice parser))) - -(def: character_classes - Test - (all _.and - (do [! random.monad] - [offset (at ! each (n.% 50) random.nat) - range (at ! each (|>> (n.% 50) (n.+ 10)) random.nat) - .let [limit (n.+ offset range)] - expected (at ! each (|>> (n.% range) (n.+ offset) text.of_char) random.nat) - out_of_range (case offset - 0 (at ! each (|>> (n.% 10) ++ (n.+ limit) text.of_char) random.nat) - _ (at ! each (|>> (n.% offset) text.of_char) random.nat))] - (_.coverage [/.range] - (and (..should_pass expected (/.range offset limit)) - (..should_fail out_of_range (/.range offset limit))))) - (do [! random.monad] - [expected (random.char unicode.upper_case) - invalid (random.only (|>> (unicode/block.within? unicode/block.upper_case) not) - (random.char unicode.character))] - (_.coverage [/.upper] - (and (..should_pass (text.of_char expected) /.upper) - (..should_fail (text.of_char invalid) /.upper)))) - (do [! random.monad] - [expected (random.char unicode.lower_case) - invalid (random.only (|>> (unicode/block.within? unicode/block.lower_case) not) - (random.char unicode.character))] - (_.coverage [/.lower] - (and (..should_pass (text.of_char expected) /.lower) - (..should_fail (text.of_char invalid) /.lower)))) - (do [! random.monad] - [expected (at ! each (n.% 10) random.nat) - invalid (random.char (unicode.set [unicode/block.number_forms (list)]))] - (_.coverage [/.decimal] - (and (..should_pass (at n.decimal encoded expected) /.decimal) - (..should_fail (text.of_char invalid) /.decimal)))) - (do [! random.monad] - [expected (at ! each (n.% 8) random.nat) - invalid (random.char (unicode.set [unicode/block.number_forms (list)]))] - (_.coverage [/.octal] - (and (..should_pass (at n.octal encoded expected) /.octal) - (..should_fail (text.of_char invalid) /.octal)))) - (do [! random.monad] - [expected (at ! each (n.% 16) random.nat) - invalid (random.char (unicode.set [unicode/block.number_forms (list)]))] - (_.coverage [/.hexadecimal] - (and (..should_pass (at n.hex encoded expected) /.hexadecimal) - (..should_fail (text.of_char invalid) /.hexadecimal)))) - (do [! random.monad] - [expected (random.char unicode.alphabetic) - invalid (random.only (function (_ char) - (not (or (unicode/block.within? unicode/block.upper_case char) - (unicode/block.within? unicode/block.lower_case char)))) - (random.char unicode.character))] - (_.coverage [/.alpha] - (and (..should_pass (text.of_char expected) /.alpha) - (..should_fail (text.of_char invalid) /.alpha)))) - (do [! random.monad] - [expected (random.char unicode.alpha_numeric) - invalid (random.only (function (_ char) - (not (or (unicode/block.within? unicode/block.upper_case char) - (unicode/block.within? unicode/block.lower_case char) - (unicode/block.within? unicode/block.numeric char)))) - (random.char unicode.character))] - (_.coverage [/.alpha_num] - (and (..should_pass (text.of_char expected) /.alpha_num) - (..should_fail (text.of_char invalid) /.alpha_num)))) - (do [! random.monad] - [expected (all random.either - (in text.tab) - (in text.vertical_tab) - (in text.space) - (in text.new_line) - (in text.carriage_return) - (in text.form_feed)) - invalid (|> (random.unicode 1) (random.only (function (_ char) - (not (or (text#= text.tab char) - (text#= text.vertical_tab char) - (text#= text.space char) - (text#= text.new_line char) - (text#= text.carriage_return char) - (text#= text.form_feed char))))))] - (_.coverage [/.space] - (and (..should_pass expected /.space) - (..should_fail invalid /.space)))) - (do [! random.monad] - [.let [num_options 3] - options (|> (random.char unicode.character) - (random.set n.hash num_options) - (at ! each (|>> set.list - (list#each text.of_char) - text.together))) - expected (at ! each (function (_ value) - (|> options - (text.char (n.% num_options value)) - maybe.trusted)) - random.nat) - invalid (random.only (function (_ char) - (not (text.contains? (text.of_char char) options))) - (random.char unicode.character))] - (_.coverage [/.one_of /.one_of! /.character_should_be] - (and (..should_pass (text.of_char expected) (/.one_of options)) - (..should_fail (text.of_char invalid) (/.one_of options)) - (..should_fail' (text.of_char invalid) (/.one_of options) - /.character_should_be) - - (..should_pass! (text.of_char expected) (/.one_of! options)) - (..should_fail (text.of_char invalid) (/.one_of! options)) - (..should_fail' (text.of_char invalid) (/.one_of! options) - /.character_should_be) - ))) - (do [! random.monad] - [.let [num_options 3] - options (|> (random.char unicode.character) - (random.set n.hash num_options) - (at ! each (|>> set.list - (list#each text.of_char) - text.together))) - invalid (at ! each (function (_ value) - (|> options - (text.char (n.% num_options value)) - maybe.trusted)) - random.nat) - expected (random.only (function (_ char) - (not (text.contains? (text.of_char char) options))) - (random.char unicode.character))] - (_.coverage [/.none_of /.none_of! /.character_should_not_be] - (and (..should_pass (text.of_char expected) (/.none_of options)) - (..should_fail (text.of_char invalid) (/.none_of options)) - (..should_fail' (text.of_char invalid) (/.none_of options) - /.character_should_not_be) - - (..should_pass! (text.of_char expected) (/.none_of! options)) - (..should_fail (text.of_char invalid) (/.none_of! options)) - (..should_fail' (text.of_char invalid) (/.none_of! options) - /.character_should_not_be) - ))) - )) - -(def: runs - Test - (let [octal! (/.one_of! "01234567")] - (all _.and - (do [! random.monad] - [left (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) - right (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) - .let [expected (format left right)] - invalid (|> random.nat - (at ! each (n.% 16)) - (random.only (n.>= 8)) - (at ! each (at n.hex encoded)))] - (_.coverage [/.many /.many!] - (and (..should_pass expected (/.many /.octal)) - (..should_fail invalid (/.many /.octal)) - - (..should_pass! expected (/.many! octal!))))) - (do [! random.monad] - [left (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) - right (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) - .let [expected (format left right)] - invalid (|> random.nat - (at ! each (n.% 16)) - (random.only (n.>= 8)) - (at ! each (at n.hex encoded)))] - (_.coverage [/.some /.some!] - (and (..should_pass expected (/.some /.octal)) - (..should_pass "" (/.some /.octal)) - (..should_fail invalid (/.some /.octal)) - - (..should_pass! expected (/.some! octal!)) - (..should_pass! "" (/.some! octal!))))) - (do [! random.monad] - [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] - first octal - second octal - third octal] - (_.coverage [/.exactly /.exactly!] - (and (..should_pass (format first second) (/.exactly 2 /.octal)) - (..should_fail (format first second third) (/.exactly 2 /.octal)) - (..should_fail (format first) (/.exactly 2 /.octal)) - - (..should_pass! (format first second) (/.exactly! 2 octal!)) - (..should_fail (format first second third) (/.exactly! 2 octal!)) - (..should_fail (format first) (/.exactly! 2 octal!))))) - (do [! random.monad] - [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] - first octal - second octal - third octal] - (_.coverage [/.at_most /.at_most!] - (and (..should_pass (format first second) (/.at_most 2 /.octal)) - (..should_pass (format first) (/.at_most 2 /.octal)) - (..should_fail (format first second third) (/.at_most 2 /.octal)) - - (..should_pass! (format first second) (/.at_most! 2 octal!)) - (..should_pass! (format first) (/.at_most! 2 octal!)) - (..should_fail (format first second third) (/.at_most! 2 octal!))))) - (do [! random.monad] - [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] - first octal - second octal - third octal] - (_.coverage [/.at_least /.at_least!] - (and (..should_pass (format first second) (/.at_least 2 /.octal)) - (..should_pass (format first second third) (/.at_least 2 /.octal)) - (..should_fail (format first) (/.at_least 2 /.octal)) - - (..should_pass! (format first second) (/.at_least! 2 octal!)) - (..should_pass! (format first second third) (/.at_least! 2 octal!)) - (..should_fail (format first) (/.at_least! 2 octal!))))) - (do [! random.monad] - [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] - first octal - second octal - third octal] - (_.coverage [/.between /.between!] - (and (..should_pass (format first second) (/.between 2 1 /.octal)) - (..should_pass (format first second third) (/.between 2 1 /.octal)) - (..should_fail (format first) (/.between 2 1 /.octal)) - - (..should_pass! (format first second) (/.between! 2 1 octal!)) - (..should_pass! (format first second third) (/.between! 2 1 octal!)) - (..should_fail (format first) (/.between! 2 1 octal!))))) - ))) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.Parser]) - (all _.and - (do [! random.monad] - [sample (random.unicode 1)] - (_.coverage [/.result /.end] - (and (|> (/.result /.end - "") - (!expect {try.#Success _})) - (|> (/.result /.end - sample) - (!expect {try.#Failure _}))))) - (do [! random.monad] - [.let [size 10] - expected (random.unicode size) - dummy (|> (random.unicode size) - (random.only (|>> (text#= expected) not)))] - (_.coverage [/.this /.cannot_match] - (and (|> (/.result (/.this expected) - expected) - (!expect {try.#Success []})) - (|> (/.result (/.this expected) - dummy) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_match error))))))) - (_.coverage [/.Slice /.slice /.cannot_slice] - (|> "" - (/.result (/.slice /.any!)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_slice error))))) - (do [! random.monad] - [expected (random.unicode 1)] - (_.coverage [/.any /.any!] - (and (..should_pass expected /.any) - (..should_fail "" /.any) - - (..should_pass! expected /.any!) - (..should_fail "" /.any!)))) - (do [! random.monad] - [expected (random.unicode 1)] - (_.coverage [/.next /.cannot_parse] - (and (..should_pass expected (<>.before /.any /.next)) - (|> "" - (/.result (<>.before /.any /.next)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_parse error))))))) - (do [! random.monad] - [dummy (random.unicode 1)] - (_.coverage [/.unconsumed_input] - (|> (format dummy dummy) - (/.result /.any) - (!expect (^.multi {try.#Failure error} - (exception.match? /.unconsumed_input error)))))) - (do [! random.monad] - [sample (random.unicode 1)] - (_.coverage [/.Offset /.offset] - (|> sample - (/.result (do <>.monad - [pre /.offset - _ /.any - post /.offset] - (in [pre post]))) - (!expect {try.#Success [0 1]})))) - (do [! random.monad] - [left (random.unicode 1) - right (random.unicode 1) - .let [input (format left right)]] - (_.coverage [/.remaining] - (|> input - (/.result (do <>.monad - [pre /.remaining - _ /.any - post /.remaining - _ /.any] - (in (and (text#= input pre) - (text#= right post))))) - (!expect {try.#Success #1})))) - (do [! random.monad] - [left (random.unicode 1) - right (random.unicode 1) - expected (random.only (|>> (text#= right) not) - (random.unicode 1))] - (_.coverage [/.enclosed] - (|> (format left expected right) - (/.result (/.enclosed [left right] (/.this expected))) - (!expect {try.#Success _})))) - (do [! random.monad] - [input (random.unicode 1) - output (random.unicode 1)] - (_.coverage [/.local] - (|> output - (/.result (do <>.monad - [_ (/.local input (/.this input))] - (/.this output))) - (!expect {try.#Success _})))) - (do [! random.monad] - [expected (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] - (_.coverage [/.then] - (|> (list (code.text expected)) - (<c>.result (/.then /.octal <c>.text)) - (!expect (^.multi {try.#Success actual} - (text#= expected actual)))))) - (do [! random.monad] - [invalid (random.upper_case 1) - expected (random.only (|>> (unicode/block.within? unicode/block.upper_case) - not) - (random.char unicode.character)) - .let [upper! (/.one_of! "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]] - (_.coverage [/.not /.not! /.expected_to_fail] - (and (..should_pass (text.of_char expected) (/.not /.upper)) - (|> invalid - (/.result (/.not /.upper)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.expected_to_fail error)))) - - (..should_pass! (text.of_char expected) (/.not! upper!)) - (|> invalid - (/.result (/.not! upper!)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.expected_to_fail error))))))) - (do [! random.monad] - [upper (random.upper_case 1) - lower (random.lower_case 1) - invalid (random.only (function (_ char) - (not (or (unicode/block.within? unicode/block.upper_case char) - (unicode/block.within? unicode/block.lower_case char)))) - (random.char unicode.character)) - .let [upper! (/.one_of! "ABCDEFGHIJKLMNOPQRSTUVWXYZ") - lower! (/.one_of! "abcdefghijklmnopqrstuvwxyz")]] - (_.coverage [/.and /.and!] - (and (..should_pass (format upper lower) (/.and /.upper /.lower)) - (..should_fail (format (text.of_char invalid) lower) (/.and /.upper /.lower)) - (..should_fail (format upper (text.of_char invalid)) (/.and /.upper /.lower)) - - (..should_pass! (format upper lower) (/.and! upper! lower!)) - (..should_fail (format (text.of_char invalid) lower) (/.and! upper! lower!)) - (..should_fail (format upper (text.of_char invalid)) (/.and! upper! lower!))))) - (do [! random.monad] - [expected (random.unicode 1) - invalid (random.unicode 1)] - (_.coverage [/.satisfies /.character_does_not_satisfy_predicate] - (and (..should_pass expected (/.satisfies (function.constant true))) - (..should_fail' invalid (/.satisfies (function.constant false)) - /.character_does_not_satisfy_predicate)))) - ..character_classes - ..runs - ))) diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index 394c9f1c1..d96c0a92c 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -1,23 +1,31 @@ (.using [library - [lux (.except) + [lux (.except Variant Record) ["_" test (.only Test)] + ["@" target] + ["[0]" debug] ["[0]" meta] [abstract + [codec (.except)] [monad (.only do)] + ["[0]" equivalence (.only Equivalence) + ["[0]/[1]" \\polytypic]] [\\specification ["$[0]" equivalence] ["$[0]" codec]]] [control - ["[0]" try (.open: "[1]#[0]" functor)]] + ["[0]" try (.open: "[1]#[0]" functor)] + ["p" parser + ... TODO: Get rid of this import ASAP + [json (.only)]]] [data ["[0]" product] ["[0]" bit] ["[0]" text (.only) ["%" format (.only format)]] [collection - ["[0]" sequence] - ["[0]" dictionary] + ["[0]" sequence (.only sequence)] + ["[0]" dictionary (.only Dictionary)] ["[0]" set] ["[0]" list (.open: "[1]#[0]" functor)]]] [math @@ -27,10 +35,96 @@ ["[0]" frac]]] ["[0]" macro (.only) ["[0]" syntax (.only syntax)] - ["[0]" code]]]] + ["[0]" code]] + [time + ["[0]" date] + ["[0]" instant + ["[0]/[1]" \\test]] + ["[0]" duration + ["[0]/[1]" \\test]] + ] + [type + ["[0]" unit]]]] + ["[0]" \\polytypic] [\\library ["[0]" / (.only JSON) (.open: "[1]#[0]" equivalence)]]) +(type: Variant + (.Variant + {#Bit Bit} + {#Text Text} + {#Frac Frac})) + +(type: Recursive + (Rec Recursive + (.Variant + {#Number Frac} + {#Addition Frac Recursive}))) + +(type: Record + (.Record + [#bit Bit + #frac Frac + #text Text + #maybe (Maybe Frac) + #list (List Frac) + #dictionary (Dictionary Text Frac) + #variant Variant + #tuple [Bit Text Frac] + #recursive Recursive + ... #instant instant.Instant + ... #duration duration.Duration + #date date.Date + #grams (unit.Qty unit.Gram)])) + +(def: gen_recursive + (Random Recursive) + (random.rec + (function (_ gen_recursive) + (random.or random.safe_frac + (random.and random.safe_frac + gen_recursive))))) + +(def: qty + (All (_ unit) (Random (unit.Qty unit))) + (at random.monad each (debug.private unit.in') random.int)) + +(def: gen_record + (Random Record) + (do [! random.monad] + [size (at ! each (n.% 2) random.nat)] + (all random.and + random.bit + random.safe_frac + (random.unicode size) + (random.maybe random.safe_frac) + (random.list size random.safe_frac) + (random.dictionary text.hash size (random.unicode size) random.safe_frac) + (all random.or random.bit (random.unicode size) random.safe_frac) + (all random.and random.bit (random.unicode size) random.safe_frac) + ..gen_recursive + ... \\test/instant.instant + ... \\test/duration.duration + random.date + ..qty + ))) + +(for @.old (these) + (these (def: equivalence + (Equivalence Record) + (\\polytypic/equivalence.equivalence Record)) + + (def: codec + (Codec JSON Record) + (\\polytypic.codec Record)))) + +(def: \\polytypic + Test + (<| (_.covering \\polytypic._) + (_.for [\\polytypic.codec] + (for @.old (_.property "PLACEHOLDER" true) + ($codec.spec ..equivalence ..codec ..gen_record))))) + (def: .public random (Random /.JSON) (random.rec @@ -199,4 +293,6 @@ (/#= {/.#Array <array_sequence>} value4) (/#= {/.#Number <number>} value6)))))) ))) + + ..\\polytypic )))) diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux index ebda04668..e283b6081 100644 --- a/stdlib/source/test/lux/data/text.lux +++ b/stdlib/source/test/lux/data/text.lux @@ -11,14 +11,29 @@ ["$[0]" monoid]]] [control ["[0]" pipe] - ["[0]" maybe]] + ["[0]" maybe] + ["[0]" try (.only Try)] + ["[0]" exception (.only Exception)] + ["[0]" function] + ["<>" parser (.only) + ["<c>" code]]] [data [collection - ["[0]" list] - ["[0]" set]]] + ["[0]" set] + ["[0]" list (.open: "[1]#[0]" functor)] + [tree + ["[0]" finger]]] + [text + ["%" format (.only format)] + ["[0]" unicode + ["[1]" set] + ["[1]/[0]" block]]]] + [macro + ["^" pattern] + ["[0]" code]] [math ["[0]" random] - [number + [number (.only hex) ["n" nat]]]]] ["[0]" / ["[1][0]" buffer] @@ -29,7 +44,420 @@ ["[1][0]" unicode ["[1]" set]]] [\\library - ["[0]" /]]) + ["[0]" / (.open: "[1]#[0]" equivalence)]] + ["[0]" \\parser]) + +(def: !expect + (template (_ <pattern> <value>) + [(case <value> + <pattern> + true + + _ + false)])) + +(def: (should_fail' sample parser exception) + (All (_ a e) (-> Text (\\parser.Parser a) (Exception e) Bit)) + (case (\\parser.result parser sample) + {try.#Failure error} + (exception.match? exception error) + + _ + false)) + +(def: (should_fail sample parser) + (All (_ a) (-> Text (\\parser.Parser a) Bit)) + (case (\\parser.result parser sample) + {try.#Failure _} + true + + _ + false)) + +(def: (should_pass expected parser) + (-> Text (\\parser.Parser Text) Bit) + (|> expected + (\\parser.result parser) + (at try.functor each (/#= expected)) + (try.else false))) + +(def: (should_pass! expected parser) + (-> Text (\\parser.Parser \\parser.Slice) Bit) + (..should_pass expected (\\parser.slice parser))) + +(def: \\parser#character_classes + Test + (all _.and + (do [! random.monad] + [offset (at ! each (n.% 50) random.nat) + range (at ! each (|>> (n.% 50) (n.+ 10)) random.nat) + .let [limit (n.+ offset range)] + expected (at ! each (|>> (n.% range) (n.+ offset) /.of_char) random.nat) + out_of_range (case offset + 0 (at ! each (|>> (n.% 10) ++ (n.+ limit) /.of_char) random.nat) + _ (at ! each (|>> (n.% offset) /.of_char) random.nat))] + (_.coverage [\\parser.range] + (and (..should_pass expected (\\parser.range offset limit)) + (..should_fail out_of_range (\\parser.range offset limit))))) + (do [! random.monad] + [expected (random.char unicode.upper_case) + invalid (random.only (|>> (unicode/block.within? unicode/block.upper_case) not) + (random.char unicode.character))] + (_.coverage [\\parser.upper] + (and (..should_pass (/.of_char expected) \\parser.upper) + (..should_fail (/.of_char invalid) \\parser.upper)))) + (do [! random.monad] + [expected (random.char unicode.lower_case) + invalid (random.only (|>> (unicode/block.within? unicode/block.lower_case) not) + (random.char unicode.character))] + (_.coverage [\\parser.lower] + (and (..should_pass (/.of_char expected) \\parser.lower) + (..should_fail (/.of_char invalid) \\parser.lower)))) + (do [! random.monad] + [expected (at ! each (n.% 10) random.nat) + invalid (random.char (unicode.set [unicode/block.number_forms (list)]))] + (_.coverage [\\parser.decimal] + (and (..should_pass (at n.decimal encoded expected) \\parser.decimal) + (..should_fail (/.of_char invalid) \\parser.decimal)))) + (do [! random.monad] + [expected (at ! each (n.% 8) random.nat) + invalid (random.char (unicode.set [unicode/block.number_forms (list)]))] + (_.coverage [\\parser.octal] + (and (..should_pass (at n.octal encoded expected) \\parser.octal) + (..should_fail (/.of_char invalid) \\parser.octal)))) + (do [! random.monad] + [expected (at ! each (n.% 16) random.nat) + invalid (random.char (unicode.set [unicode/block.number_forms (list)]))] + (_.coverage [\\parser.hexadecimal] + (and (..should_pass (at n.hex encoded expected) \\parser.hexadecimal) + (..should_fail (/.of_char invalid) \\parser.hexadecimal)))) + (do [! random.monad] + [expected (random.char unicode.alphabetic) + invalid (random.only (function (_ char) + (not (or (unicode/block.within? unicode/block.upper_case char) + (unicode/block.within? unicode/block.lower_case char)))) + (random.char unicode.character))] + (_.coverage [\\parser.alpha] + (and (..should_pass (/.of_char expected) \\parser.alpha) + (..should_fail (/.of_char invalid) \\parser.alpha)))) + (do [! random.monad] + [expected (random.char unicode.alpha_numeric) + invalid (random.only (function (_ char) + (not (or (unicode/block.within? unicode/block.upper_case char) + (unicode/block.within? unicode/block.lower_case char) + (unicode/block.within? unicode/block.numeric char)))) + (random.char unicode.character))] + (_.coverage [\\parser.alpha_num] + (and (..should_pass (/.of_char expected) \\parser.alpha_num) + (..should_fail (/.of_char invalid) \\parser.alpha_num)))) + (do [! random.monad] + [expected (all random.either + (in /.tab) + (in /.vertical_tab) + (in /.space) + (in /.new_line) + (in /.carriage_return) + (in /.form_feed)) + invalid (|> (random.unicode 1) (random.only (function (_ char) + (not (or (/#= /.tab char) + (/#= /.vertical_tab char) + (/#= /.space char) + (/#= /.new_line char) + (/#= /.carriage_return char) + (/#= /.form_feed char))))))] + (_.coverage [\\parser.space] + (and (..should_pass expected \\parser.space) + (..should_fail invalid \\parser.space)))) + (do [! random.monad] + [.let [num_options 3] + options (|> (random.char unicode.character) + (random.set n.hash num_options) + (at ! each (|>> set.list + (list#each /.of_char) + /.together))) + expected (at ! each (function (_ value) + (|> options + (/.char (n.% num_options value)) + maybe.trusted)) + random.nat) + invalid (random.only (function (_ char) + (not (/.contains? (/.of_char char) options))) + (random.char unicode.character))] + (_.coverage [\\parser.one_of \\parser.one_of! \\parser.character_should_be] + (and (..should_pass (/.of_char expected) (\\parser.one_of options)) + (..should_fail (/.of_char invalid) (\\parser.one_of options)) + (..should_fail' (/.of_char invalid) (\\parser.one_of options) + \\parser.character_should_be) + + (..should_pass! (/.of_char expected) (\\parser.one_of! options)) + (..should_fail (/.of_char invalid) (\\parser.one_of! options)) + (..should_fail' (/.of_char invalid) (\\parser.one_of! options) + \\parser.character_should_be) + ))) + (do [! random.monad] + [.let [num_options 3] + options (|> (random.char unicode.character) + (random.set n.hash num_options) + (at ! each (|>> set.list + (list#each /.of_char) + /.together))) + invalid (at ! each (function (_ value) + (|> options + (/.char (n.% num_options value)) + maybe.trusted)) + random.nat) + expected (random.only (function (_ char) + (not (/.contains? (/.of_char char) options))) + (random.char unicode.character))] + (_.coverage [\\parser.none_of \\parser.none_of! \\parser.character_should_not_be] + (and (..should_pass (/.of_char expected) (\\parser.none_of options)) + (..should_fail (/.of_char invalid) (\\parser.none_of options)) + (..should_fail' (/.of_char invalid) (\\parser.none_of options) + \\parser.character_should_not_be) + + (..should_pass! (/.of_char expected) (\\parser.none_of! options)) + (..should_fail (/.of_char invalid) (\\parser.none_of! options)) + (..should_fail' (/.of_char invalid) (\\parser.none_of! options) + \\parser.character_should_not_be) + ))) + )) + +(def: \\parser#runs + Test + (let [octal! (\\parser.one_of! "01234567")] + (all _.and + (do [! random.monad] + [left (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) + right (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) + .let [expected (format left right)] + invalid (|> random.nat + (at ! each (n.% 16)) + (random.only (n.>= 8)) + (at ! each (at n.hex encoded)))] + (_.coverage [\\parser.many \\parser.many!] + (and (..should_pass expected (\\parser.many \\parser.octal)) + (..should_fail invalid (\\parser.many \\parser.octal)) + + (..should_pass! expected (\\parser.many! octal!))))) + (do [! random.monad] + [left (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) + right (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat) + .let [expected (format left right)] + invalid (|> random.nat + (at ! each (n.% 16)) + (random.only (n.>= 8)) + (at ! each (at n.hex encoded)))] + (_.coverage [\\parser.some \\parser.some!] + (and (..should_pass expected (\\parser.some \\parser.octal)) + (..should_pass "" (\\parser.some \\parser.octal)) + (..should_fail invalid (\\parser.some \\parser.octal)) + + (..should_pass! expected (\\parser.some! octal!)) + (..should_pass! "" (\\parser.some! octal!))))) + (do [! random.monad] + [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] + first octal + second octal + third octal] + (_.coverage [\\parser.exactly \\parser.exactly!] + (and (..should_pass (format first second) (\\parser.exactly 2 \\parser.octal)) + (..should_fail (format first second third) (\\parser.exactly 2 \\parser.octal)) + (..should_fail (format first) (\\parser.exactly 2 \\parser.octal)) + + (..should_pass! (format first second) (\\parser.exactly! 2 octal!)) + (..should_fail (format first second third) (\\parser.exactly! 2 octal!)) + (..should_fail (format first) (\\parser.exactly! 2 octal!))))) + (do [! random.monad] + [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] + first octal + second octal + third octal] + (_.coverage [\\parser.at_most \\parser.at_most!] + (and (..should_pass (format first second) (\\parser.at_most 2 \\parser.octal)) + (..should_pass (format first) (\\parser.at_most 2 \\parser.octal)) + (..should_fail (format first second third) (\\parser.at_most 2 \\parser.octal)) + + (..should_pass! (format first second) (\\parser.at_most! 2 octal!)) + (..should_pass! (format first) (\\parser.at_most! 2 octal!)) + (..should_fail (format first second third) (\\parser.at_most! 2 octal!))))) + (do [! random.monad] + [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] + first octal + second octal + third octal] + (_.coverage [\\parser.at_least \\parser.at_least!] + (and (..should_pass (format first second) (\\parser.at_least 2 \\parser.octal)) + (..should_pass (format first second third) (\\parser.at_least 2 \\parser.octal)) + (..should_fail (format first) (\\parser.at_least 2 \\parser.octal)) + + (..should_pass! (format first second) (\\parser.at_least! 2 octal!)) + (..should_pass! (format first second third) (\\parser.at_least! 2 octal!)) + (..should_fail (format first) (\\parser.at_least! 2 octal!))))) + (do [! random.monad] + [.let [octal (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] + first octal + second octal + third octal] + (_.coverage [\\parser.between \\parser.between!] + (and (..should_pass (format first second) (\\parser.between 2 1 \\parser.octal)) + (..should_pass (format first second third) (\\parser.between 2 1 \\parser.octal)) + (..should_fail (format first) (\\parser.between 2 1 \\parser.octal)) + + (..should_pass! (format first second) (\\parser.between! 2 1 octal!)) + (..should_pass! (format first second third) (\\parser.between! 2 1 octal!)) + (..should_fail (format first) (\\parser.between! 2 1 octal!))))) + ))) + +(def: \\parser + Test + (<| (_.covering \\parser._) + (_.for [\\parser.Parser]) + (all _.and + (do [! random.monad] + [sample (random.unicode 1)] + (_.coverage [\\parser.result \\parser.end] + (and (|> (\\parser.result \\parser.end + "") + (!expect {try.#Success _})) + (|> (\\parser.result \\parser.end + sample) + (!expect {try.#Failure _}))))) + (do [! random.monad] + [.let [size 10] + expected (random.unicode size) + dummy (|> (random.unicode size) + (random.only (|>> (/#= expected) not)))] + (_.coverage [\\parser.this \\parser.cannot_match] + (and (|> (\\parser.result (\\parser.this expected) + expected) + (!expect {try.#Success []})) + (|> (\\parser.result (\\parser.this expected) + dummy) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_match error))))))) + (_.coverage [\\parser.Slice \\parser.slice \\parser.cannot_slice] + (|> "" + (\\parser.result (\\parser.slice \\parser.any!)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_slice error))))) + (do [! random.monad] + [expected (random.unicode 1)] + (_.coverage [\\parser.any \\parser.any!] + (and (..should_pass expected \\parser.any) + (..should_fail "" \\parser.any) + + (..should_pass! expected \\parser.any!) + (..should_fail "" \\parser.any!)))) + (do [! random.monad] + [expected (random.unicode 1)] + (_.coverage [\\parser.next \\parser.cannot_parse] + (and (..should_pass expected (<>.before \\parser.any \\parser.next)) + (|> "" + (\\parser.result (<>.before \\parser.any \\parser.next)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_parse error))))))) + (do [! random.monad] + [dummy (random.unicode 1)] + (_.coverage [\\parser.unconsumed_input] + (|> (format dummy dummy) + (\\parser.result \\parser.any) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.unconsumed_input error)))))) + (do [! random.monad] + [sample (random.unicode 1)] + (_.coverage [\\parser.Offset \\parser.offset] + (|> sample + (\\parser.result (do <>.monad + [pre \\parser.offset + _ \\parser.any + post \\parser.offset] + (in [pre post]))) + (!expect {try.#Success [0 1]})))) + (do [! random.monad] + [left (random.unicode 1) + right (random.unicode 1) + .let [input (format left right)]] + (_.coverage [\\parser.remaining] + (|> input + (\\parser.result (do <>.monad + [pre \\parser.remaining + _ \\parser.any + post \\parser.remaining + _ \\parser.any] + (in (and (/#= input pre) + (/#= right post))))) + (!expect {try.#Success #1})))) + (do [! random.monad] + [left (random.unicode 1) + right (random.unicode 1) + expected (random.only (|>> (/#= right) not) + (random.unicode 1))] + (_.coverage [\\parser.enclosed] + (|> (format left expected right) + (\\parser.result (\\parser.enclosed [left right] (\\parser.this expected))) + (!expect {try.#Success _})))) + (do [! random.monad] + [input (random.unicode 1) + output (random.unicode 1)] + (_.coverage [\\parser.local] + (|> output + (\\parser.result (do <>.monad + [_ (\\parser.local input (\\parser.this input))] + (\\parser.this output))) + (!expect {try.#Success _})))) + (do [! random.monad] + [expected (at ! each (|>> (n.% 8) (at n.octal encoded)) random.nat)] + (_.coverage [\\parser.then] + (|> (list (code.text expected)) + (<c>.result (\\parser.then \\parser.octal <c>.text)) + (!expect (^.multi {try.#Success actual} + (/#= expected actual)))))) + (do [! random.monad] + [invalid (random.upper_case 1) + expected (random.only (|>> (unicode/block.within? unicode/block.upper_case) + not) + (random.char unicode.character)) + .let [upper! (\\parser.one_of! "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]] + (_.coverage [\\parser.not \\parser.not! \\parser.expected_to_fail] + (and (..should_pass (/.of_char expected) (\\parser.not \\parser.upper)) + (|> invalid + (\\parser.result (\\parser.not \\parser.upper)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.expected_to_fail error)))) + + (..should_pass! (/.of_char expected) (\\parser.not! upper!)) + (|> invalid + (\\parser.result (\\parser.not! upper!)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.expected_to_fail error))))))) + (do [! random.monad] + [upper (random.upper_case 1) + lower (random.lower_case 1) + invalid (random.only (function (_ char) + (not (or (unicode/block.within? unicode/block.upper_case char) + (unicode/block.within? unicode/block.lower_case char)))) + (random.char unicode.character)) + .let [upper! (\\parser.one_of! "ABCDEFGHIJKLMNOPQRSTUVWXYZ") + lower! (\\parser.one_of! "abcdefghijklmnopqrstuvwxyz")]] + (_.coverage [\\parser.and \\parser.and!] + (and (..should_pass (format upper lower) (\\parser.and \\parser.upper \\parser.lower)) + (..should_fail (format (/.of_char invalid) lower) (\\parser.and \\parser.upper \\parser.lower)) + (..should_fail (format upper (/.of_char invalid)) (\\parser.and \\parser.upper \\parser.lower)) + + (..should_pass! (format upper lower) (\\parser.and! upper! lower!)) + (..should_fail (format (/.of_char invalid) lower) (\\parser.and! upper! lower!)) + (..should_fail (format upper (/.of_char invalid)) (\\parser.and! upper! lower!))))) + (do [! random.monad] + [expected (random.unicode 1) + invalid (random.unicode 1)] + (_.coverage [\\parser.satisfies \\parser.character_does_not_satisfy_predicate] + (and (..should_pass expected (\\parser.satisfies (function.constant true))) + (..should_fail' invalid (\\parser.satisfies (function.constant false)) + \\parser.character_does_not_satisfy_predicate)))) + + \\parser#character_classes + \\parser#runs + ))) (def: bounded_size (random.Random Nat) @@ -337,4 +765,6 @@ /regex.test /escape.test /unicode.test + + ..\\parser ))) diff --git a/stdlib/source/test/lux/data/text/regex.lux b/stdlib/source/test/lux/data/text/regex.lux index 43a34d694..0f419d22a 100644 --- a/stdlib/source/test/lux/data/text/regex.lux +++ b/stdlib/source/test/lux/data/text/regex.lux @@ -8,11 +8,11 @@ ["[0]" pipe] ["[0]" try] [parser - ["<[0]>" text (.only Parser)] ["<[0]>" code]]] [data ["[0]" text (.open: "[1]#[0]" equivalence) - ["%" format (.only format)]]] + ["%" format (.only format)] + ["<[1]>" \\parser (.only Parser)]]] ["[0]" macro (.only) [syntax (.only syntax)] ["[0]" code]] diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux index 0716e76d1..dd2835166 100644 --- a/stdlib/source/test/lux/extension.lux +++ b/stdlib/source/test/lux/extension.lux @@ -22,7 +22,6 @@ ["[0]" try (.open: "[1]#[0]" functor)] ["<>" parser (.only) ["<[0]>" code] - ["<[0]>" analysis] ["<[0]>" synthesis]]] [data ["[0]" binary] @@ -52,7 +51,8 @@ ["[0]" generation] ["[0]" directive] ["[0]" analysis (.only) - ["[0]" type]] + ["[0]" type] + ["<[1]>" \\parser]] [phase [generation (~~ (.for "JVM" (~~ (.these ["[0]" jvm diff --git a/stdlib/source/test/lux/meta/configuration.lux b/stdlib/source/test/lux/meta/configuration.lux index 45dcc5e5d..f456630a0 100644 --- a/stdlib/source/test/lux/meta/configuration.lux +++ b/stdlib/source/test/lux/meta/configuration.lux @@ -12,10 +12,10 @@ ["[0]" try (.open: "[1]#[0]" functor)] ["[0]" exception] ["<>" parser (.only) - ["<[0]>" text] ["<[0]>" code]]] [data - ["[0]" text] + ["[0]" text (.only) + ["<[1]>" \\parser]] [collection ["[0]" list]]] ["[0]" macro (.only) diff --git a/stdlib/source/test/lux/time.lux b/stdlib/source/test/lux/time.lux index a054a8990..4cb18d5df 100644 --- a/stdlib/source/test/lux/time.lux +++ b/stdlib/source/test/lux/time.lux @@ -12,12 +12,11 @@ [control ["[0]" pipe] ["[0]" try (.open: "[1]#[0]" functor)] - ["[0]" exception] - [parser - ["<[0]>" text]]] + ["[0]" exception]] [data ["[0]" text (.only) - ["%" format (.only format)]]] + ["%" format (.only format)] + ["<[1]>" \\parser]]] [math ["[0]" random] [number diff --git a/stdlib/source/test/lux/time/date.lux b/stdlib/source/test/lux/time/date.lux index beaae5d9d..a95e4c10f 100644 --- a/stdlib/source/test/lux/time/date.lux +++ b/stdlib/source/test/lux/time/date.lux @@ -11,12 +11,11 @@ ["$[0]" codec]]] [control ["[0]" try (.open: "[1]#[0]" functor)] - ["[0]" exception] - [parser - ["<[0]>" text]]] + ["[0]" exception]] [data - [text - ["%" format (.only format)]]] + ["[0]" text + ["%" format (.only format)] + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random)] [number diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux index 407833523..763b3ba9f 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux @@ -8,11 +8,12 @@ [\\specification ["$[0]" equivalence]]] [control + ["<>" parser] ["[0]" pipe] - ["[0]" function] - ["[0]" maybe] ["[0]" try] - ["[0]" exception (.only exception:)]] + ["[0]" exception (.only exception:)] + ["[0]" function] + ["[0]" maybe]] [data ["[0]" bit (.open: "[1]#[0]" equivalence)] ["[0]" text (.open: "[1]#[0]" equivalence)] @@ -23,10 +24,27 @@ [math ["[0]" random (.only Random) (.open: "[1]#[0]" monad)] [number - ["f" frac]]] + ["n" nat] + ["i" int] + ["f" frac] + ["r" rev]]] [meta + ["[0]" symbol (.open: "[1]#[0]" equivalence)] ["[0]" configuration - ["$[1]" \\test]]]]] + ["$[1]" \\test]]] + [tool + [compiler + [reference (.only Constant) + [variable (.only)]]]]]] + ["[0]" \\parser] + [\\library + ["[0]" / (.only) + [// + [phase + ["[0]" extension]] + [/// + ["[0]" phase] + ["[0]" version]]]]] ["[0]" / ["[1][0]" complex] ["[1][0]" inference] @@ -45,15 +63,129 @@ ["[1][0]" symbol] ["[0]" location ["[2][1]" /] - ["[1]" \\library (.open: "[1]#[0]" equivalence)]]]]]] - [\\library - ["[0]" / (.only) - [// - [phase - ["[0]" extension]] - [/// - ["[0]" phase] - ["[0]" version]]]]]) + ["[1]" \\library (.open: "[1]#[0]" equivalence)]]]]]]) + +(def: !expect + (template (_ <expectation> <computation>) + [(case <computation> + <expectation> + true + + _ + false)])) + +(def: constant + (Random Constant) + (random.and (random.unicode 10) + (random.unicode 10))) + +(def: \\parser + Test + (<| (_.covering \\parser._) + (_.for [\\parser.Parser]) + (do [! random.monad] + [] + (`` (all _.and + (do [! random.monad] + [expected (at ! each (|>> /.bit) random.bit)] + (_.coverage [\\parser.result \\parser.any] + (|> (list expected) + (\\parser.result \\parser.any) + (pipe.case + {try.#Success actual} + (at /.equivalence = expected actual) + + {try.#Failure _} + false)))) + (~~ (with_template [<query> <check> <random> <analysis> <=>] + [(do [! random.monad] + [expected <random>] + (_.coverage [<query>] + (|> (list (<analysis> expected)) + (\\parser.result <query>) + (pipe.case + {try.#Success actual} + (<=> expected actual) + + {try.#Failure _} + false)))) + (do [! random.monad] + [expected <random>] + (_.coverage [<check>] + (|> (list (<analysis> expected)) + (\\parser.result (<check> expected)) + (!expect {try.#Success _}))))] + + [\\parser.bit \\parser.this_bit random.bit /.bit bit#=] + [\\parser.nat \\parser.this_nat random.nat /.nat n.=] + [\\parser.int \\parser.this_int random.int /.int i.=] + [\\parser.frac \\parser.this_frac random.safe_frac /.frac f.=] + [\\parser.rev \\parser.this_rev random.rev /.rev r.=] + [\\parser.text \\parser.this_text (random.unicode 10) /.text text#=] + [\\parser.local \\parser.this_local random.nat /.local n.=] + [\\parser.foreign \\parser.this_foreign random.nat /.foreign n.=] + [\\parser.constant \\parser.this_constant ..constant /.constant symbol#=] + )) + (do [! random.monad] + [expected random.bit] + (_.coverage [\\parser.tuple] + (|> (list (/.tuple (list (/.bit expected)))) + (\\parser.result (\\parser.tuple \\parser.bit)) + (pipe.case + {try.#Success actual} + (bit#= expected actual) + + {try.#Failure _} + false)))) + (do [! random.monad] + [dummy random.bit] + (_.coverage [\\parser.end?] + (and (|> (\\parser.result \\parser.end? (list)) + (!expect {try.#Success #1})) + (|> (\\parser.result (do <>.monad + [verdict \\parser.end? + _ \\parser.bit] + (in verdict)) + (list (/.bit dummy))) + (!expect {try.#Success #0}))))) + (do [! random.monad] + [dummy random.bit] + (_.coverage [\\parser.end] + (and (|> (\\parser.result \\parser.end (list)) + (!expect {try.#Success _})) + (|> (\\parser.result \\parser.end (list (/.bit dummy))) + (!expect {try.#Failure _}))))) + (do [! random.monad] + [expected random.bit] + (_.coverage [\\parser.cannot_parse] + (and (|> (list (/.bit expected)) + (\\parser.result \\parser.nat) + (pipe.case + {try.#Success _} + false + + {try.#Failure error} + (exception.match? \\parser.cannot_parse error))) + (|> (list) + (\\parser.result \\parser.bit) + (pipe.case + {try.#Success _} + false + + {try.#Failure error} + (exception.match? \\parser.cannot_parse error)))))) + (do [! random.monad] + [expected random.bit] + (_.coverage [\\parser.unconsumed_input] + (|> (list (/.bit expected) (/.bit expected)) + (\\parser.result \\parser.bit) + (pipe.case + {try.#Success _} + false + + {try.#Failure error} + (exception.match? \\parser.unconsumed_input error))))) + ))))) (def: (random_branch random) (All (_ a) (-> (Random a) (Random (/.Branch' a)))) @@ -491,4 +623,6 @@ /simple.test /type.test /coverage.test + + ..\\parser )))) diff --git a/stdlib/source/test/lux/tool/compiler/meta/cli/compiler.lux b/stdlib/source/test/lux/tool/compiler/meta/cli/compiler.lux index 1a7aacc6d..b66061811 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/cli/compiler.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/cli/compiler.lux @@ -7,9 +7,10 @@ [\\specification ["$[0]" equivalence]]] [control - ["[0]" try (.open: "[1]#[0]" functor)] - ["<>" parser - ["<[0]>" text]]] + ["[0]" try (.open: "[1]#[0]" functor)]] + [data + ["[0]" text + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random)] [number diff --git a/stdlib/source/test/lux/type.lux b/stdlib/source/test/lux/type.lux index 299da6fc7..f14d09760 100644 --- a/stdlib/source/test/lux/type.lux +++ b/stdlib/source/test/lux/type.lux @@ -29,7 +29,6 @@ ["[1][0]" check] ["[1][0]" dynamic] ["[1][0]" implicit] - ["[1][0]" poly] ["[1][0]" quotient] ["[1][0]" refinement] ["[1][0]" resource] @@ -256,7 +255,6 @@ /check.test /dynamic.test /implicit.test - /poly.test /quotient.test /refinement.test /resource.test diff --git a/stdlib/source/test/lux/type/poly.lux b/stdlib/source/test/lux/type/poly.lux deleted file mode 100644 index 10c3bbbf6..000000000 --- a/stdlib/source/test/lux/type/poly.lux +++ /dev/null @@ -1,20 +0,0 @@ -(.using - [library - [lux (.except) - ["_" test (.only Test)]]] - [\\library - ["[0]" /]] - ["[0]" / - ["[1][0]" equivalence] - ["[1][0]" functor] - ["[1][0]" json]]) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.poly: /.code]) - (all _.and - /equivalence.test - /functor.test - /json.test - ))) diff --git a/stdlib/source/test/lux/type/poly/equivalence.lux b/stdlib/source/test/lux/type/poly/equivalence.lux deleted file mode 100644 index 9f353f55a..000000000 --- a/stdlib/source/test/lux/type/poly/equivalence.lux +++ /dev/null @@ -1,89 +0,0 @@ -(.using - [library - [lux (.except Variant Record) - ["_" test (.only Test)] - ["@" target] - [abstract - [monad (.only do)] - [equivalence (.only Equivalence) - [\\poly - ["[0]" /]]] - [\\specification - ["$[0]" equivalence]]] - [control - ["[0]" maybe]] - [data - ["[0]" bit] - ["[0]" text] - [collection - ["[0]" list]]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["i" int]]]]]) - -(type: Variant - (.Variant - {#Case0 Bit} - {#Case1 Int} - {#Case2 Frac})) - -(type: Recursive - (Rec Recursive - (.Variant - {#Number Frac} - {#Addition Frac Recursive}))) - -(type: Record - (.Record - [#bit Bit - #int Int - #frac Frac - #text Text - #maybe (Maybe Int) - #list (List Int) - #variant Variant - #tuple [Int Frac Text] - #recursive Recursive])) - -(def: gen_recursive - (Random Recursive) - (random.rec (function (_ gen_recursive) - (random.or random.safe_frac - (random.and random.safe_frac - gen_recursive))))) - -(def: random - (Random Record) - (do [! random.monad] - [size (at ! each (n.% 2) random.nat) - .let [gen_int (|> random.int (at ! each (|>> i.abs (i.% +1,000,000))))]] - (all random.and - random.bit - gen_int - random.safe_frac - (random.unicode size) - (random.maybe gen_int) - (random.list size gen_int) - (all random.or - random.bit - gen_int - random.safe_frac) - (all random.and - gen_int - random.safe_frac - (random.unicode size)) - gen_recursive))) - -(for @.old (these) - (these (def: equivalence - (Equivalence ..Record) - (/.equivalence ..Record)))) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.equivalence] - (for @.old (_.property "PLACEHOLDER" true) - ($equivalence.spec ..equivalence ..random))))) diff --git a/stdlib/source/test/lux/type/poly/functor.lux b/stdlib/source/test/lux/type/poly/functor.lux deleted file mode 100644 index 35daa7eff..000000000 --- a/stdlib/source/test/lux/type/poly/functor.lux +++ /dev/null @@ -1,38 +0,0 @@ -(.using - [library - [lux (.except) - ["@" target] - [abstract - [monad (.only do)] - [functor (.only Functor) - [\\poly - ["[0]" /]]]] - ["r" math/random (.only Random)] - ["_" test (.only Test)] - [control - ["[0]" state]] - [data - ["[0]" identity]]]]) - -(for @.old (these) - (these (def: maybe_functor - (Functor .Maybe) - (/.functor .Maybe)) - - (def: list_functor - (Functor .List) - (/.functor .List)) - - (def: state_functor - (All (_ s) (Functor (state.State s))) - (/.functor state.State)) - - (def: identity_functor - (Functor identity.Identity) - (/.functor identity.Identity)))) - -(def: .public test - Test - (<| (_.covering /._) - (_.coverage [/.functor] - true))) diff --git a/stdlib/source/test/lux/type/poly/json.lux b/stdlib/source/test/lux/type/poly/json.lux deleted file mode 100644 index 3ec8050a6..000000000 --- a/stdlib/source/test/lux/type/poly/json.lux +++ /dev/null @@ -1,124 +0,0 @@ -(.using - [library - [lux (.except Variant Record) - ["_" test (.only Test)] - ["@" target] - ["[0]" debug] - [abstract - [codec (.except)] - [monad (.only do)] - ["[0]" equivalence (.only Equivalence) - ["poly/[1]" \\poly]] - [\\specification - ["$[0]" equivalence] - ["$[0]" codec]]] - [control - ["[0]" try] - ["p" parser - ... TODO: Get rid of this import ASAP - [json (.only)]]] - [data - ["[0]" bit] - ["[0]" text] - [format - [json (.only JSON) - [\\poly - ["[0]" /]]]] - [collection - [sequence (.only sequence)] - ["d" dictionary] - ["[0]" list]]] - [type - ["[0]" unit]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["[0]" frac]]] - [time - ["ti" instant] - ["tda" date] - ... ["tdu" duration] - ]]] - [test - [lux - [time - ["_[0]" instant] - ... ["_[0]" duration] - ]]]) - -(type: Variant - (.Variant - {#Bit Bit} - {#Text Text} - {#Frac Frac})) - -(type: Recursive - (Rec Recursive - (.Variant - {#Number Frac} - {#Addition Frac Recursive}))) - -(type: Record - (.Record - [#bit Bit - #frac Frac - #text Text - #maybe (Maybe Frac) - #list (List Frac) - #dictionary (d.Dictionary Text Frac) - #variant Variant - #tuple [Bit Text Frac] - #recursive Recursive - ... #instant ti.Instant - ... #duration tdu.Duration - #date tda.Date - #grams (unit.Qty unit.Gram)])) - -(def: gen_recursive - (Random Recursive) - (random.rec - (function (_ gen_recursive) - (random.or random.safe_frac - (random.and random.safe_frac - gen_recursive))))) - -(def: qty - (All (_ unit) (Random (unit.Qty unit))) - (at random.monad each (debug.private unit.in') random.int)) - -(def: gen_record - (Random Record) - (do [! random.monad] - [size (at ! each (n.% 2) random.nat)] - (all random.and - random.bit - random.safe_frac - (random.unicode size) - (random.maybe random.safe_frac) - (random.list size random.safe_frac) - (random.dictionary text.hash size (random.unicode size) random.safe_frac) - (all random.or random.bit (random.unicode size) random.safe_frac) - (all random.and random.bit (random.unicode size) random.safe_frac) - ..gen_recursive - ... _instant.instant - ... _duration.duration - random.date - ..qty - ))) - -(for @.old (these) - (these (def: equivalence - (Equivalence Record) - (poly/equivalence.equivalence Record)) - - (def: codec - (Codec JSON Record) - (/.codec Record)))) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.codec] - (for @.old (_.property "PLACEHOLDER" true) - ($codec.spec ..equivalence ..codec ..gen_record))))) |