diff options
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/aedifex.lux | 8 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/parser.lux | 15 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/pom.lux | 5 | ||||
-rw-r--r-- | stdlib/source/test/lux.lux | 27 | ||||
-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 |
10 files changed, 275 insertions, 146 deletions
diff --git a/stdlib/source/test/aedifex.lux b/stdlib/source/test/aedifex.lux index 8757242c5..477ae4d50 100644 --- a/stdlib/source/test/aedifex.lux +++ b/stdlib/source/test/aedifex.lux @@ -16,10 +16,10 @@ ["#." local] ["#." metadata] ["#." package] + ["#." parser] + ["#." pom] ["#." profile] ["#." project] - ## ["#." parser] - ## ["#." pom] ## ["#." repository] ## ["#." runtime] ]) @@ -44,11 +44,11 @@ /local.test /metadata.test /package.test + /parser.test + /pom.test /profile.test /project.test - ## /parser.test - ## /pom.test ## /repository.test ## /runtime.test )) diff --git a/stdlib/source/test/aedifex/parser.lux b/stdlib/source/test/aedifex/parser.lux index 0a13acb32..07c426ebb 100644 --- a/stdlib/source/test/aedifex/parser.lux +++ b/stdlib/source/test/aedifex/parser.lux @@ -8,7 +8,7 @@ [pipe (#+ case>)] ["." try] [parser - ["<c>" code]]] + ["<.>" code]]] [data ["." text] [collection @@ -61,6 +61,10 @@ (set.from_list text.hash (list //.default_source)) sources))))) +(def: with_default_repository + (-> //.Profile //.Profile) + (update@ #//.repositories (set.add //.default_repository))) + (def: single_profile Test (do random.monad @@ -69,10 +73,11 @@ (|> expected //format.profile list - (<c>.run /.project) + (<code>.run /.project) (case> (#try.Success actual) (|> expected ..with_default_sources + ..with_default_repository (//project.project //.default) (\ //project.equivalence = actual)) @@ -93,13 +98,15 @@ (|> expected //format.project list - (<c>.run /.project) + (<code>.run /.project) (case> (#try.Success actual) (|> expected ..with_empty_profile dictionary.entries (list\map (function (_ [name profile]) - [name (..with_default_sources profile)])) + [name (|> profile + ..with_default_sources + ..with_default_repository)])) (dictionary.from_list text.hash) (\ //project.equivalence = actual)) diff --git a/stdlib/source/test/aedifex/pom.lux b/stdlib/source/test/aedifex/pom.lux index c87ff0590..75b8cf5dc 100644 --- a/stdlib/source/test/aedifex/pom.lux +++ b/stdlib/source/test/aedifex/pom.lux @@ -30,11 +30,12 @@ (get@ #//.identity expected)] [(#try.Success pom) (#.Some _)] - (case (<xml>.run /.parser pom) + (case (<xml>.run /.parser (list pom)) (#try.Success actual) (\ //.equivalence = (|> (\ //.monoid identity) - (set@ #//.dependencies (get@ #//.dependencies expected))) + (set@ #//.dependencies (get@ #//.dependencies expected)) + (set@ #//.repositories (get@ #//.repositories expected))) actual) (#try.Failure error) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index de14f2dea..b2929de58 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -36,6 +36,7 @@ ["#." macro] ["#." math] ["#." meta] + ["#." program] ["#." time] ## ["#." tool] ## TODO: Update & expand tests for this ["#." type] @@ -220,13 +221,15 @@ /macro.test /math.test /meta.test + /program.test /time.test ## /tool.test /type.test /world.test /ffi.test <target> - <extension>))))) + <extension> + ))))) (def: test Test @@ -255,7 +258,21 @@ ))) (program: args - (<| io - _.run! - (_.times' (#.Some 2,000) 100) - ..test)) + (let [shift (for {@.jvm 1 + @.old 1 + @.js 2 + @.python 6} + 0) + time_out (|> 1 + (i64.left_shift shift) + (n.* 1,000)) + times (: (-> Test Test) + (for {@.js (_.times 10) + @.python (_.times 1) + @.lua (_.times 1) + @.ruby (_.times 1)} + (_.times' (#.Some time_out) 100)))] + (<| io + _.run! + times + ..test))) 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] + )) + ))) + ))))) |