From 04c7f49a732380a2b9f72b1b937171b341c24323 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 9 Apr 2022 03:03:46 -0400 Subject: Better names for testing macros (plus better indentation). --- stdlib/source/test/lux/data/format/json.lux | 162 +++++----- stdlib/source/test/lux/data/format/tar.lux | 452 ++++++++++++++-------------- stdlib/source/test/lux/data/format/xml.lux | 14 +- 3 files changed, 314 insertions(+), 314 deletions(-) (limited to 'stdlib/source/test/lux/data/format') diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index 84f31a550..63bbcab87 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -73,20 +73,20 @@ (do random.monad [sample ..random] - (_.cover [/.Null /.null?] - (# bit.equivalence = - (/.null? sample) - (case sample - {/.#Null} true - _ false)))) + (_.coverage [/.Null /.null?] + (# bit.equivalence = + (/.null? sample) + (case sample + {/.#Null} true + _ false)))) (do random.monad [expected ..random] - (_.cover [/.format] - (|> expected - /.format - (# /.codec decoded) - (try#each (#= expected)) - (try.else false)))) + (_.coverage [/.format] + (|> expected + /.format + (# /.codec decoded) + (try#each (#= expected)) + (try.else false)))) (do random.monad [keys (random.set text.hash 3 (random.alphabetic 1)) values (random.set frac.hash 3 random.safe_frac) @@ -94,55 +94,55 @@ (list#each (|>> {/.#Number}) (set.list values))) object (/.object expected)]] (all _.and - (_.cover [/.object /.fields] - (case (/.fields object) - {try.#Success actual} - (# (list.equivalence text.equivalence) = - (list#each product.left expected) - actual) - - {try.#Failure error} - false)) - (_.cover [/.field] - (list.every? (function (_ [key expected]) - (|> (/.field key object) - (try#each (#= expected)) - (try.else false))) - expected)) + (_.coverage [/.object /.fields] + (case (/.fields object) + {try.#Success actual} + (# (list.equivalence text.equivalence) = + (list#each product.left expected) + actual) + + {try.#Failure error} + false)) + (_.coverage [/.field] + (list.every? (function (_ [key expected]) + (|> (/.field key object) + (try#each (#= expected)) + (try.else false))) + expected)) )) (do random.monad [key (random.alphabetic 1) unknown (random.only (|>> (# text.equivalence = key) not) (random.alphabetic 1)) expected random.safe_frac] - (_.cover [/.has] - (<| (try.else false) - (do try.monad - [object (/.has key {/.#Number expected} (/.object (list))) - .let [can_find_known_key! - (|> object - (/.field key) - (try#each (#= {/.#Number expected})) - (try.else false)) + (_.coverage [/.has] + (<| (try.else false) + (do try.monad + [object (/.has key {/.#Number expected} (/.object (list))) + .let [can_find_known_key! + (|> object + (/.field key) + (try#each (#= {/.#Number expected})) + (try.else false)) - cannot_find_unknown_key! - (case (/.field unknown object) - {try.#Success _} - false + cannot_find_unknown_key! + (case (/.field unknown object) + {try.#Success _} + false - {try.#Failure error} - true)]] - (in (and can_find_known_key! - cannot_find_unknown_key!)))))) + {try.#Failure error} + true)]] + (in (and can_find_known_key! + cannot_find_unknown_key!)))))) (~~ (template [ ] [(do random.monad [key (random.alphabetic 1) value ] - (_.cover [ ] - (|> (/.object (list [key { value}])) - ( key) - (try#each (# = value)) - (try.else false))))] + (_.coverage [ ] + (|> (/.object (list [key { value}])) + ( key) + (try#each (# = value)) + (try.else false))))] [/.Boolean /.boolean_field /.#Boolean random.bit bit.equivalence] [/.Number /.number_field /.#Number random.safe_frac frac.equivalence] @@ -164,36 +164,36 @@ (string) (string) (string)] - (_.cover [/.json] - (and (#= {/.#Null} (/.json ())) - (~~ (template [ ] - [(#= { } (/.json ))] - - [/.#Boolean ] - [/.#Number ] - [/.#String ] - )) - (#= {/.#Array } (/.json [() ])) - (let [object (/.json { () - - - - [() ] - { }})] - (<| (try.else false) - (do try.monad - [value0 (/.field object) - value1 (/.field object) - value2 (/.field object) - value3 (/.field object) - value4 (/.field object) - value5 (/.field object) - value6 (/.field value5)] - (in (and (#= {/.#Null} value0) - (#= {/.#Boolean } value1) - (#= {/.#Number } value2) - (#= {/.#String } value3) - (#= {/.#Array } value4) - (#= {/.#Number } value6)))))) - ))) + (_.coverage [/.json] + (and (#= {/.#Null} (/.json ())) + (~~ (template [ ] + [(#= { } (/.json ))] + + [/.#Boolean ] + [/.#Number ] + [/.#String ] + )) + (#= {/.#Array } (/.json [() ])) + (let [object (/.json { () + + + + [() ] + { }})] + (<| (try.else false) + (do try.monad + [value0 (/.field object) + value1 (/.field object) + value2 (/.field object) + value3 (/.field object) + value4 (/.field object) + value5 (/.field object) + value6 (/.field value5)] + (in (and (#= {/.#Null} value0) + (#= {/.#Boolean } value1) + (#= {/.#Number } value2) + (#= {/.#String } value3) + (#= {/.#Array } value4) + (#= {/.#Number } value6)))))) + ))) )))) diff --git a/stdlib/source/test/lux/data/format/tar.lux b/stdlib/source/test/lux/data/format/tar.lux index a62ce9de4..b4c57411f 100644 --- a/stdlib/source/test/lux/data/format/tar.lux +++ b/stdlib/source/test/lux/data/format/tar.lux @@ -45,30 +45,30 @@ not_ascii (random.text (random.char (unicode.set [unicode/block.katakana (list)])) /.path_size)] (`` (all _.and - (_.cover [/.path /.from_path] - (case (/.path expected) - {try.#Success actual} - (text#= expected - (/.from_path actual)) - - {try.#Failure error} - false)) - (_.cover [/.no_path] - (text#= "" (/.from_path /.no_path))) - (_.cover [/.path_size /.path_is_too_long] - (case (/.path invalid) - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.path_is_too_long error))) - (_.cover [/.not_ascii] - (case (/.path not_ascii) - {try.#Success actual} - false - - {try.#Failure error} - (exception.match? /.not_ascii error))) + (_.coverage [/.path /.from_path] + (case (/.path expected) + {try.#Success actual} + (text#= expected + (/.from_path actual)) + + {try.#Failure error} + false)) + (_.coverage [/.no_path] + (text#= "" (/.from_path /.no_path))) + (_.coverage [/.path_size /.path_is_too_long] + (case (/.path invalid) + {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.path_is_too_long error))) + (_.coverage [/.not_ascii] + (case (/.path not_ascii) + {try.#Success actual} + false + + {try.#Failure error} + (exception.match? /.not_ascii error))) ))))) (def: name @@ -80,28 +80,28 @@ not_ascii (random.text (random.char (unicode.set [unicode/block.katakana (list)])) /.name_size)] (`` (all _.and - (_.cover [/.name /.from_name] - (case (/.name expected) - {try.#Success actual} - (text#= expected - (/.from_name actual)) - - {try.#Failure error} - false)) - (_.cover [/.name_size /.name_is_too_long] - (case (/.name invalid) - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.name_is_too_long error))) - (_.cover [/.not_ascii] - (case (/.name not_ascii) - {try.#Success actual} - false - - {try.#Failure error} - (exception.match? /.not_ascii error))) + (_.coverage [/.name /.from_name] + (case (/.name expected) + {try.#Success actual} + (text#= expected + (/.from_name actual)) + + {try.#Failure error} + false)) + (_.coverage [/.name_size /.name_is_too_long] + (case (/.name invalid) + {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.name_is_too_long error))) + (_.coverage [/.not_ascii] + (case (/.name not_ascii) + {try.#Success actual} + false + + {try.#Failure error} + (exception.match? /.not_ascii error))) ))))) (def: small @@ -111,21 +111,21 @@ [expected (|> random.nat (# ! each (n.% /.small_limit))) invalid (|> random.nat (# ! each (n.max /.small_limit)))] (`` (all _.and - (_.cover [/.small /.from_small] - (case (/.small expected) - {try.#Success actual} - (n.= expected - (/.from_small actual)) - - {try.#Failure error} - false)) - (_.cover [/.small_limit /.not_a_small_number] - (case (/.small invalid) - {try.#Success actual} - false - - {try.#Failure error} - (exception.match? /.not_a_small_number error))) + (_.coverage [/.small /.from_small] + (case (/.small expected) + {try.#Success actual} + (n.= expected + (/.from_small actual)) + + {try.#Failure error} + false)) + (_.coverage [/.small_limit /.not_a_small_number] + (case (/.small invalid) + {try.#Success actual} + false + + {try.#Failure error} + (exception.match? /.not_a_small_number error))) ))))) (def: big @@ -135,21 +135,21 @@ [expected (|> random.nat (# ! each (n.% /.big_limit))) invalid (|> random.nat (# ! each (n.max /.big_limit)))] (`` (all _.and - (_.cover [/.big /.from_big] - (case (/.big expected) - {try.#Success actual} - (n.= expected - (/.from_big actual)) - - {try.#Failure error} - false)) - (_.cover [/.big_limit /.not_a_big_number] - (case (/.big invalid) - {try.#Success actual} - false - - {try.#Failure error} - (exception.match? /.not_a_big_number error))) + (_.coverage [/.big /.from_big] + (case (/.big expected) + {try.#Success actual} + (n.= expected + (/.from_big actual)) + + {try.#Failure error} + false)) + (_.coverage [/.big_limit /.not_a_big_number] + (case (/.big invalid) + {try.#Success actual} + false + + {try.#Failure error} + (exception.match? /.not_a_big_number error))) ))))) (def: chunk_size 32) @@ -168,20 +168,20 @@ (# utf8.codec encoded))]] (`` (all _.and (~~ (template [ ] - [(_.cover [] - (|> (do try.monad - [expected_path (/.path expected_path) - tar (|> (sequence.sequence { expected_path}) - (format.result /.writer) - (.result /.parser))] - (in (case (sequence.list tar) - (pattern (list { actual_path})) - (text#= (/.from_path expected_path) - (/.from_path actual_path)) - - _ - false))) - (try.else false)))] + [(_.coverage [] + (|> (do try.monad + [expected_path (/.path expected_path) + tar (|> (sequence.sequence { expected_path}) + (format.result /.writer) + (.result /.parser))] + (in (case (sequence.list tar) + (pattern (list { actual_path})) + (text#= (/.from_path expected_path) + (/.from_path actual_path)) + + _ + false))) + (try.else false)))] [/.Symbolic_Link /.#Symbolic_Link] [/.Directory /.#Directory] @@ -189,34 +189,34 @@ (_.for [/.File /.Content /.content /.data] (all _.and (~~ (template [ ] - [(_.cover [] - (|> (do try.monad - [expected_path (/.path expected_path) - expected_content (/.content content) - tar (|> (sequence.sequence { [expected_path - expected_moment - /.none - [/.#user [/.#name /.anonymous - /.#id /.no_id] - /.#group [/.#name /.anonymous - /.#id /.no_id]] - expected_content]}) - (format.result /.writer) - (.result /.parser))] - (in (case (sequence.list tar) - (pattern (list { [actual_path actual_moment actual_mode actual_ownership actual_content]})) - (let [seconds (is (-> Instant Int) - (|>> instant.relative (duration.ticks duration.second)))] - (and (text#= (/.from_path expected_path) - (/.from_path actual_path)) - (i.= (seconds expected_moment) - (seconds actual_moment)) - (binary#= (/.data expected_content) - (/.data actual_content)))) - - _ - false))) - (try.else false)))] + [(_.coverage [] + (|> (do try.monad + [expected_path (/.path expected_path) + expected_content (/.content content) + tar (|> (sequence.sequence { [expected_path + expected_moment + /.none + [/.#user [/.#name /.anonymous + /.#id /.no_id] + /.#group [/.#name /.anonymous + /.#id /.no_id]] + expected_content]}) + (format.result /.writer) + (.result /.parser))] + (in (case (sequence.list tar) + (pattern (list { [actual_path actual_moment actual_mode actual_ownership actual_content]})) + (let [seconds (is (-> Instant Int) + (|>> instant.relative (duration.ticks duration.second)))] + (and (text#= (/.from_path expected_path) + (/.from_path actual_path)) + (i.= (seconds expected_moment) + (seconds actual_moment)) + (binary#= (/.data expected_content) + (/.data actual_content)))) + + _ + false))) + (try.else false)))] [/.Normal /.#Normal] [/.Contiguous /.#Contiguous] @@ -247,13 +247,36 @@ modes (random.list 4 ..random_mode) .let [expected_mode (list#mix /.and /.none modes)]] (`` (all _.and - (_.cover [/.and] + (_.coverage [/.and] + (|> (do try.monad + [path (/.path path) + content (/.content (binary.empty 0)) + tar (|> (sequence.sequence {/.#Normal [path + (instant.of_millis +0) + expected_mode + [/.#user [/.#name /.anonymous + /.#id /.no_id] + /.#group [/.#name /.anonymous + /.#id /.no_id]] + content]}) + (format.result /.writer) + (.result /.parser))] + (in (case (sequence.list tar) + (pattern (list {/.#Normal [_ _ actual_mode _ _]})) + (n.= (/.mode expected_mode) + (/.mode actual_mode)) + + _ + false))) + (try.else false))) + (~~ (template [] + [(_.coverage [] (|> (do try.monad [path (/.path path) content (/.content (binary.empty 0)) tar (|> (sequence.sequence {/.#Normal [path (instant.of_millis +0) - expected_mode + [/.#user [/.#name /.anonymous /.#id /.no_id] /.#group [/.#name /.anonymous @@ -263,35 +286,12 @@ (.result /.parser))] (in (case (sequence.list tar) (pattern (list {/.#Normal [_ _ actual_mode _ _]})) - (n.= (/.mode expected_mode) + (n.= (/.mode ) (/.mode actual_mode)) _ false))) - (try.else false))) - (~~ (template [] - [(_.cover [] - (|> (do try.monad - [path (/.path path) - content (/.content (binary.empty 0)) - tar (|> (sequence.sequence {/.#Normal [path - (instant.of_millis +0) - - [/.#user [/.#name /.anonymous - /.#id /.no_id] - /.#group [/.#name /.anonymous - /.#id /.no_id]] - content]}) - (format.result /.writer) - (.result /.parser))] - (in (case (sequence.list tar) - (pattern (list {/.#Normal [_ _ actual_mode _ _]})) - (n.= (/.mode ) - (/.mode actual_mode)) - - _ - false))) - (try.else false)))] + (try.else false)))] [/.none] @@ -322,73 +322,73 @@ /.name_size)] (_.for [/.Ownership /.Owner /.ID] (all _.and - (_.cover [/.name_size /.name_is_too_long] - (case (/.name invalid) - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.name_is_too_long error))) - (_.cover [/.not_ascii] - (case (/.name not_ascii) - {try.#Success actual} - false - - {try.#Failure error} - (exception.match? /.not_ascii error))) - (_.cover [/.Name /.name /.from_name] - (|> (do try.monad - [path (/.path path) - content (/.content (binary.empty 0)) - expected (/.name expected) - tar (|> (sequence.sequence {/.#Normal [path - (instant.of_millis +0) - /.none - [/.#user [/.#name expected - /.#id /.no_id] - /.#group [/.#name /.anonymous - /.#id /.no_id]] - content]}) - (format.result /.writer) - (.result /.parser))] - (in (case (sequence.list tar) - (pattern (list {/.#Normal [_ _ _ actual_ownership _]})) - (and (text#= (/.from_name expected) - (/.from_name (the [/.#user /.#name] actual_ownership))) - (text#= (/.from_name /.anonymous) - (/.from_name (the [/.#group /.#name] actual_ownership)))) - - _ - false))) - (try.else false))) - (_.cover [/.anonymous /.no_id] - (|> (do try.monad - [path (/.path path) - content (/.content (binary.empty 0)) - tar (|> (sequence.sequence {/.#Normal [path - (instant.of_millis +0) - /.none - [/.#user [/.#name /.anonymous - /.#id /.no_id] - /.#group [/.#name /.anonymous - /.#id /.no_id]] - content]}) - (format.result /.writer) - (.result /.parser))] - (in (case (sequence.list tar) - (pattern (list {/.#Normal [_ _ _ actual_ownership _]})) - (and (text#= (/.from_name /.anonymous) - (/.from_name (the [/.#user /.#name] actual_ownership))) - (n.= (/.from_small /.no_id) - (/.from_small (the [/.#user /.#id] actual_ownership))) - (text#= (/.from_name /.anonymous) - (/.from_name (the [/.#group /.#name] actual_ownership))) - (n.= (/.from_small /.no_id) - (/.from_small (the [/.#group /.#id] actual_ownership)))) - - _ - false))) - (try.else false))) + (_.coverage [/.name_size /.name_is_too_long] + (case (/.name invalid) + {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.name_is_too_long error))) + (_.coverage [/.not_ascii] + (case (/.name not_ascii) + {try.#Success actual} + false + + {try.#Failure error} + (exception.match? /.not_ascii error))) + (_.coverage [/.Name /.name /.from_name] + (|> (do try.monad + [path (/.path path) + content (/.content (binary.empty 0)) + expected (/.name expected) + tar (|> (sequence.sequence {/.#Normal [path + (instant.of_millis +0) + /.none + [/.#user [/.#name expected + /.#id /.no_id] + /.#group [/.#name /.anonymous + /.#id /.no_id]] + content]}) + (format.result /.writer) + (.result /.parser))] + (in (case (sequence.list tar) + (pattern (list {/.#Normal [_ _ _ actual_ownership _]})) + (and (text#= (/.from_name expected) + (/.from_name (the [/.#user /.#name] actual_ownership))) + (text#= (/.from_name /.anonymous) + (/.from_name (the [/.#group /.#name] actual_ownership)))) + + _ + false))) + (try.else false))) + (_.coverage [/.anonymous /.no_id] + (|> (do try.monad + [path (/.path path) + content (/.content (binary.empty 0)) + tar (|> (sequence.sequence {/.#Normal [path + (instant.of_millis +0) + /.none + [/.#user [/.#name /.anonymous + /.#id /.no_id] + /.#group [/.#name /.anonymous + /.#id /.no_id]] + content]}) + (format.result /.writer) + (.result /.parser))] + (in (case (sequence.list tar) + (pattern (list {/.#Normal [_ _ _ actual_ownership _]})) + (and (text#= (/.from_name /.anonymous) + (/.from_name (the [/.#user /.#name] actual_ownership))) + (n.= (/.from_small /.no_id) + (/.from_small (the [/.#user /.#id] actual_ownership))) + (text#= (/.from_name /.anonymous) + (/.from_name (the [/.#group /.#name] actual_ownership))) + (n.= (/.from_small /.no_id) + (/.from_small (the [/.#group /.#id] actual_ownership)))) + + _ + false))) + (try.else false))) )))) (def: .public test @@ -398,20 +398,20 @@ (do random.monad [_ (in [])] (all _.and - (_.cover [/.writer /.parser] - (|> sequence.empty - (format.result /.writer) - (.result /.parser) - (# try.monad each sequence.empty?) - (try.else false))) - (_.cover [/.invalid_end_of_archive] - (let [dump (format.result /.writer sequence.empty)] - (case (.result /.parser (binary#composite dump dump)) - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.invalid_end_of_archive error)))) + (_.coverage [/.writer /.parser] + (|> sequence.empty + (format.result /.writer) + (.result /.parser) + (# try.monad each sequence.empty?) + (try.else false))) + (_.coverage [/.invalid_end_of_archive] + (let [dump (format.result /.writer sequence.empty)] + (case (.result /.parser (binary#composite dump dump)) + {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.invalid_end_of_archive error)))) ..path ..name diff --git a/stdlib/source/test/lux/data/format/xml.lux b/stdlib/source/test/lux/data/format/xml.lux index b4c0e7276..0e45f5d72 100644 --- a/stdlib/source/test/lux/data/format/xml.lux +++ b/stdlib/source/test/lux/data/format/xml.lux @@ -82,16 +82,16 @@ [(^.let symbol [namespace name]) ..symbol] (`` (all _.and (~~ (template [ ] - [(_.cover [ ] - (and (text#= name ( ["" name])) - (let [symbol ( symbol)] - (and (text.starts_with? namespace symbol) - (text.ends_with? name symbol)))))] + [(_.coverage [ ] + (and (text#= name ( ["" name])) + (let [symbol ( symbol)] + (and (text.starts_with? namespace symbol) + (text.ends_with? name symbol)))))] [/.Tag /.tag] [/.Attribute /.attribute] )) - (_.cover [/.Attrs /.attributes] - (dictionary.empty? /.attributes)) + (_.coverage [/.Attrs /.attributes] + (dictionary.empty? /.attributes)) ))) ))) -- cgit v1.2.3