@@ -6,6 +6,70 @@ const { parseArgs } = require('../index.js');
66
77// Test results are as we expect
88
9+ test ( 'when short option used as flag then stored as flag' , function ( t ) {
10+ const passedArgs = [ '-f' ] ;
11+ const expected = { flags : { f : true } , values : { f : undefined } , positionals : [ ] } ;
12+ const args = parseArgs ( passedArgs ) ;
13+
14+ t . deepEqual ( args , expected ) ;
15+
16+ t . end ( ) ;
17+ } ) ;
18+
19+ test ( 'when short option used as flag before positional then stored as flag and positional (and not value)' , function ( t ) {
20+ const passedArgs = [ '-f' , 'bar' ] ;
21+ const expected = { flags : { f : true } , values : { f : undefined } , positionals : [ 'bar' ] } ;
22+ const args = parseArgs ( passedArgs ) ;
23+
24+ t . deepEqual ( args , expected ) ;
25+
26+ t . end ( ) ;
27+ } ) ;
28+
29+ test ( 'when short option withValue used with value then stored as value' , function ( t ) {
30+ const passedArgs = [ '-f' , 'bar' ] ;
31+ const passedOptions = { withValue : [ 'f' ] } ;
32+ const expected = { flags : { f : true } , values : { f : 'bar' } , positionals : [ ] } ;
33+ const args = parseArgs ( passedArgs , passedOptions ) ;
34+
35+ t . deepEqual ( args , expected ) ;
36+
37+ t . end ( ) ;
38+ } ) ;
39+
40+ test ( 'when short option listed in short used as flag then long option stored as flag' , function ( t ) {
41+ const passedArgs = [ '-f' ] ;
42+ const passedOptions = { short : { f : 'foo' } } ;
43+ const expected = { flags : { foo : true } , values : { foo : undefined } , positionals : [ ] } ;
44+ const args = parseArgs ( passedArgs , passedOptions ) ;
45+
46+ t . deepEqual ( args , expected ) ;
47+
48+ t . end ( ) ;
49+ } ) ;
50+
51+ test ( 'when short option listed in short and long listed in withValue and used with value then long option stored as value' , function ( t ) {
52+ const passedArgs = [ '-f' , 'bar' ] ;
53+ const passedOptions = { short : { f : 'foo' } , withValue : [ 'foo' ] } ;
54+ const expected = { flags : { foo : true } , values : { foo : 'bar' } , positionals : [ ] } ;
55+ const args = parseArgs ( passedArgs , passedOptions ) ;
56+
57+ t . deepEqual ( args , expected ) ;
58+
59+ t . end ( ) ;
60+ } ) ;
61+
62+ test ( 'when short option withValue used without value then stored as flag' , function ( t ) {
63+ const passedArgs = [ '-f' ] ;
64+ const passedOptions = { withValue : [ 'f' ] } ;
65+ const expected = { flags : { f : true } , values : { f : undefined } , positionals : [ ] } ;
66+ const args = parseArgs ( passedArgs , passedOptions ) ;
67+
68+ t . deepEqual ( args , expected ) ;
69+
70+ t . end ( ) ;
71+ } ) ;
72+
973test ( 'Everything after a bare `--` is considered a positional argument' , function ( t ) {
1074 const passedArgs = [ '--' , 'barepositionals' , 'mopositionals' ] ;
1175 const expected = { flags : { } , values : { } , positionals : [ 'barepositionals' , 'mopositionals' ] } ;
0 commit comments