@@ -11,6 +11,68 @@ describe("integration: parsing", function()
11
11
assert .are .same (helpers .parse (cli , ' ' ), {})
12
12
end )
13
13
14
+ describe (' validating number of arguments' , function ()
15
+ context (' when no arguments are defined' , function ()
16
+ it (' raises nothing' , function ()
17
+ helpers .parse (cli , ' ' )
18
+ end )
19
+ end )
20
+
21
+ context (' with a required argument' , function ()
22
+ it (' raises an error on extraneous arguments' , function ()
23
+ cli :argument (' FOO' , ' ...' )
24
+
25
+ local _ , err = helpers .parse (cli , ' foo bar' )
26
+
27
+ assert .equal (err , ' bad number of arguments: expected exactly 1 argument not 2' )
28
+ end )
29
+
30
+ it (' raises an error on few arguments' , function ()
31
+ cli :argument (' FOO' , ' ...' )
32
+
33
+ local _ , err = helpers .parse (cli , ' ' )
34
+
35
+ assert .equal (err , ' bad number of arguments: expected exactly 1 argument not 0' )
36
+ end )
37
+ end )
38
+
39
+ context (' with a splat with unlimited reptitions' , function ()
40
+ it (' does not raise an error if nothing is passed in' , function ()
41
+ cli :splat (' FOO' , ' ...' )
42
+
43
+ local _ , err = helpers .parse (cli , ' ' )
44
+
45
+ assert .equal (nil , err )
46
+ end )
47
+
48
+ it (' does not raise an error if something was passed in' , function ()
49
+ cli :splat (' FOO' , ' ...' )
50
+
51
+ local _ , err = helpers .parse (cli , ' foo' )
52
+
53
+ assert .equal (nil , err )
54
+ end )
55
+ end )
56
+
57
+ context (' with a splat with bounded reptitions' , function ()
58
+ it (' does not raise an error if passed count is within bounds' , function ()
59
+ cli :splat (' FOO' , ' ...' , nil , 3 )
60
+
61
+ local _ , err = helpers .parse (cli , ' foo bar' )
62
+
63
+ assert .equal (nil , err )
64
+ end )
65
+
66
+ it (' raises an error if passed count is outside of bounds' , function ()
67
+ cli :splat (' FOO' , ' ...' , nil , 3 )
68
+
69
+ local _ , err = helpers .parse (cli , ' foo bar bax hax' )
70
+
71
+ assert .equal (err , ' bad number of arguments: expected 0-3 arguments not 4' )
72
+ end )
73
+ end )
74
+ end )
75
+
14
76
context (' given a set of arguments' , function ()
15
77
it (' works when all are passed in' , function ()
16
78
cli :argument (' FOO' , ' ...' )
0 commit comments