diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/program.lux | 65 |
1 files changed, 65 insertions, 0 deletions
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)))))))) |