@@ -19,11 +19,23 @@ describe('parseArguments', () => {
19
19
{ name : 'arr' , aliases : [ 'a' ] , type : OptionType . Array , description : '' } ,
20
20
{ name : 'p1' , positional : 0 , aliases : [ ] , type : OptionType . String , description : '' } ,
21
21
{ name : 'p2' , positional : 1 , aliases : [ ] , type : OptionType . String , description : '' } ,
22
+ { name : 't1' , aliases : [ ] , type : OptionType . Boolean ,
23
+ types : [ OptionType . Boolean , OptionType . String ] , description : '' } ,
24
+ { name : 't2' , aliases : [ ] , type : OptionType . Boolean ,
25
+ types : [ OptionType . Boolean , OptionType . Number ] , description : '' } ,
26
+ { name : 't3' , aliases : [ ] , type : OptionType . Number ,
27
+ types : [ OptionType . Number , OptionType . Any ] , description : '' } ,
28
+ { name : 'e1' , aliases : [ ] , type : OptionType . String , enum : [ 'hello' , 'world' ] , description : '' } ,
29
+ { name : 'e2' , aliases : [ ] , type : OptionType . String , enum : [ 'hello' , '' ] , description : '' } ,
30
+ { name : 'e3' , aliases : [ ] , type : OptionType . Boolean ,
31
+ types : [ OptionType . String , OptionType . Boolean ] , enum : [ 'json' , true , false ] ,
32
+ description : '' } ,
22
33
] ;
23
34
24
35
const tests : { [ test : string ] : Partial < Arguments > } = {
25
36
'--bool' : { bool : true } ,
26
- '--bool=1' : { bool : true } ,
37
+ '--bool=1' : { '--' : [ '--bool=1' ] } ,
38
+ '--bool=yellow' : { '--' : [ '--bool=yellow' ] } ,
27
39
'--bool=true' : { bool : true } ,
28
40
'--bool=false' : { bool : false } ,
29
41
'--no-bool' : { bool : false } ,
@@ -33,7 +45,7 @@ describe('parseArguments', () => {
33
45
'--b true' : { bool : true } ,
34
46
'--b false' : { bool : false } ,
35
47
'--bool --num' : { bool : true , num : 0 } ,
36
- '--bool --num=true' : { bool : true } ,
48
+ '--bool --num=true' : { bool : true , '--' : [ '--num=true' ] } ,
37
49
'--bool=true --num' : { bool : true , num : 0 } ,
38
50
'--bool true --num' : { bool : true , num : 0 } ,
39
51
'--bool=false --num' : { bool : false , num : 0 } ,
@@ -51,16 +63,55 @@ describe('parseArguments', () => {
51
63
'--bool val1 --etc --num val2 --v' : { bool : true , num : 0 , p1 : 'val1' , p2 : 'val2' ,
52
64
'--' : [ '--etc' , '--v' ] } ,
53
65
'--arr=a --arr=b --arr c d' : { arr : [ 'a' , 'b' , 'c' ] , p1 : 'd' } ,
54
- '--arr=1 --arr --arr c d' : { arr : [ '1' , '--arr' ] , p1 : 'c' , p2 : 'd' } ,
66
+ '--arr=1 --arr --arr c d' : { arr : [ '1' , '' , 'c' ] , p1 : 'd' } ,
67
+ '--arr=1 --arr --arr c d e' : { arr : [ '1' , '' , 'c' ] , p1 : 'd' , p2 : 'e' } ,
55
68
'--str=1' : { str : '1' } ,
56
69
'--hello-world=1' : { helloWorld : '1' } ,
57
70
'--hello-bool' : { helloBool : true } ,
58
71
'--helloBool' : { helloBool : true } ,
59
72
'--no-helloBool' : { helloBool : false } ,
60
73
'--noHelloBool' : { helloBool : false } ,
74
+ '--noBool' : { bool : false } ,
61
75
'-b' : { bool : true } ,
62
76
'-sb' : { bool : true , str : '' } ,
63
77
'-bs' : { bool : true , str : '' } ,
78
+ '--t1=true' : { t1 : true } ,
79
+ '--t1' : { t1 : true } ,
80
+ '--t1 --num' : { t1 : true , num : 0 } ,
81
+ '--no-t1' : { t1 : false } ,
82
+ '--t1=yellow' : { t1 : 'yellow' } ,
83
+ '--no-t1=true' : { '--' : [ '--no-t1=true' ] } ,
84
+ '--t1=123' : { t1 : '123' } ,
85
+ '--t2=true' : { t2 : true } ,
86
+ '--t2' : { t2 : true } ,
87
+ '--no-t2' : { t2 : false } ,
88
+ '--t2=yellow' : { '--' : [ '--t2=yellow' ] } ,
89
+ '--no-t2=true' : { '--' : [ '--no-t2=true' ] } ,
90
+ '--t2=123' : { t2 : 123 } ,
91
+ '--t3=a' : { t3 : 'a' } ,
92
+ '--t3' : { t3 : 0 } ,
93
+ '--t3 true' : { t3 : true } ,
94
+ '--e1 hello' : { e1 : 'hello' } ,
95
+ '--e1=hello' : { e1 : 'hello' } ,
96
+ '--e1 yellow' : { p1 : 'yellow' , '--' : [ '--e1' ] } ,
97
+ '--e1=yellow' : { '--' : [ '--e1=yellow' ] } ,
98
+ '--e1' : { '--' : [ '--e1' ] } ,
99
+ '--e1 true' : { p1 : 'true' , '--' : [ '--e1' ] } ,
100
+ '--e1=true' : { '--' : [ '--e1=true' ] } ,
101
+ '--e2 hello' : { e2 : 'hello' } ,
102
+ '--e2=hello' : { e2 : 'hello' } ,
103
+ '--e2 yellow' : { p1 : 'yellow' , e2 : '' } ,
104
+ '--e2=yellow' : { '--' : [ '--e2=yellow' ] } ,
105
+ '--e2' : { e2 : '' } ,
106
+ '--e2 true' : { p1 : 'true' , e2 : '' } ,
107
+ '--e2=true' : { '--' : [ '--e2=true' ] } ,
108
+ '--e3 json' : { e3 : 'json' } ,
109
+ '--e3=json' : { e3 : 'json' } ,
110
+ '--e3 yellow' : { p1 : 'yellow' , e3 : true } ,
111
+ '--e3=yellow' : { '--' : [ '--e3=yellow' ] } ,
112
+ '--e3' : { e3 : true } ,
113
+ '--e3 true' : { e3 : true } ,
114
+ '--e3=true' : { e3 : true } ,
64
115
} ;
65
116
66
117
Object . entries ( tests ) . forEach ( ( [ str , expected ] ) => {
0 commit comments