@@ -19,11 +19,23 @@ describe('parseArguments', () => {
1919 { name : 'arr' , aliases : [ 'a' ] , type : OptionType . Array , description : '' } ,
2020 { name : 'p1' , positional : 0 , aliases : [ ] , type : OptionType . String , description : '' } ,
2121 { 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 : '' } ,
2233 ] ;
2334
2435 const tests : { [ test : string ] : Partial < Arguments > } = {
2536 '--bool' : { bool : true } ,
26- '--bool=1' : { bool : true } ,
37+ '--bool=1' : { '--' : [ '--bool=1' ] } ,
38+ '--bool=yellow' : { '--' : [ '--bool=yellow' ] } ,
2739 '--bool=true' : { bool : true } ,
2840 '--bool=false' : { bool : false } ,
2941 '--no-bool' : { bool : false } ,
@@ -33,7 +45,7 @@ describe('parseArguments', () => {
3345 '--b true' : { bool : true } ,
3446 '--b false' : { bool : false } ,
3547 '--bool --num' : { bool : true , num : 0 } ,
36- '--bool --num=true' : { bool : true } ,
48+ '--bool --num=true' : { bool : true , '--' : [ '--num=true' ] } ,
3749 '--bool=true --num' : { bool : true , num : 0 } ,
3850 '--bool true --num' : { bool : true , num : 0 } ,
3951 '--bool=false --num' : { bool : false , num : 0 } ,
@@ -51,16 +63,55 @@ describe('parseArguments', () => {
5163 '--bool val1 --etc --num val2 --v' : { bool : true , num : 0 , p1 : 'val1' , p2 : 'val2' ,
5264 '--' : [ '--etc' , '--v' ] } ,
5365 '--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' } ,
5568 '--str=1' : { str : '1' } ,
5669 '--hello-world=1' : { helloWorld : '1' } ,
5770 '--hello-bool' : { helloBool : true } ,
5871 '--helloBool' : { helloBool : true } ,
5972 '--no-helloBool' : { helloBool : false } ,
6073 '--noHelloBool' : { helloBool : false } ,
74+ '--noBool' : { bool : false } ,
6175 '-b' : { bool : true } ,
6276 '-sb' : { bool : true , str : '' } ,
6377 '-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 } ,
64115 } ;
65116
66117 Object . entries ( tests ) . forEach ( ( [ str , expected ] ) => {
0 commit comments