@@ -1567,6 +1567,63 @@ describe('yargs-parser', function () {
1567
1567
Array . isArray ( result [ 'someOption' ] ) . should . equal ( true )
1568
1568
result [ 'someOption' ] . should . deep . equal ( [ 1 , 2 ] )
1569
1569
} )
1570
+
1571
+ // see https://github.com/yargs/yargs-parser/issues/6
1572
+ it ( 'should respect the type `boolean` option for arrays' , function ( ) {
1573
+ var result = parser ( [ '-x=true' , 'false' ] , {
1574
+ array : [ { key : 'x' , boolean : true } ]
1575
+ } )
1576
+ result . should . have . property ( 'x' ) . that . is . an ( 'array' ) . and . to . deep . equal ( [ true , false ] )
1577
+ } )
1578
+
1579
+ it ( 'should respect the type `number` option for arrays' , function ( ) {
1580
+ var result = parser ( [ '-x=5' , '2' ] , {
1581
+ array : [ { key : 'x' , number : true } ]
1582
+ } )
1583
+ result . should . have . property ( 'x' ) . that . is . an ( 'array' ) . and . to . deep . equal ( [ 5 , 2 ] )
1584
+ } )
1585
+
1586
+ it ( 'should respect the type `string` option for arrays' , function ( ) {
1587
+ var result = parser ( [ '-x=5' , '2' ] , {
1588
+ configuration : {
1589
+ 'parse-numbers' : true
1590
+ } ,
1591
+ array : [ { key : 'x' , string : true } ]
1592
+ } )
1593
+ result . should . have . property ( 'x' ) . that . is . an ( 'array' ) . and . to . deep . equal ( [ '5' , '2' ] )
1594
+ } )
1595
+
1596
+ it ( 'should eat non-hyphenated arguments until hyphenated option is hit - combined with coercion' , function ( ) {
1597
+ var result = parser ( [
1598
+ '-a=hello' , 'world' ,
1599
+ '-b' , '33' , '22' ,
1600
+ '--foo' , 'true' , 'false' ,
1601
+ '--bar=cat' , 'dog'
1602
+ ] , {
1603
+ array : [
1604
+ 'a' ,
1605
+ { key : 'b' , integer : true } ,
1606
+ { key : 'foo' , boolean : true } ,
1607
+ 'bar'
1608
+ ]
1609
+ } )
1610
+
1611
+ Array . isArray ( result . a ) . should . equal ( true )
1612
+ result . a . should . include ( 'hello' )
1613
+ result . a . should . include ( 'world' )
1614
+
1615
+ Array . isArray ( result . b ) . should . equal ( true )
1616
+ result . b . should . include ( 33 )
1617
+ result . b . should . include ( 22 )
1618
+
1619
+ Array . isArray ( result . foo ) . should . equal ( true )
1620
+ result . foo . should . include ( true )
1621
+ result . foo . should . include ( false )
1622
+
1623
+ Array . isArray ( result . bar ) . should . equal ( true )
1624
+ result . bar . should . include ( 'cat' )
1625
+ result . bar . should . include ( 'dog' )
1626
+ } )
1570
1627
} )
1571
1628
1572
1629
describe ( 'nargs' , function ( ) {
0 commit comments