@@ -68,19 +68,108 @@ test('args are passed "withValue" and "multiples"', function (t) {
6868 t . end ( )
6969} )
7070
71+ test ( 'correct default args when use node -p' , function ( t ) {
72+ const holdArgv = process . argv ;
73+ process . argv = [ process . argv0 , '--foo' ] ;
74+ const holdExecArgv = process . execArgv ;
75+ process . execArgv = [ '-p' , '0' ] ;
76+ const result = parseArgs ( ) ;
77+
78+ const expected = { flags : { foo : true } ,
79+ values : { foo : [ undefined ] } ,
80+ positionals : [ ] } ;
81+ t . deepEqual ( result , expected ) ;
82+
83+ t . end ( ) ;
84+ process . argv = holdArgv ;
85+ process . execArgv = holdExecArgv ;
86+ } ) ;
87+
88+ test ( 'correct default args when use node --print' , function ( t ) {
89+ const holdArgv = process . argv ;
90+ process . argv = [ process . argv0 , '--foo' ] ;
91+ const holdExecArgv = process . execArgv ;
92+ process . execArgv = [ '--print' , '0' ] ;
93+ const result = parseArgs ( ) ;
94+
95+ const expected = { flags : { foo : true } ,
96+ values : { foo : [ undefined ] } ,
97+ positionals : [ ] } ;
98+ t . deepEqual ( result , expected ) ;
99+
100+ t . end ( ) ;
101+ process . argv = holdArgv ;
102+ process . execArgv = holdExecArgv ;
103+ } ) ;
104+
105+ test ( 'correct default args when use node -e' , function ( t ) {
106+ const holdArgv = process . argv ;
107+ process . argv = [ process . argv0 , '--foo' ] ;
108+ const holdExecArgv = process . execArgv ;
109+ process . execArgv = [ '-e' , '0' ] ;
110+ const result = parseArgs ( ) ;
111+
112+ const expected = { flags : { foo : true } ,
113+ values : { foo : [ undefined ] } ,
114+ positionals : [ ] } ;
115+ t . deepEqual ( result , expected ) ;
116+
117+ t . end ( ) ;
118+ process . argv = holdArgv ;
119+ process . execArgv = holdExecArgv ;
120+ } ) ;
121+
122+ test ( 'correct default args when use node --eval' , function ( t ) {
123+ const holdArgv = process . argv ;
124+ process . argv = [ process . argv0 , '--foo' ] ;
125+ const holdExecArgv = process . execArgv ;
126+ process . execArgv = [ '--eval' , '0' ] ;
127+ const result = parseArgs ( ) ;
128+
129+ const expected = { flags : { foo : true } ,
130+ values : { foo : [ undefined ] } ,
131+ positionals : [ ] } ;
132+ t . deepEqual ( result , expected ) ;
133+
134+ t . end ( ) ;
135+ process . argv = holdArgv ;
136+ process . execArgv = holdExecArgv ;
137+ } ) ;
138+
139+ test ( 'correct default args when normal arguments' , function ( t ) {
140+ const holdArgv = process . argv ;
141+ process . argv = [ process . argv0 , 'script.js' , '--foo' ] ;
142+ const holdExecArgv = process . execArgv ;
143+ process . execArgv = [ ] ;
144+ const result = parseArgs ( ) ;
145+
146+ const expected = { flags : { foo : true } ,
147+ values : { foo : [ undefined ] } ,
148+ positionals : [ ] } ;
149+ t . deepEqual ( result , expected ) ;
150+
151+ t . end ( ) ;
152+ process . argv = holdArgv ;
153+ process . execArgv = holdExecArgv ;
154+ } ) ;
155+
71156test ( 'excess leading dashes on options are retained' , function ( t ) {
72157 // Enforce a design decision for an edge case.
73158 const passedArgs = [ '---triple' ] ;
74159 const passedOptions = { } ;
75- const expected = { flags : { '-triple' : true } , values : { '-triple' : [ undefined ] } , positionals : [ ] } ;
76- const args = parseArgs ( passedArgs , passedOptions ) ;
160+ const expected = {
161+ flags : { '-triple' : true } ,
162+ values : { '-triple' : [ undefined ] } ,
163+ positionals : [ ]
164+ } ;
165+ const result = parseArgs ( passedArgs , passedOptions ) ;
77166
78- t . deepEqual ( args , expected , 'excess option dashes are retained' ) ;
167+ t . deepEqual ( result , expected , 'excess option dashes are retained' ) ;
79168
80169 t . end ( ) ;
81170} ) ;
82171
83- //Test bad inputs
172+ // Test bad inputs
84173
85174test ( 'boolean passed to "withValue" option' , function ( t ) {
86175 const passedArgs = [ '--so=wat' ]
0 commit comments