From 71de092a045dc70ab1c9eead477cf1512b144a87 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 12 Jan 2021 23:09:05 -0400 Subject: Raise error when trying to use deprecated fields/method/classes in JVM. --- stdlib/source/test/aedifex/artifact/time.lux | 42 ++++++++++ stdlib/source/test/aedifex/artifact/time/date.lux | 44 ++++++++++ stdlib/source/test/aedifex/artifact/time/time.lux | 31 +++++++ .../test/aedifex/artifact/time_stamp/date.lux | 44 ---------- .../test/aedifex/artifact/time_stamp/time.lux | 31 ------- stdlib/source/test/lux/control/parser/text.lux | 28 +++---- stdlib/source/test/lux/control/remember.lux | 2 +- stdlib/source/test/lux/data/format/tar.lux | 20 ++--- stdlib/source/test/lux/data/text/unicode/block.lux | 4 +- stdlib/source/test/lux/data/text/unicode/set.lux | 4 +- stdlib/source/test/lux/macro.lux | 2 +- stdlib/source/test/lux/meta.lux | 88 ++++++++++---------- stdlib/source/test/lux/target/jvm.lux | 12 +-- stdlib/source/test/lux/time.lux | 10 ++- stdlib/source/test/lux/time/year.lux | 97 ++++++++++++++++++++++ stdlib/source/test/lux/world/console.lux | 59 +++++++++---- stdlib/source/test/lux/world/shell.lux | 8 +- 17 files changed, 347 insertions(+), 179 deletions(-) create mode 100644 stdlib/source/test/aedifex/artifact/time.lux create mode 100644 stdlib/source/test/aedifex/artifact/time/date.lux create mode 100644 stdlib/source/test/aedifex/artifact/time/time.lux delete mode 100644 stdlib/source/test/aedifex/artifact/time_stamp/date.lux delete mode 100644 stdlib/source/test/aedifex/artifact/time_stamp/time.lux create mode 100644 stdlib/source/test/lux/time/year.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/aedifex/artifact/time.lux b/stdlib/source/test/aedifex/artifact/time.lux new file mode 100644 index 000000000..880bc1f83 --- /dev/null +++ b/stdlib/source/test/aedifex/artifact/time.lux @@ -0,0 +1,42 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try ("#\." functor)] + [parser + ["<.>" text]]] + [math + ["." random]] + [time + ["." instant]]] + {#program + ["." /]} + ["." / #_ + ["#." date] + ["#." time]]) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Time]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence random.instant)) + + (do random.monad + [expected random.instant] + (_.cover [/.format /.parser] + (|> expected + /.format + (.run /.parser) + (try\map (\ instant.equivalence = expected)) + (try.default false)))) + + /date.test + /time.test + ))) diff --git a/stdlib/source/test/aedifex/artifact/time/date.lux b/stdlib/source/test/aedifex/artifact/time/date.lux new file mode 100644 index 000000000..0f4b5b7d3 --- /dev/null +++ b/stdlib/source/test/aedifex/artifact/time/date.lux @@ -0,0 +1,44 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)]] + [control + ["." try ("#\." functor)] + [parser + ["<.>" text]]] + [math + ["." random (#+ Random)] + [number + ["n" nat] + ["i" int]]] + [time + ["." date (#+ Date)] + ["." year]]] + {#program + ["." /]}) + +(def: #export random + (Random Date) + (random.one (function (_ raw) + (try.to_maybe + (do try.monad + [year (|> raw date.year year.value i.abs (i.% +10,000) year.year)] + (date.date year + (date.month raw) + (date.day_of_month raw))))) + random.date)) + +(def: #export test + Test + (<| (_.covering /._) + ($_ _.and + (do random.monad + [expected ..random] + (_.cover [/.format /.parser] + (|> expected + /.format + (.run /.parser) + (try\map (\ date.equivalence = expected)) + (try.default false)))) + ))) diff --git a/stdlib/source/test/aedifex/artifact/time/time.lux b/stdlib/source/test/aedifex/artifact/time/time.lux new file mode 100644 index 000000000..bd9bbe071 --- /dev/null +++ b/stdlib/source/test/aedifex/artifact/time/time.lux @@ -0,0 +1,31 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + ["." time (#+ Time)] + [abstract + [monad (#+ do)]] + [control + ["." try ("#\." functor)] + [parser + ["<.>" text]]] + [math + ["." random (#+ Random)] + [number + ["n" nat] + ["i" int]]]] + {#program + ["." /]}) + +(def: #export test + Test + (<| (_.covering /._) + ($_ _.and + (do random.monad + [expected random.time] + (_.cover [/.format /.parser] + (|> expected + /.format + (.run /.parser) + (try\map (\ time.equivalence = expected)) + (try.default false)))) + ))) diff --git a/stdlib/source/test/aedifex/artifact/time_stamp/date.lux b/stdlib/source/test/aedifex/artifact/time_stamp/date.lux deleted file mode 100644 index 0f4b5b7d3..000000000 --- a/stdlib/source/test/aedifex/artifact/time_stamp/date.lux +++ /dev/null @@ -1,44 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)]] - [control - ["." try ("#\." functor)] - [parser - ["<.>" text]]] - [math - ["." random (#+ Random)] - [number - ["n" nat] - ["i" int]]] - [time - ["." date (#+ Date)] - ["." year]]] - {#program - ["." /]}) - -(def: #export random - (Random Date) - (random.one (function (_ raw) - (try.to_maybe - (do try.monad - [year (|> raw date.year year.value i.abs (i.% +10,000) year.year)] - (date.date year - (date.month raw) - (date.day_of_month raw))))) - random.date)) - -(def: #export test - Test - (<| (_.covering /._) - ($_ _.and - (do random.monad - [expected ..random] - (_.cover [/.format /.parser] - (|> expected - /.format - (.run /.parser) - (try\map (\ date.equivalence = expected)) - (try.default false)))) - ))) diff --git a/stdlib/source/test/aedifex/artifact/time_stamp/time.lux b/stdlib/source/test/aedifex/artifact/time_stamp/time.lux deleted file mode 100644 index bd9bbe071..000000000 --- a/stdlib/source/test/aedifex/artifact/time_stamp/time.lux +++ /dev/null @@ -1,31 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - ["." time (#+ Time)] - [abstract - [monad (#+ do)]] - [control - ["." try ("#\." functor)] - [parser - ["<.>" text]]] - [math - ["." random (#+ Random)] - [number - ["n" nat] - ["i" int]]]] - {#program - ["." /]}) - -(def: #export test - Test - (<| (_.covering /._) - ($_ _.and - (do random.monad - [expected random.time] - (_.cover [/.format /.parser] - (|> expected - /.format - (.run /.parser) - (try\map (\ time.equivalence = expected)) - (try.default false)))) - ))) diff --git a/stdlib/source/test/lux/control/parser/text.lux b/stdlib/source/test/lux/control/parser/text.lux index dd8ce8ceb..6b2152320 100644 --- a/stdlib/source/test/lux/control/parser/text.lux +++ b/stdlib/source/test/lux/control/parser/text.lux @@ -82,15 +82,15 @@ (and (..should_pass expected (/.range offset limit)) (..should_fail out_of_range (/.range offset limit))))) (do {! random.monad} - [expected (random.char unicode.ascii/upper_alpha) - invalid (random.filter (|>> (unicode/block.within? unicode/block.basic_latin/upper_alpha) not) + [expected (random.char unicode.ascii/upper) + invalid (random.filter (|>> (unicode/block.within? unicode/block.basic_latin/upper) not) (random.char unicode.character))] (_.cover [/.upper] (and (..should_pass (text.from_code expected) /.upper) (..should_fail (text.from_code invalid) /.upper)))) (do {! random.monad} - [expected (random.char unicode.ascii/lower_alpha) - invalid (random.filter (|>> (unicode/block.within? unicode/block.basic_latin/lower_alpha) not) + [expected (random.char unicode.ascii/lower) + invalid (random.filter (|>> (unicode/block.within? unicode/block.basic_latin/lower) not) (random.char unicode.character))] (_.cover [/.lower] (and (..should_pass (text.from_code expected) /.lower) @@ -116,8 +116,8 @@ (do {! random.monad} [expected (random.char unicode.ascii/alpha) invalid (random.filter (function (_ char) - (not (or (unicode/block.within? unicode/block.basic_latin/upper_alpha char) - (unicode/block.within? unicode/block.basic_latin/lower_alpha char)))) + (not (or (unicode/block.within? unicode/block.basic_latin/upper char) + (unicode/block.within? unicode/block.basic_latin/lower char)))) (random.char unicode.character))] (_.cover [/.alpha] (and (..should_pass (text.from_code expected) /.alpha) @@ -125,8 +125,8 @@ (do {! random.monad} [expected (random.char unicode.ascii/alpha_num) invalid (random.filter (function (_ char) - (not (or (unicode/block.within? unicode/block.basic_latin/upper_alpha char) - (unicode/block.within? unicode/block.basic_latin/lower_alpha char) + (not (or (unicode/block.within? unicode/block.basic_latin/upper char) + (unicode/block.within? unicode/block.basic_latin/lower char) (unicode/block.within? unicode/block.basic_latin/decimal char)))) (random.char unicode.character))] (_.cover [/.alpha_num] @@ -395,8 +395,8 @@ (!expect (^multi (#try.Success actual) (text\= expected actual)))))) (do {! random.monad} - [invalid (random.ascii/upper_alpha 1) - expected (random.filter (|>> (unicode/block.within? unicode/block.basic_latin/upper_alpha) + [invalid (random.ascii/upper 1) + expected (random.filter (|>> (unicode/block.within? unicode/block.basic_latin/upper) not) (random.char unicode.character)) #let [upper! (/.one_of! "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]] @@ -413,11 +413,11 @@ (!expect (^multi (#try.Failure error) (exception.match? /.expected_to_fail error))))))) (do {! random.monad} - [upper (random.ascii/upper_alpha 1) - lower (random.ascii/lower_alpha 1) + [upper (random.ascii/upper 1) + lower (random.ascii/lower 1) invalid (random.filter (function (_ char) - (not (or (unicode/block.within? unicode/block.basic_latin/upper_alpha char) - (unicode/block.within? unicode/block.basic_latin/lower_alpha char)))) + (not (or (unicode/block.within? unicode/block.basic_latin/upper char) + (unicode/block.within? unicode/block.basic_latin/lower char)))) (random.char unicode.character)) #let [upper! (/.one_of! "ABCDEFGHIJKLMNOPQRSTUVWXYZ") lower! (/.one_of! "abcdefghijklmnopqrstuvwxyz")]] diff --git a/stdlib/source/test/lux/control/remember.lux b/stdlib/source/test/lux/control/remember.lux index 753130ea2..bfe18fa5b 100644 --- a/stdlib/source/test/lux/control/remember.lux +++ b/stdlib/source/test/lux/control/remember.lux @@ -29,7 +29,7 @@ (def: deadline (Random Date) random.date) (def: message (Random Text) (random\map %.nat random.nat)) -(def: focus (Random Code) (random\map code.text (random.ascii/upper_alpha 10))) +(def: focus (Random Code) (random\map code.text (random.ascii/upper 10))) (def: (to_remember macro deadline message focus) (-> Name Date Text (Maybe Code) Code) diff --git a/stdlib/source/test/lux/data/format/tar.lux b/stdlib/source/test/lux/data/format/tar.lux index 9d576b93a..1300012dd 100644 --- a/stdlib/source/test/lux/data/format/tar.lux +++ b/stdlib/source/test/lux/data/format/tar.lux @@ -38,8 +38,8 @@ Test (_.for [/.Path] (do {! random.monad} - [expected (random.ascii/lower_alpha /.path_size) - invalid (random.ascii/lower_alpha (inc /.path_size)) + [expected (random.ascii/lower /.path_size) + invalid (random.ascii/lower (inc /.path_size)) not_ascii (random.text (random.char (unicode.set [unicode/block.katakana (list)])) /.path_size)] (`` ($_ _.and @@ -71,8 +71,8 @@ Test (_.for [/.Name] (do {! random.monad} - [expected (random.ascii/lower_alpha /.name_size) - invalid (random.ascii/lower_alpha (inc /.name_size)) + [expected (random.ascii/lower /.name_size) + invalid (random.ascii/lower (inc /.name_size)) not_ascii (random.text (random.char (unicode.set [unicode/block.katakana (list)])) /.name_size)] (`` ($_ _.and @@ -153,10 +153,10 @@ (def: entry Test (do {! random.monad} - [expected_path (random.ascii/lower_alpha (dec /.path_size)) + [expected_path (random.ascii/lower (dec /.path_size)) expected_moment (\ ! map (|>> (n.% 1,0,00,00,00,00,000) .int instant.from_millis) random.nat) - chunk (random.ascii/lower_alpha chunk_size) + chunk (random.ascii/lower chunk_size) chunks (\ ! map (n.% 100) random.nat) #let [content (|> chunk (list.repeat chunks) @@ -239,7 +239,7 @@ Test (_.for [/.Mode /.mode] (do {! random.monad} - [path (random.ascii/lower_alpha 10) + [path (random.ascii/lower 10) modes (random.list 4 ..random_mode) #let [expected_mode (list\fold /.and /.none modes)]] (`` ($_ _.and @@ -311,9 +311,9 @@ (def: ownership Test (do {! random.monad} - [path (random.ascii/lower_alpha /.path_size) - expected (random.ascii/lower_alpha /.name_size) - invalid (random.ascii/lower_alpha (inc /.name_size)) + [path (random.ascii/lower /.path_size) + expected (random.ascii/lower /.name_size) + invalid (random.ascii/lower (inc /.name_size)) not_ascii (random.text (random.char (unicode.set [unicode/block.katakana (list)])) /.name_size)] (_.for [/.Ownership /.Owner /.ID] diff --git a/stdlib/source/test/lux/data/text/unicode/block.lux b/stdlib/source/test/lux/data/text/unicode/block.lux index 316bbe516..d822a69d3 100644 --- a/stdlib/source/test/lux/data/text/unicode/block.lux +++ b/stdlib/source/test/lux/data/text/unicode/block.lux @@ -140,8 +140,8 @@ ## Specialized blocks /.basic_latin/decimal - /.basic_latin/upper_alpha - /.basic_latin/lower_alpha]] + /.basic_latin/upper + /.basic_latin/lower]] ) (template [ ] [((: (-> Any (List /.Block)) diff --git a/stdlib/source/test/lux/data/text/unicode/set.lux b/stdlib/source/test/lux/data/text/unicode/set.lux index a219bff51..c63239cad 100644 --- a/stdlib/source/test/lux/data/text/unicode/set.lux +++ b/stdlib/source/test/lux/data/text/unicode/set.lux @@ -84,8 +84,8 @@ [/.ascii] [/.ascii/alpha] [/.ascii/alpha_num] - [/.ascii/lower_alpha] - [/.ascii/upper_alpha] + [/.ascii/lower] + [/.ascii/upper] [/.character] [/.non_character] [/.full] diff --git a/stdlib/source/test/lux/macro.lux b/stdlib/source/test/lux/macro.lux index 0b1077526..d4e3e9ae4 100644 --- a/stdlib/source/test/lux/macro.lux +++ b/stdlib/source/test/lux/macro.lux @@ -58,7 +58,7 @@ (Random [Nat Text .Lux]) (do {! random.monad} [seed random.nat - gensym_prefix (random.ascii/upper_alpha 1) + gensym_prefix (random.ascii/upper 1) #let [macro_module (name.module (name_of /._)) current_module (name.module (name_of .._))]] (wrap [seed diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux index c1e0e8e03..ec76184cd 100644 --- a/stdlib/source/test/lux/meta.lux +++ b/stdlib/source/test/lux/meta.lux @@ -41,11 +41,11 @@ (def: compiler_related Test (do random.monad - [target (random.ascii/upper_alpha 1) - version (random.ascii/upper_alpha 1) - source_code (random.ascii/upper_alpha 1) - expected_current_module (random.ascii/upper_alpha 1) - primitive_type (random.ascii/upper_alpha 1) + [target (random.ascii/upper 1) + version (random.ascii/upper 1) + source_code (random.ascii/upper 1) + expected_current_module (random.ascii/upper 1) + primitive_type (random.ascii/upper 1) expected_seed random.nat expected random.nat dummy (random.filter (|>> (n.= expected) not) random.nat) @@ -87,15 +87,15 @@ (def: error_handling Test (do random.monad - [target (random.ascii/upper_alpha 1) - version (random.ascii/upper_alpha 1) - source_code (random.ascii/upper_alpha 1) - expected_current_module (random.ascii/upper_alpha 1) - primitive_type (random.ascii/upper_alpha 1) + [target (random.ascii/upper 1) + version (random.ascii/upper 1) + source_code (random.ascii/upper 1) + expected_current_module (random.ascii/upper 1) + primitive_type (random.ascii/upper 1) expected_seed random.nat expected random.nat dummy (random.filter (|>> (n.= expected) not) random.nat) - expected_error (random.ascii/upper_alpha 1) + expected_error (random.ascii/upper 1) #let [expected_lux {#.info {#.target target #.version version #.mode #.Build} @@ -161,21 +161,21 @@ (def: module_related Test (do random.monad - [target (random.ascii/upper_alpha 1) - version (random.ascii/upper_alpha 1) - source_code (random.ascii/upper_alpha 1) - expected_current_module (random.ascii/upper_alpha 1) + [target (random.ascii/upper 1) + version (random.ascii/upper 1) + source_code (random.ascii/upper 1) + expected_current_module (random.ascii/upper 1) imported_module_name (random.filter (|>> (text\= expected_current_module) not) - (random.ascii/upper_alpha 1)) - primitive_type (random.ascii/upper_alpha 1) + (random.ascii/upper 1)) + primitive_type (random.ascii/upper 1) expected_seed random.nat expected random.nat dummy (random.filter (|>> (n.= expected) not) random.nat) - expected_short (random.ascii/upper_alpha 1) + expected_short (random.ascii/upper 1) dummy_module (random.filter (function (_ module) (not (or (text\= expected_current_module module) (text\= imported_module_name module)))) - (random.ascii/upper_alpha 1)) + (random.ascii/upper 1)) #let [imported_module {#.module_hash 0 #.module_aliases (list) #.definitions (list) @@ -275,19 +275,19 @@ (def: random_location (Random Location) ($_ random.and - (random.ascii/upper_alpha 1) + (random.ascii/upper 1) random.nat random.nat)) (def: context_related (do {! random.monad} - [target (random.ascii/upper_alpha 1) - version (random.ascii/upper_alpha 1) - source_code (random.ascii/upper_alpha 1) - expected_current_module (random.ascii/upper_alpha 1) + [target (random.ascii/upper 1) + version (random.ascii/upper 1) + source_code (random.ascii/upper 1) + expected_current_module (random.ascii/upper 1) expected_type (\ ! map (function (_ name) (#.Primitive name (list))) - (random.ascii/upper_alpha 1)) + (random.ascii/upper 1)) expected_seed random.nat expected random.nat dummy (random.filter (|>> (n.= expected) not) random.nat) @@ -339,13 +339,13 @@ (def: definition_related Test (do {! random.monad} - [expected_current_module (random.ascii/upper_alpha 1) + [expected_current_module (random.ascii/upper 1) expected_macro_module (random.filter (|>> (text\= expected_current_module) not) - (random.ascii/upper_alpha 1)) - expected_short (random.ascii/upper_alpha 1) + (random.ascii/upper 1)) + expected_short (random.ascii/upper 1) expected_type (\ ! map (function (_ name) (#.Primitive name (list))) - (random.ascii/upper_alpha 1)) + (random.ascii/upper 1)) expected_value (random.either (wrap .def:) (wrap .macro:)) #let [expected_lux @@ -459,13 +459,13 @@ Test (do {! random.monad} [expected_exported? random.bit - expected_current_module (random.ascii/upper_alpha 1) + expected_current_module (random.ascii/upper 1) expected_macro_module (random.filter (|>> (text\= expected_current_module) not) - (random.ascii/upper_alpha 1)) - expected_short (random.ascii/upper_alpha 1) + (random.ascii/upper 1)) + expected_short (random.ascii/upper 1) expected_type (\ ! map (function (_ name) (#.Primitive name (list))) - (random.ascii/upper_alpha 1)) + (random.ascii/upper 1)) #let [expected_annotations (' [])] expected_value (random.either (wrap .def:) (wrap .macro:)) @@ -638,16 +638,16 @@ (def: tags_related Test (do {! random.monad} - [current_module (random.ascii/upper_alpha 1) + [current_module (random.ascii/upper 1) tag_module (random.filter (|>> (text\= current_module) not) - (random.ascii/upper_alpha 1)) + (random.ascii/upper 1)) - name_0 (random.ascii/upper_alpha 1) + name_0 (random.ascii/upper 1) name_1 (random.filter (|>> (text\= name_0) not) - (random.ascii/upper_alpha 1)) + (random.ascii/upper 1)) #let [random_tag (\ ! map (|>> [tag_module]) - (random.ascii/upper_alpha 1))] + (random.ascii/upper 1))] all_tags (|> random_tag (random.set name.hash 10) (\ ! map set.to_list)) @@ -762,13 +762,13 @@ (<| (_.covering /._) ($_ _.and (do {! random.monad} - [target (random.ascii/upper_alpha 1) - version (random.ascii/upper_alpha 1) - source_code (random.ascii/upper_alpha 1) - expected_current_module (random.ascii/upper_alpha 1) + [target (random.ascii/upper 1) + version (random.ascii/upper 1) + source_code (random.ascii/upper 1) + expected_current_module (random.ascii/upper 1) expected_type (\ ! map (function (_ name) (#.Primitive name (list))) - (random.ascii/upper_alpha 1)) + (random.ascii/upper 1)) expected_seed random.nat expected random.nat dummy (random.filter (|>> (n.= expected) not) random.nat) @@ -799,7 +799,7 @@ (do random.monad [expected_value random.nat - expected_error (random.ascii/upper_alpha 1)] + expected_error (random.ascii/upper 1)] (_.cover [/.lift] (and (|> expected_error #try.Failure diff --git a/stdlib/source/test/lux/target/jvm.lux b/stdlib/source/test/lux/target/jvm.lux index a04371340..f2c8963d3 100644 --- a/stdlib/source/test/lux/target/jvm.lux +++ b/stdlib/source/test/lux/target/jvm.lux @@ -86,9 +86,9 @@ (def: class_name (Random Text) (do random.monad - [super_package (random.ascii/lower_alpha 10) - package (random.ascii/lower_alpha 10) - name (random.ascii/upper_alpha 10)] + [super_package (random.ascii/lower 10) + package (random.ascii/lower 10) + name (random.ascii/upper 10)] (wrap (format super_package /name.external_separator package /name.external_separator name)))) @@ -105,7 +105,7 @@ (-> (-> Any Bit) (Bytecode Any) (Random Bit)) (do random.monad [class_name ..class_name - method_name (random.ascii/upper_alpha 10)] + method_name (random.ascii/upper 10)] (wrap (case (do try.monad [class (/class.class /version.v6_0 /class.public (/name.internal class_name) @@ -1319,9 +1319,9 @@ (function (_ primitive return substitute test) (do random.monad [class_name ..class_name - primitive_method_name (random.ascii/upper_alpha 10) + primitive_method_name (random.ascii/upper 10) #let [primitive_method_type (/type.method [(list) (get@ #unboxed primitive) (list)])] - object_method_name (|> (random.ascii/upper_alpha 10) + object_method_name (|> (random.ascii/upper 10) (random.filter (|>> (text\= primitive_method_name) not))) expected (get@ #random primitive) #let [$Self (/type.class class_name (list))]] diff --git a/stdlib/source/test/lux/time.lux b/stdlib/source/test/lux/time.lux index 5fd13dbe9..cc18c20e0 100644 --- a/stdlib/source/test/lux/time.lux +++ b/stdlib/source/test/lux/time.lux @@ -2,18 +2,20 @@ [lux #* ["_" test (#+ Test)]] ["." / #_ + ["#." date] + ["#." day] ["#." duration] ["#." instant] - ["#." day] ["#." month] - ["#." date]]) + ["#." year]]) (def: #export test Test ($_ _.and + /date.test + /day.test /duration.test /instant.test - /day.test /month.test - /date.test + /year.test )) diff --git a/stdlib/source/test/lux/time/year.lux b/stdlib/source/test/lux/time/year.lux new file mode 100644 index 000000000..3e29f0ffb --- /dev/null +++ b/stdlib/source/test/lux/time/year.lux @@ -0,0 +1,97 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence] + ["$." order] + ["$." codec]]}] + [control + ["." try] + ["." exception]] + [data + ["." bit ("#\." equivalence)] + [text + ["%" format (#+ format)]]] + [math + ["." random (#+ Random)] + [number + ["n" nat] + ["i" int]]]] + {1 + ["." / + ["/#" // + ["#." duration] + ["#." instant] + ["#." date]]]}) + +(def: #export random + (Random /.Year) + (random.one (|>> /.year try.to_maybe) random.int)) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Year]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + (_.for [/.order] + ($order.spec /.order ..random)) + (_.for [/.codec /.parser] + ($codec.spec /.equivalence /.codec ..random)) + + (do random.monad + [expected random.int] + ($_ _.and + (_.cover [/.year] + (bit\= (i.= +0 expected) + (case (/.year expected) + (#try.Success _) + false + + (#try.Failure _) + true))) + (_.cover [/.value] + (case (/.year expected) + (#try.Success year) + (i.= expected (/.value year)) + + (#try.Failure _) + (i.= +0 expected))) + )) + (_.cover [/.there-is-no-year-0] + (case (/.year +0) + (#try.Success _) + false + + (#try.Failure error) + (exception.match? /.there-is-no-year-0 error))) + (_.cover [/.days] + (n.= (.nat (//duration.query //duration.day //duration.normal_year)) + /.days)) + (_.cover [/.epoch] + (\ /.equivalence = + (//date.year (//instant.date //instant.epoch)) + /.epoch)) + (_.for [/.Period] + (_.cover [/.leap /.century /.era] + (n.= /.leap (n./ /.century /.era)))) + (let [leap (try.assume (/.year (.int /.leap))) + century (try.assume (/.year (.int /.century))) + era (try.assume (/.year (.int /.era)))] + ($_ _.and + (_.cover [/.leap?] + (and (/.leap? leap) + (not (/.leap? century)) + (/.leap? era))) + (_.cover [/.leaps] + (and (i.= +1 (/.leaps leap)) + (i.= (.int (n./ /.leap /.century)) + (/.leaps century)) + (i.= (inc (i.* +4 (dec (/.leaps century)))) + (/.leaps era)))) + )) + ))) diff --git a/stdlib/source/test/lux/world/console.lux b/stdlib/source/test/lux/world/console.lux index b7c7d3a50..6c71f913c 100644 --- a/stdlib/source/test/lux/world/console.lux +++ b/stdlib/source/test/lux/world/console.lux @@ -6,7 +6,14 @@ [control ["." io] ["." try (#+ Try)] - ["." exception (#+ exception:)]]] + ["." exception (#+ exception:)] + [security + ["!" capability]]] + [data + ["." text ("#\." equivalence) + ["%" format (#+ format)]]] + [math + ["." random]]] {1 ["." /]} {[1 #spec] @@ -15,30 +22,50 @@ (exception: dead) (def: simulation - (/.Simulation Bit) + (/.Simulation [Bit Text]) (structure - (def: (on_read dead?) - (if dead? - (exception.throw ..dead []) - (#try.Success [dead? (char "a")]))) + (def: (on_read [dead? content]) + (do try.monad + [char (try.from_maybe (text.nth 0 content)) + [_ content] (try.from_maybe (text.split 1 content))] + (if dead? + (exception.throw ..dead []) + (wrap [[dead? content] char])))) - (def: (on_read_line dead?) - (if dead? - (exception.throw ..dead []) - (#try.Success [dead? "YOLO"]))) + (def: (on_read_line [dead? content]) + (do try.monad + [[line content] (try.from_maybe (text.split_with text.new_line content))] + (if dead? + (exception.throw ..dead []) + (wrap [[dead? content] line])))) - (def: (on_write message dead?) + (def: (on_write message [dead? content]) (if dead? (exception.throw ..dead []) - (#try.Success dead?))) + (#try.Success [dead? (format content message)]))) - (def: (on_close dead?) + (def: (on_close [dead? content]) (if dead? (exception.throw ..dead []) - (#try.Success true))))) + (#try.Success [true content]))))) (def: #export test Test (<| (_.covering /._) - (_.for [/.mock /.Simulation] - ($/.spec (io.io (/.mock ..simulation false)))))) + ($_ _.and + (_.for [/.async /.mock /.Simulation] + ($/.spec (io.io (/.async (/.mock ..simulation [false ""]))))) + (do random.monad + [expected (random.ascii/alpha 10) + #let [console (/.mock ..simulation [false ""])]] + (_.cover [/.write_line] + (io.run + (do io.monad + [?_ (/.write_line expected console) + ?actual (!.use (\ console read_line) [])] + (wrap (<| (try.default false) + (do try.monad + [_ ?_ + actual ?actual] + (wrap (text\= expected actual))))))))) + ))) diff --git a/stdlib/source/test/lux/world/shell.lux b/stdlib/source/test/lux/world/shell.lux index a336de350..fa7d77f22 100644 --- a/stdlib/source/test/lux/world/shell.lux +++ b/stdlib/source/test/lux/world/shell.lux @@ -98,9 +98,9 @@ Test (<| (_.covering /._) ($_ _.and - (_.for [/.mock /.Simulation] - ($/.spec (/.mock (|>> ..simulation #try.Success) - false))) + (_.for [/.async /.mock /.Simulation] + ($/.spec (/.async (/.mock (|>> ..simulation #try.Success) + false)))) (_.cover [/.error] (not (i.= /.normal /.error))) (do random.monad @@ -137,6 +137,6 @@ wrote! destroyed! (i.= exit await))))] - (_.cover' [/.async /.Can_Write] + (_.cover' [/.Can_Write] (try.default false verdict))))) ))) -- cgit v1.2.3