From 45c599e49ae2659331d13222948f7e755967fdf9 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 24 Oct 2022 16:58:07 -0400 Subject: New module just for the Char type + fixes to JSON parsing. --- stdlib/source/test/lux/data/format/json.lux | 54 ++++++++++++++- stdlib/source/test/lux/data/format/xml.lux | 2 +- stdlib/source/test/lux/data/text.lux | 4 +- stdlib/source/test/lux/data/text/char.lux | 83 +++++++++++++++++++++++ stdlib/source/test/lux/data/text/escape.lux | 3 +- stdlib/source/test/lux/world/net.lux | 2 + stdlib/source/test/lux/world/net/uri/encoding.lux | 55 +++++++++++++++ 7 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 stdlib/source/test/lux/data/text/char.lux create mode 100644 stdlib/source/test/lux/world/net/uri/encoding.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index e04705902..ad9427770 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -26,9 +26,10 @@ ["[0]" set] ["[0]" list (.use "[1]#[0]" functor)]]] [math - ["[0]" random (.only Random)] - [number + ["[0]" random (.only Random) (.use "[1]#[0]" monad)] + [number (.only hex) ["n" nat] + ["[0]" i64] ["[0]" frac]]] ["[0]" meta (.only) ["@" target] @@ -297,6 +298,42 @@ [value (macro.symbol "string")] (in (list (code.text (%.code value))))))) +(def (digits/4 it) + (-> Nat Text) + (<| (if (n.< (hex "10") it) + (format "000" (%.nat_16 it))) + (if (n.< (hex "100") it) + (format "00" (%.nat_16 it))) + (if (n.< (hex "1000") it) + (format "0" (%.nat_16 it))) + (%.nat_16 it))) + +(def escaped_string + (Random [Text Text]) + (all random.either + (random#in [text.tab "\t"]) + (random#in [text.back_space "\b"]) + (random#in [text.new_line "\n"]) + (random#in [text.carriage_return "\r"]) + (random#in [text.form_feed "\f"]) + (random#in [text.double_quote (format "\" text.double_quote)]) + (random#in ["\" "\\"]) + (do [! random.monad] + [char (at ! each (i64.and (hex "FF")) + random.nat)] + (in [(text.of_char char) + (format "\u" (digits/4 char))])) + )) + +(def any_string + (Random [Text Text]) + (all random.either + escaped_string + (do random.monad + [it (random.alphabetic 1)] + (in [it it])) + )) + (def .public test Test (<| (_.covering /._) @@ -305,7 +342,18 @@ (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random)) (_.for [/.codec] - ($codec.spec /.equivalence /.codec ..random)) + (all _.and + ($codec.spec /.equivalence /.codec ..random) + (do random.monad + [key (random.alphabetic 1) + [expected escaped] any_string] + (_.coverage [/.#String] + (|> {/.#String escaped} + (at /.codec encoded) + (at /.codec decoded) + (try#each (at /.equivalence = {/.#String expected})) + (try.else false)))) + )) (do random.monad [sample ..random] diff --git a/stdlib/source/test/lux/data/format/xml.lux b/stdlib/source/test/lux/data/format/xml.lux index 44e3c2553..653027509 100644 --- a/stdlib/source/test/lux/data/format/xml.lux +++ b/stdlib/source/test/lux/data/format/xml.lux @@ -228,7 +228,7 @@ (def .public test Test (<| (_.covering /._) - (_.for [/.XML]) + (_.for [/.XML /.#Text /.#Node]) (all _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random)) diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux index 8d560a409..99171b434 100644 --- a/stdlib/source/test/lux/data/text.lux +++ b/stdlib/source/test/lux/data/text.lux @@ -69,6 +69,7 @@ ["[1][0]" symbol] ["[1][0]" type]]]] ["[0]" / + ["[1][0]" char] ["[1][0]" buffer] ["[1][0]" encoding] ["[1][0]" regex] @@ -721,7 +722,7 @@ (def char Test (all _.and - (_.for [/.Char /.of_char] + (_.for [/.of_char] (`` (all _.and (,, (with_template [ ] [(_.coverage [ ] @@ -925,6 +926,7 @@ (/#= sample2 (/.replaced sep1 sep2 sample1)))) + /char.test /buffer.test /encoding.test /regex.test diff --git a/stdlib/source/test/lux/data/text/char.lux b/stdlib/source/test/lux/data/text/char.lux new file mode 100644 index 000000000..3c19f277c --- /dev/null +++ b/stdlib/source/test/lux/data/text/char.lux @@ -0,0 +1,83 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [data + [collection + ["[0]" list] + ["[0]" set]]] + [math + ["[0]" random (.only Random)] + [number + ["[0]" nat]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + []) + (_.for [/.Unicode /.Char]) + (`` (all _.and + (with_expansions [ (these /.null + /.alarm + /.back_space + /.tab + /.new_line + /.vertical_tab + /.form_feed + /.carriage_return + /.double_quote + + /.start_of_heading + /.start_of_text + /.end_of_text + /.end_of_transmission + /.enquiry + /.acknowledgement + /.shift_out + /.shift_in + /.data_link_escape + /.device_control_1 + /.device_control_2 + /.device_control_3 + /.device_control_4 + /.negative_acknowledgement + /.synchronous_idle + /.end_of_transmission_block + /.cancel + /.end_of_medium + /.substitute + /.escape + /.file_separator + /.group_separator + /.record_separator + /.unit_separator + /.delete + )] + (_.coverage [] + (let [options (list ) + uniques (set.of_list nat.hash options)] + (nat.= (list.size options) + (set.size uniques))))) + (,, (with_template [ ] + [(_.coverage [] + (same? ))] + + [/.\0 /.null] + [/.\a /.alarm] + [/.\b /.back_space] + [/.\t /.tab] + [/.\n /.new_line] + [/.\v /.vertical_tab] + [/.\f /.form_feed] + [/.\r /.carriage_return] + [/.\'' /.double_quote] + )) + (_.coverage [/.line_feed] + (same? /.new_line /.line_feed)) + )))) diff --git a/stdlib/source/test/lux/data/text/escape.lux b/stdlib/source/test/lux/data/text/escape.lux index 554aaa16f..82be1dcb4 100644 --- a/stdlib/source/test/lux/data/text/escape.lux +++ b/stdlib/source/test/lux/data/text/escape.lux @@ -9,7 +9,8 @@ ["[0]" exception]] [data ["[0]" bit (.use "[1]#[0]" equivalence)] - ["[0]" text (.only Char) (.use "[1]#[0]" equivalence) + ["[0]" text (.use "[1]#[0]" equivalence) + [char (.only Char)] ["%" \\format (.only format)]] [collection ["[0]" set (.only Set)]]] diff --git a/stdlib/source/test/lux/world/net.lux b/stdlib/source/test/lux/world/net.lux index f9b3417ed..e7780f688 100644 --- a/stdlib/source/test/lux/world/net.lux +++ b/stdlib/source/test/lux/world/net.lux @@ -17,6 +17,7 @@ ["[1]/[0]" status] ["[1]/[0]" version]] ["[1][0]" uri + ["[1]/[0]" encoding] ["[1]/[0]" scheme] ["[1]/[0]" path]]]) @@ -41,6 +42,7 @@ /http/status.test /http/version.test + /uri/encoding.test /uri/scheme.test /uri/path.test ))) diff --git a/stdlib/source/test/lux/world/net/uri/encoding.lux b/stdlib/source/test/lux/world/net/uri/encoding.lux new file mode 100644 index 000000000..f9a627e25 --- /dev/null +++ b/stdlib/source/test/lux/world/net/uri/encoding.lux @@ -0,0 +1,55 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [control + ["[0]" maybe] + ["[0]" try (.use "[1]#[0]" functor)]] + [data + ["[0]" text (.use "[1]#[0]" equivalence) + ["%" \\format]] + [collection + ["[0]" list] + ["[0]" set]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(def .public test + Test + (<| (_.covering /._) + (let [choices (set.list /.reserved) + variety (list.size choices)]) + (do [! random.monad] + [safe (random.lower_case 1) + + left (random.lower_case 1) + middle (random.lower_case 1) + right (random.lower_case 1) + left_choice (at ! each (n.% variety) random.nat) + right_choice (at ! each (n.% variety) random.nat) + .let [left_choice (maybe.trusted (list.item left_choice choices)) + right_choice (maybe.trusted (list.item right_choice choices)) + unsafe (%.format left + (text.of_char left_choice) middle + (text.of_char right_choice) right)]]) + (_.for [/.URI_Encoded]) + (all _.and + (_.coverage [/.reserved] + (not (set.empty? /.reserved))) + (_.coverage [/.encoded] + (and (text#= safe (/.encoded safe)) + (not (text#= unsafe (/.encoded unsafe))))) + (_.coverage [/.decoded] + (|> unsafe + /.encoded + /.decoded + (try#each (text#= unsafe)) + (try.else false))) + ))) -- cgit v1.2.3