5
5
const test = require ( 'tape' ) ;
6
6
const { parseArgs } = require ( '../index.js' ) ;
7
7
8
- test ( 'defaultValue must be a boolean when option type is boolean' , ( t ) => {
8
+ test ( 'default must be a boolean when option type is boolean' , ( t ) => {
9
9
const args = [ ] ;
10
- const options = { alpha : { type : 'boolean' , defaultValue : 'not a boolean' } } ;
10
+ const options = { alpha : { type : 'boolean' , default : 'not a boolean' } } ;
11
11
t . throws ( ( ) => {
12
12
parseArgs ( { args, options } ) ;
13
- } , / a l p h a \. d e f a u l t V a l u e m u s t b e B o o l e a n /
13
+ } , / a l p h a \. d e f a u l t m u s t b e B o o l e a n /
14
14
) ;
15
15
t . end ( ) ;
16
16
} ) ;
17
17
18
- test ( 'defaultValue must be a boolean array when option type is boolean and multiple' , ( t ) => {
18
+ test ( 'default must be a boolean array when option type is boolean and multiple' , ( t ) => {
19
19
const args = [ ] ;
20
- const options = { alpha : { type : 'boolean' , multiple : true , defaultValue : 'not an array' } } ;
20
+ const options = { alpha : { type : 'boolean' , multiple : true , default : 'not an array' } } ;
21
21
t . throws ( ( ) => {
22
22
parseArgs ( { args, options } ) ;
23
- } , / a l p h a \. d e f a u l t V a l u e m u s t b e A r r a y /
23
+ } , / a l p h a \. d e f a u l t m u s t b e A r r a y /
24
24
) ;
25
25
t . end ( ) ;
26
26
} ) ;
27
27
28
- test ( 'defaultValue must be a boolean array when option type is string and multiple is true' , ( t ) => {
28
+ test ( 'default must be a boolean array when option type is string and multiple is true' , ( t ) => {
29
29
const args = [ ] ;
30
- const options = { alpha : { type : 'boolean' , multiple : true , defaultValue : [ true , true , 42 ] } } ;
30
+ const options = { alpha : { type : 'boolean' , multiple : true , default : [ true , true , 42 ] } } ;
31
31
t . throws ( ( ) => {
32
32
parseArgs ( { args, options } ) ;
33
- } , / a l p h a \. d e f a u l t V a l u e \[ 2 \] m u s t b e B o o l e a n /
33
+ } , / a l p h a \. d e f a u l t \[ 2 \] m u s t b e B o o l e a n /
34
34
) ;
35
35
t . end ( ) ;
36
36
} ) ;
37
37
38
- test ( 'defaultValue must be a string when option type is string' , ( t ) => {
38
+ test ( 'default must be a string when option type is string' , ( t ) => {
39
39
const args = [ ] ;
40
- const options = { alpha : { type : 'string' , defaultValue : true } } ;
40
+ const options = { alpha : { type : 'string' , default : true } } ;
41
41
t . throws ( ( ) => {
42
42
parseArgs ( { args, options } ) ;
43
- } , / a l p h a \. d e f a u l t V a l u e m u s t b e S t r i n g /
43
+ } , / a l p h a \. d e f a u l t m u s t b e S t r i n g /
44
44
) ;
45
45
t . end ( ) ;
46
46
} ) ;
47
47
48
- test ( 'defaultValue must be an array when option type is string and multiple is true' , ( t ) => {
48
+ test ( 'default must be an array when option type is string and multiple is true' , ( t ) => {
49
49
const args = [ ] ;
50
- const options = { alpha : { type : 'string' , multiple : true , defaultValue : 'not an array' } } ;
50
+ const options = { alpha : { type : 'string' , multiple : true , default : 'not an array' } } ;
51
51
t . throws ( ( ) => {
52
52
parseArgs ( { args, options } ) ;
53
- } , / a l p h a \. d e f a u l t V a l u e m u s t b e A r r a y /
53
+ } , / a l p h a \. d e f a u l t m u s t b e A r r a y /
54
54
) ;
55
55
t . end ( ) ;
56
56
} ) ;
57
57
58
- test ( 'defaultValue must be a string array when option type is string and multiple is true' , ( t ) => {
58
+ test ( 'default must be a string array when option type is string and multiple is true' , ( t ) => {
59
59
const args = [ ] ;
60
- const options = { alpha : { type : 'string' , multiple : true , defaultValue : [ 'str' , 42 ] } } ;
60
+ const options = { alpha : { type : 'string' , multiple : true , default : [ 'str' , 42 ] } } ;
61
61
t . throws ( ( ) => {
62
62
parseArgs ( { args, options } ) ;
63
- } , / a l p h a \. d e f a u l t V a l u e \[ 1 \] m u s t b e S t r i n g /
63
+ } , / a l p h a \. d e f a u l t \[ 1 \] m u s t b e S t r i n g /
64
64
) ;
65
65
t . end ( ) ;
66
66
} ) ;
67
67
68
- test ( 'defaultValue accepted input when multiple is true' , ( t ) => {
68
+ test ( 'default accepted input when multiple is true' , ( t ) => {
69
69
const args = [ '--inputStringArr' , 'c' , '--inputStringArr' , 'd' , '--inputBoolArr' , '--inputBoolArr' ] ;
70
70
const options = {
71
- inputStringArr : { type : 'string' , multiple : true , defaultValue : [ 'a' , 'b' ] } ,
72
- emptyStringArr : { type : 'string' , multiple : true , defaultValue : [ ] } ,
73
- fullStringArr : { type : 'string' , multiple : true , defaultValue : [ 'a' , 'b' ] } ,
74
- inputBoolArr : { type : 'boolean' , multiple : true , defaultValue : [ false , true , false ] } ,
75
- emptyBoolArr : { type : 'boolean' , multiple : true , defaultValue : [ ] } ,
76
- fullBoolArr : { type : 'boolean' , multiple : true , defaultValue : [ false , true , false ] } ,
71
+ inputStringArr : { type : 'string' , multiple : true , default : [ 'a' , 'b' ] } ,
72
+ emptyStringArr : { type : 'string' , multiple : true , default : [ ] } ,
73
+ fullStringArr : { type : 'string' , multiple : true , default : [ 'a' , 'b' ] } ,
74
+ inputBoolArr : { type : 'boolean' , multiple : true , default : [ false , true , false ] } ,
75
+ emptyBoolArr : { type : 'boolean' , multiple : true , default : [ ] } ,
76
+ fullBoolArr : { type : 'boolean' , multiple : true , default : [ false , true , false ] } ,
77
77
} ;
78
78
const expected = { values : { __proto__ : null ,
79
79
inputStringArr : [ 'c' , 'd' ] ,
@@ -88,12 +88,12 @@ test('defaultValue accepted input when multiple is true', (t) => {
88
88
t . end ( ) ;
89
89
} ) ;
90
90
91
- test ( 'when defaultValue is set, the option must be added as result' , ( t ) => {
91
+ test ( 'when default is set, the option must be added as result' , ( t ) => {
92
92
const args = [ ] ;
93
93
const options = {
94
- a : { type : 'string' , defaultValue : 'HELLO' } ,
95
- b : { type : 'boolean' , defaultValue : false } ,
96
- c : { type : 'boolean' , defaultValue : true }
94
+ a : { type : 'string' , default : 'HELLO' } ,
95
+ b : { type : 'boolean' , default : false } ,
96
+ c : { type : 'boolean' , default : true }
97
97
} ;
98
98
const expected = { values : { __proto__ : null , a : 'HELLO' , b : false , c : true } , positionals : [ ] } ;
99
99
@@ -103,12 +103,12 @@ test('when defaultValue is set, the option must be added as result', (t) => {
103
103
t . end ( ) ;
104
104
} ) ;
105
105
106
- test ( 'when defaultValue is set, the args value takes precedence' , ( t ) => {
106
+ test ( 'when default is set, the args value takes precedence' , ( t ) => {
107
107
const args = [ '--a' , 'WORLD' , '--b' , '-c' ] ;
108
108
const options = {
109
- a : { type : 'string' , defaultValue : 'HELLO' } ,
110
- b : { type : 'boolean' , defaultValue : false } ,
111
- c : { type : 'boolean' , defaultValue : true }
109
+ a : { type : 'string' , default : 'HELLO' } ,
110
+ b : { type : 'boolean' , default : false } ,
111
+ c : { type : 'boolean' , default : true }
112
112
} ;
113
113
const expected = { values : { __proto__ : null , a : 'WORLD' , b : true , c : true } , positionals : [ ] } ;
114
114
@@ -118,12 +118,12 @@ test('when defaultValue is set, the args value takes precedence', (t) => {
118
118
t . end ( ) ;
119
119
} ) ;
120
120
121
- test ( 'tokens should not include the defaultValue options' , ( t ) => {
121
+ test ( 'tokens should not include the default options' , ( t ) => {
122
122
const args = [ ] ;
123
123
const options = {
124
- a : { type : 'string' , defaultValue : 'HELLO' } ,
125
- b : { type : 'boolean' , defaultValue : false } ,
126
- c : { type : 'boolean' , defaultValue : true }
124
+ a : { type : 'string' , default : 'HELLO' } ,
125
+ b : { type : 'boolean' , default : false } ,
126
+ c : { type : 'boolean' , default : true }
127
127
} ;
128
128
129
129
const expectedTokens = [ ] ;
@@ -133,13 +133,13 @@ test('tokens should not include the defaultValue options', (t) => {
133
133
t . end ( ) ;
134
134
} ) ;
135
135
136
- test ( 'tokens:true should not include the defaultValue options after the args input' , ( t ) => {
136
+ test ( 'tokens:true should not include the default options after the args input' , ( t ) => {
137
137
const args = [ '--z' , 'zero' , 'positional-item' ] ;
138
138
const options = {
139
139
z : { type : 'string' } ,
140
- a : { type : 'string' , defaultValue : 'HELLO' } ,
141
- b : { type : 'boolean' , defaultValue : false } ,
142
- c : { type : 'boolean' , defaultValue : true }
140
+ a : { type : 'string' , default : 'HELLO' } ,
141
+ b : { type : 'boolean' , default : false } ,
142
+ c : { type : 'boolean' , default : true }
143
143
} ;
144
144
145
145
const expectedTokens = [
@@ -157,7 +157,7 @@ test('proto as default value must be ignored', (t) => {
157
157
const options = Object . create ( null ) ;
158
158
159
159
// eslint-disable-next-line no-proto
160
- options . __proto__ = { type : 'string' , defaultValue : 'HELLO' } ;
160
+ options . __proto__ = { type : 'string' , default : 'HELLO' } ;
161
161
162
162
const result = parseArgs ( { args, options, allowPositionals : true } ) ;
163
163
const expected = { values : { __proto__ : null } , positionals : [ ] } ;
@@ -168,10 +168,10 @@ test('proto as default value must be ignored', (t) => {
168
168
169
169
test ( 'multiple as false should expect a String and not an array' , ( t ) => {
170
170
const args = [ ] ;
171
- const options = { alpha : { type : 'string' , multiple : false , defaultValue : 42 } } ;
171
+ const options = { alpha : { type : 'string' , multiple : false , default : 42 } } ;
172
172
t . throws ( ( ) => {
173
173
parseArgs ( { args, options } ) ;
174
- } , / a l p h a \. d e f a u l t V a l u e m u s t b e S t r i n g /
174
+ } , / a l p h a \. d e f a u l t m u s t b e S t r i n g /
175
175
) ;
176
176
t . end ( ) ;
177
177
} ) ;
0 commit comments