From 6d4950f84e4ec1d35dff95c9816d75f360d4a349 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 19 Apr 2019 18:49:43 -0400 Subject: Moved the CLI parser under "lux/control/parser/". --- stdlib/source/test/lux.lux | 5 +- stdlib/source/test/lux/control.lux | 6 +-- stdlib/source/test/lux/control/cli.lux | 75 -------------------------- stdlib/source/test/lux/control/parser/cli.lux | 77 +++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 80 deletions(-) delete mode 100644 stdlib/source/test/lux/control/cli.lux create mode 100644 stdlib/source/test/lux/control/parser/cli.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index ab5d2e1d4..f62a071ae 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -12,9 +12,10 @@ [monad (#+ do)] [predicate (#+ Predicate)]] [control - [cli (#+ program:)] ["." io (#+ io)] - ["." function]] + ["." function] + [parser + [cli (#+ program:)]]] [data ["." name] [number diff --git a/stdlib/source/test/lux/control.lux b/stdlib/source/test/lux/control.lux index bacb4cb24..61d69459f 100644 --- a/stdlib/source/test/lux/control.lux +++ b/stdlib/source/test/lux/control.lux @@ -2,7 +2,6 @@ [lux #* ["_" test (#+ Test)]] ["." / #_ - ["#." cli] ["#." continuation] ["#." exception] ["#." io] @@ -20,7 +19,8 @@ ["#." actor] ["#." stm]] ["#." parser #_ - ["#/." text]] + ["#/." text] + ["#/." cli]] [security ["#." privacy] ["#." integrity]] @@ -40,6 +40,7 @@ Test ($_ _.and /parser/text.test + /parser/cli.test )) (def: security @@ -52,7 +53,6 @@ (def: #export test Test ($_ _.and - /cli.test /continuation.test /exception.test /io.test diff --git a/stdlib/source/test/lux/control/cli.lux b/stdlib/source/test/lux/control/cli.lux deleted file mode 100644 index ff7a3abb3..000000000 --- a/stdlib/source/test/lux/control/cli.lux +++ /dev/null @@ -1,75 +0,0 @@ -(.module: - [lux #* - data/text/format - ["M" abstract/monad (#+ Monad do)] - ["_" test (#+ Test)] - ["r" math/random] - [control - pipe - ["p" parser]] - [data - ["." error] - [number - ["." nat ("#;." decimal)]] - ["." text ("#;." equivalence)] - [collection - ["." list]]]] - {1 - ["." /]}) - -(def: #export test - Test - (<| (_.context (%name (name-of /.CLI))) - (do r.monad - [num-args (|> r.nat (:: @ map (n/% 10))) - #let [gen-arg (:: @ map nat;encode r.nat)] - yes gen-arg - #let [gen-ignore (r.filter (|>> (text;= yes) not) - (r.unicode 5))] - no gen-ignore - pre-ignore (r.list 5 gen-ignore) - post-ignore (r.list 5 gen-ignore)] - ($_ _.and - (_.test "Can read any argument." - (|> (/.run (list yes) /.any) - (case> (#error.Failure _) - #0 - - (#error.Success arg) - (text;= arg yes)))) - (_.test "Can test tokens." - (and (|> (/.run (list yes) (/.this yes)) - (case> (#error.Failure _) - #0 - - (#error.Success _) - #1)) - (|> (/.run (list no) (/.this yes)) - (case> (#error.Failure _) - #1 - - (#error.Success _) - #0)))) - (_.test "Can use custom token parsers." - (|> (/.run (list yes) (/.parse nat;decode)) - (case> (#error.Failure _) - #0 - - (#error.Success parsed) - (text;= (nat;encode parsed) - yes)))) - (_.test "Can query if there are any more inputs." - (and (|> (/.run (list) /.end) - (case> (#error.Success []) #1 _ #0)) - (|> (/.run (list yes) (p.not /.end)) - (case> (#error.Success []) #0 _ #1)))) - (_.test "Can parse CLI input anywhere." - (|> (/.run (list.concat (list pre-ignore (list yes) post-ignore)) - (|> (/.somewhere (/.this yes)) - (p.before (p.some /.any)))) - (case> (#error.Failure _) - #0 - - (#error.Success _) - #1))) - )))) diff --git a/stdlib/source/test/lux/control/parser/cli.lux b/stdlib/source/test/lux/control/parser/cli.lux new file mode 100644 index 000000000..a476c97c6 --- /dev/null +++ b/stdlib/source/test/lux/control/parser/cli.lux @@ -0,0 +1,77 @@ +(.module: + [lux #* + [data + text/format + ["." name]] + ["M" abstract/monad (#+ Monad do)] + ["_" test (#+ Test)] + ["r" math/random] + [control + pipe + ["p" parser]] + [data + ["." error] + [number + ["." nat ("#@." decimal)]] + ["." text ("#@." equivalence)] + [collection + ["." list]]]] + {1 + ["." /]}) + +(def: #export test + Test + (<| (_.context (name.module (name-of /._))) + (do r.monad + [num-args (|> r.nat (:: @ map (n/% 10))) + #let [gen-arg (:: @ map nat@encode r.nat)] + yes gen-arg + #let [gen-ignore (r.filter (|>> (text@= yes) not) + (r.unicode 5))] + no gen-ignore + pre-ignore (r.list 5 gen-ignore) + post-ignore (r.list 5 gen-ignore)] + ($_ _.and + (_.test "Can read any argument." + (|> (/.run (list yes) /.any) + (case> (#error.Failure _) + #0 + + (#error.Success arg) + (text@= arg yes)))) + (_.test "Can test tokens." + (and (|> (/.run (list yes) (/.this yes)) + (case> (#error.Failure _) + #0 + + (#error.Success _) + #1)) + (|> (/.run (list no) (/.this yes)) + (case> (#error.Failure _) + #1 + + (#error.Success _) + #0)))) + (_.test "Can use custom token parsers." + (|> (/.run (list yes) (/.parse nat@decode)) + (case> (#error.Failure _) + #0 + + (#error.Success parsed) + (text@= (nat@encode parsed) + yes)))) + (_.test "Can query if there are any more inputs." + (and (|> (/.run (list) /.end) + (case> (#error.Success []) #1 _ #0)) + (|> (/.run (list yes) (p.not /.end)) + (case> (#error.Success []) #0 _ #1)))) + (_.test "Can parse CLI input anywhere." + (|> (/.run (list.concat (list pre-ignore (list yes) post-ignore)) + (|> (/.somewhere (/.this yes)) + (p.before (p.some /.any)))) + (case> (#error.Failure _) + #0 + + (#error.Success _) + #1))) + )))) -- cgit v1.2.3