@@ -2191,7 +2191,7 @@ describe('yargs-parser', function () {
21912191
21922192 parsed [ 'x' ] . should . deep . equal ( [ 'a' , 'b' ] )
21932193 } )
2194- it ( 'keeps only last argument' , function ( ) {
2194+ it ( 'string: keeps only last argument' , function ( ) {
21952195 var parsed = parser ( '-x a -x b' , {
21962196 configuration : {
21972197 'duplicate-arguments-array' : false
@@ -2200,6 +2200,26 @@ describe('yargs-parser', function () {
22002200
22012201 parsed [ 'x' ] . should . equal ( 'b' )
22022202 } )
2203+ it ( 'array[string]: keeps only last argument' , function ( ) {
2204+ var parsed = parser ( '-x a -x b' , {
2205+ configuration : {
2206+ array : [ { key : 'x' , string : true } ] ,
2207+ 'duplicate-arguments-array' : false
2208+ }
2209+ } )
2210+
2211+ parsed [ 'x' ] . should . equal ( 'b' )
2212+ } )
2213+ it ( 'array[number]: keeps only last argument' , function ( ) {
2214+ var parsed = parser ( '-x 1 -x 2' , {
2215+ configuration : {
2216+ array : [ { key : 'x' , number : true } ] ,
2217+ 'duplicate-arguments-array' : false
2218+ }
2219+ } )
2220+
2221+ parsed [ 'x' ] . should . equal ( 2 )
2222+ } )
22032223 it ( 'does not interfere with nargs' , function ( ) {
22042224 var parsed = parser ( '-x a b c -x o p q' , {
22052225 narg : { x : 3 } ,
@@ -2405,25 +2425,25 @@ describe('yargs-parser', function () {
24052425 } )
24062426 describe ( 'duplicate=true, flatten=false,' , function ( ) {
24072427 describe ( 'type=array' , function ( ) {
2408- it ( '[-x 1 -x 2 -x 3] => [1, 2, 3 ]' , function ( ) {
2428+ it ( 'number: [-x 1 -x 2 -x 3] => [[1], [2], [3] ]' , function ( ) {
24092429 var parsed = parser ( '-x 1 -x 2 -x 3' , {
2410- array : [ 'x' ] ,
2430+ array : [ { key : 'x' , number : true } ] ,
24112431 configuration : {
24122432 'duplicate-arguments-array' : true ,
24132433 'flatten-duplicate-arrays' : false
24142434 }
24152435 } )
2416- parsed [ 'x' ] . should . deep . equal ( [ 1 , 2 , 3 ] )
2436+ parsed [ 'x' ] . should . deep . equal ( [ [ 1 ] , [ 2 ] , [ 3 ] ] )
24172437 } )
2418- it ( ' [-x 1 2 3 -x 2 3 4 ] => [[1, 2, 3 ], [ 2, 3, 4]]' , function ( ) {
2419- var parsed = parser ( '-x 1 2 3 -x 2 3 4 ' , {
2420- array : [ 'x' ] ,
2438+ it ( "string: [-x 1 -x 2 -x 3 ] => [['1' ], ['2'], ['3']]" , function ( ) {
2439+ var parsed = parser ( '-x 1 -x 2 -x 3 ' , {
2440+ array : [ { key : 'x' , string : true } ] ,
24212441 configuration : {
24222442 'duplicate-arguments-array' : true ,
24232443 'flatten-duplicate-arrays' : false
24242444 }
24252445 } )
2426- parsed [ 'x' ] . should . deep . equal ( [ [ 1 , 2 , 3 ] , [ 2 , 3 , 4 ] ] )
2446+ parsed [ 'x' ] . should . deep . equal ( [ [ '1' ] , [ '2' ] , [ '3' ] ] )
24272447 } )
24282448 } )
24292449 describe ( 'type=number' , function ( ) {
0 commit comments