blob: 8c04a119dfede705eaa41dd2c7e9f0c3d4cae4de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
(.module:
[lux #*
[control
["M" monad (#+ Monad do)]
pipe
["p" parser]]
[data
["." error]
[number
["." nat ("#/." decimal)]]
["." text ("#/." equivalence)
format]
[collection
["." list]]]
[math
["r" random]]
["_" test (#+ Test)]]
{1
["." /]})
(def: #export test
Test
(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)))
)))
|