@@ -3301,4 +3301,37 @@ describe('yargs-parser', function () {
3301
3301
expect ( { } . foo ) . to . equal ( undefined )
3302
3302
expect ( { } . bar ) . to . equal ( undefined )
3303
3303
} )
3304
+
3305
+ // Refs: https://github.com/yargs/yargs-parser/issues/386
3306
+ describe ( 'perf' , ( ) => {
3307
+ const i = 100000
3308
+ describe ( 'unknown-options-as-args' , ( ) => {
3309
+ it ( 'parses long chain of "-" with reasonable performance' , function ( ) {
3310
+ this . timeout ( 500 )
3311
+ const s = ( new Array ( i ) . fill ( '-' ) . join ( '' ) ) + 'a'
3312
+ const parsed = parser ( [ s ] , { configuration : { 'unknown-options-as-args' : true } } )
3313
+ parsed . _ [ 0 ] . should . equal ( s )
3314
+ } )
3315
+ it ( 'parses long chain of "-a-a" with reasonable performance' , function ( ) {
3316
+ this . timeout ( 500 )
3317
+ const s = '-' + ( new Array ( i ) . fill ( '-a' ) . join ( '' ) ) + '=35'
3318
+ const parsed = parser ( [ s ] , { configuration : { 'unknown-options-as-args' : true } } )
3319
+ parsed . _ [ 0 ] . should . equal ( s )
3320
+ } )
3321
+ } )
3322
+ it ( 'parses long chain of "-" with reasonable performance' , function ( ) {
3323
+ this . timeout ( 500 )
3324
+ const s = ( new Array ( i ) . fill ( '-' ) . join ( '' ) ) + 'a'
3325
+ const arg = ( new Array ( i - 2 ) . fill ( '-' ) . join ( '' ) ) + 'a'
3326
+ const parsed = parser ( [ s ] )
3327
+ parsed [ arg ] . should . equal ( true )
3328
+ } )
3329
+ it ( 'parses long chain of "-a-a" with reasonable performance' , function ( ) {
3330
+ this . timeout ( 500 )
3331
+ const s = '-' + ( new Array ( i ) . fill ( '-a' ) . join ( '' ) ) + '=35'
3332
+ const arg = 'a' + ( new Array ( i - 1 ) . fill ( 'A' ) . join ( '' ) )
3333
+ const parsed = parser ( [ s ] )
3334
+ parsed [ arg ] . should . equal ( 35 )
3335
+ } )
3336
+ } )
3304
3337
} )
0 commit comments