diff options
Diffstat (limited to 'stdlib/source/test/lux')
-rw-r--r-- | stdlib/source/test/lux/data/color/named.lux | 17 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/text/escape.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/debug.lux | 16 | ||||
-rw-r--r-- | stdlib/source/test/lux/math/number/ratio.lux | 34 | ||||
-rw-r--r-- | stdlib/source/test/lux/program.lux | 65 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/input/keyboard.lux | 232 |
6 files changed, 235 insertions, 131 deletions
diff --git a/stdlib/source/test/lux/data/color/named.lux b/stdlib/source/test/lux/data/color/named.lux index 9a3fddcaf..14ec96329 100644 --- a/stdlib/source/test/lux/data/color/named.lux +++ b/stdlib/source/test/lux/data/color/named.lux @@ -198,16 +198,15 @@ [letter/y [/.yellow /.yellow_green]] - ) - <named> (template [<definition> <by_letter>] - [((: (-> Any (List //.Color)) - (function (_ _) - (`` (list (~~ (template.splice <by_letter>)))))) - 123)] - - <colors>)] + )] (def: all_colors - (list.concat (list <named>))) + (list.concat (`` (list (~~ (template [<definition> <by_letter>] + [((: (-> Any (List //.Color)) + (function (_ _) + (`` (list (~~ (template.splice <by_letter>)))))) + 123)] + + <colors>)))))) (def: unique_colors (set.from_list //.hash ..all_colors)) diff --git a/stdlib/source/test/lux/data/text/escape.lux b/stdlib/source/test/lux/data/text/escape.lux index a91ba6247..e7f31f9d7 100644 --- a/stdlib/source/test/lux/data/text/escape.lux +++ b/stdlib/source/test/lux/data/text/escape.lux @@ -72,7 +72,7 @@ (do meta.monad [seed meta.count #let [[_ expected] (random.run (random.pcg32 [seed seed]) - (random.unicode 10))]] + (random.ascii 10))]] (wrap (list (code.text expected))))) (syntax: (static_escape {un_escaped <code>.text}) diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux index 508f9fd6d..dbed9a05f 100644 --- a/stdlib/source/test/lux/debug.lux +++ b/stdlib/source/test/lux/debug.lux @@ -1,6 +1,7 @@ (.module: [lux #* ["_" test (#+ Test)] + ["@" target] [abstract [monad (#+ do)]] [control @@ -209,7 +210,8 @@ (list\map /.inspect) (text.join_with " ") (text.enclose ["[" "]"])) - (/.inspect [sample_bit sample_int sample_frac sample_text]))))))) + (/.inspect [sample_bit sample_int sample_frac sample_text])) + ))))) (syntax: (macro_error macro) (function (_ compiler) @@ -238,11 +240,13 @@ bar random.nat baz random.bit] (_.cover [/.here] - (exec - (/.here) - (/.here foo - {bar %.nat}) - true))) + (with_expansions [<no_parameters> (for {@.js (~~ (as_is))} + (~~ (as_is (/.here))))] + (`` (exec + <no_parameters> + (/.here foo + {bar %.nat}) + true))))) (_.cover [/.unknown_local_binding] (exception.match? /.unknown_local_binding (..macro_error (/.here yolo)))) diff --git a/stdlib/source/test/lux/math/number/ratio.lux b/stdlib/source/test/lux/math/number/ratio.lux index 199096dab..f031810d9 100644 --- a/stdlib/source/test/lux/math/number/ratio.lux +++ b/stdlib/source/test/lux/math/number/ratio.lux @@ -64,17 +64,29 @@ denominator (random.filter (|>> (n\= 1) not) ..part)] (_.cover [/.nat] - (and (|> (/.ratio numerator) - /.nat - (maybe\map (n\= numerator)) - (maybe.default false)) - (|> (/.ratio numerator 1) - /.nat - (maybe\map (n\= numerator)) - (maybe.default false)) - (case (/.nat (/.ratio numerator denominator)) - #.None true - (#.Some _) false)))) + (let [only_numerator! + (|> (/.ratio numerator) + /.nat + (maybe\map (n\= numerator)) + (maybe.default false)) + + denominator_1! + (|> (/.ratio numerator 1) + /.nat + (maybe\map (n\= numerator)) + (maybe.default false)) + + with_denominator! + (case (/.nat (/.ratio numerator denominator)) + (#.Some factor) + (and (n.= 0 (n.% denominator numerator)) + (n.= numerator (n.* factor denominator))) + + #.None + (not (n.= 0 (n.% denominator numerator))))] + (and only_numerator! + denominator_1! + with_denominator!)))) (do random.monad [sample ..random] ($_ _.and diff --git a/stdlib/source/test/lux/program.lux b/stdlib/source/test/lux/program.lux new file mode 100644 index 000000000..fe969cd3c --- /dev/null +++ b/stdlib/source/test/lux/program.lux @@ -0,0 +1,65 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + ["." ffi] + [abstract + [monad (#+ do)]] + [control + ["." io] + ["." try] + ["<>" parser + ["<.>" code] + ["<.>" cli]]] + [data + ["." text] + [collection + ["." list]]] + [macro + [syntax (#+ syntax:)]] + [math + ["." random]]] + {1 + ["." /]}) + +(syntax: (actual_program {actual_program (<| <code>.form + (<>.after (<code>.text! "lux def program")) + <code>.any)}) + (wrap (list actual_program))) + +(def: #export test + Test + (<| (_.covering /._) + (do random.monad + [inputs (random.list 5 (random.ascii/upper 5))] + (_.cover [/.program:] + (let [(^open "list\.") (list.equivalence text.equivalence)] + (and (with_expansions [<program> (/.program: all_arguments + (io.io all_arguments))] + (let [outcome ((: (-> (List Text) (io.IO Any)) + (..actual_program <program>)) + inputs)] + (is? (: Any inputs) (io.run outcome)))) + (with_expansions [<program> (/.program: [arg/0 arg/1 arg/2 arg/3 arg/4] + (io.io (list arg/4 arg/3 arg/2 arg/1 arg/0)))] + (let [outcome ((: (-> (List Text) (io.IO Any)) + (..actual_program <program>)) + inputs)] + (list\= (list.reverse inputs) + (:coerce (List Text) (io.run outcome))))) + (with_expansions [<program> (/.program: [{all_arguments (<>.many <cli>.any)}] + (io.io all_arguments))] + (let [outcome ((: (-> (List Text) (io.IO Any)) + (..actual_program <program>)) + inputs)] + (list\= inputs + (:coerce (List Text) (io.run outcome))))) + (with_expansions [<program> (/.program: [arg/0 arg/1 arg/2 arg/3] + (io.io []))] + (case (ffi.try ((: (-> (List Text) (io.IO Any)) + (..actual_program <program>)) + inputs)) + (#try.Success _) + false + + (#try.Failure _) + true)))))))) diff --git a/stdlib/source/test/lux/world/input/keyboard.lux b/stdlib/source/test/lux/world/input/keyboard.lux index e38ce6271..1dde1aaa7 100644 --- a/stdlib/source/test/lux/world/input/keyboard.lux +++ b/stdlib/source/test/lux/world/input/keyboard.lux @@ -9,6 +9,8 @@ [collection ["." list] ["." set (#+ Set)]]] + [macro + ["." template]] [math ["." random (#+ Random)] [number @@ -16,101 +18,122 @@ {1 ["." /]}) -(with_expansions [<keys> (as_is /.back_space - /.enter - /.shift - /.control - /.alt - /.caps_lock - /.escape - /.space - /.page_up - /.page_down - /.end - /.home +(with_expansions [<groups> (as_is [keys/commands + [/.back_space + /.enter + /.shift + /.control + /.alt + /.caps_lock + /.escape + /.space + /.page_up + /.page_down + /.end + /.home + /.delete + /.num_lock + /.scroll_lock + /.print_screen + /.insert + /.windows - /.left - /.up - /.right - /.down - - /.a - /.b - /.c - /.d - /.e - /.f - /.g - /.h - /.i - /.j - /.k - /.l - /.m - /.n - /.o - /.p - /.q - /.r - /.s - /.t - /.u - /.v - /.w - /.x - /.y - /.z - - /.num_pad_0 - /.num_pad_1 - /.num_pad_2 - /.num_pad_3 - /.num_pad_4 - /.num_pad_5 - /.num_pad_6 - /.num_pad_7 - /.num_pad_8 - /.num_pad_9 + /.left + /.up + /.right + /.down]] + + [keys/letters + [/.a + /.b + /.c + /.d + /.e + /.f + /.g + /.h + /.i + /.j + /.k + /.l + /.m + /.n + /.o + /.p + /.q + /.r + /.s + /.t + /.u + /.v + /.w + /.x + /.y + /.z]] + + [keys/num_pad + [/.num_pad_0 + /.num_pad_1 + /.num_pad_2 + /.num_pad_3 + /.num_pad_4 + /.num_pad_5 + /.num_pad_6 + /.num_pad_7 + /.num_pad_8 + /.num_pad_9]] - /.delete - /.num_lock - /.scroll_lock - /.print_screen - /.insert - /.windows - - /.f1 - /.f2 - /.f3 - /.f4 - /.f5 - /.f6 - /.f7 - /.f8 - /.f9 - /.f10 - /.f11 - /.f12 - /.f13 - /.f14 - /.f15 - /.f16 - /.f17 - /.f18 - /.f19 - /.f20 - /.f21 - /.f22 - /.f23 - /.f24)] + [keys/functions + [/.f1 + /.f2 + /.f3 + /.f4 + /.f5 + /.f6 + /.f7 + /.f8 + /.f9 + /.f10 + /.f11 + /.f12 + /.f13 + /.f14 + /.f15 + /.f16 + /.f17 + /.f18 + /.f19 + /.f20 + /.f21 + /.f22 + /.f23 + /.f24]])] (def: listing (List /.Key) - (list <keys>)) + (list.concat (`` (list (~~ (template [<definition> <keys>] + [((: (-> Any (List /.Key)) + (function (_ _) + (`` (list (~~ (template.splice <keys>)))))) + [])] + + <groups>)))))) (def: catalogue (Set /.Key) (set.from_list n.hash ..listing)) + (def: verdict + (n.= (list.size ..listing) + (set.size ..catalogue))) + + (template [<definition> <keys>] + [(def: <definition> + Test + (_.cover <keys> + ..verdict))] + + <groups>) + (def: #export random (Random /.Key) (let [count (list.size ..listing)] @@ -122,23 +145,24 @@ Test (<| (_.covering /._) (_.for [/.Key]) - ($_ _.and - (_.cover [<keys>] - (n.= (list.size ..listing) - (set.size ..catalogue))) + (`` ($_ _.and + (~~ (template [<definition> <keys>] + [<definition>] + + <groups>)) - (_.for [/.Press] - (`` ($_ _.and - (~~ (template [<pressed?> <function>] - [(do random.monad - [key ..random - #let [sample (<function> key)]] - (_.cover [<function>] - (and (bit\= <pressed?> (get@ #/.pressed? sample)) - (n.= key (get@ #/.input sample)))))] + (_.for [/.Press] + (`` ($_ _.and + (~~ (template [<pressed?> <function>] + [(do random.monad + [key ..random + #let [sample (<function> key)]] + (_.cover [<function>] + (and (bit\= <pressed?> (get@ #/.pressed? sample)) + (n.= key (get@ #/.input sample)))))] - [#0 /.release] - [#1 /.press] - )) - ))) - )))) + [#0 /.release] + [#1 /.press] + )) + ))) + ))))) |