@@ -3963,4 +3963,37 @@ describe('yargs-parser', function () {
3963
3963
} ) . to . throw ( / y a r g s p a r s e r s u p p o r t s a m i n i m u m N o d e .j s v e r s i o n o f 5 5 / )
3964
3964
delete process . env . YARGS_MIN_NODE_VERSION
3965
3965
} )
3966
+
3967
+ // Refs: https://github.com/yargs/yargs-parser/issues/386
3968
+ describe ( 'perf' , ( ) => {
3969
+ const i = 100000
3970
+ describe ( 'unknown-options-as-args' , ( ) => {
3971
+ it ( 'parses long chain of "-" with reasonable performance' , function ( ) {
3972
+ this . timeout ( 500 )
3973
+ const s = ( new Array ( i ) . fill ( '-' ) . join ( '' ) ) + 'a'
3974
+ const parsed = parser ( [ s ] , { configuration : { 'unknown-options-as-args' : true } } )
3975
+ parsed . _ [ 0 ] . should . equal ( s )
3976
+ } )
3977
+ it ( 'parses long chain of "-a-a" with reasonable performance' , function ( ) {
3978
+ this . timeout ( 500 )
3979
+ const s = '-' + ( new Array ( i ) . fill ( '-a' ) . join ( '' ) ) + '=35'
3980
+ const parsed = parser ( [ s ] , { configuration : { 'unknown-options-as-args' : true } } )
3981
+ parsed . _ [ 0 ] . should . equal ( s )
3982
+ } )
3983
+ } )
3984
+ it ( 'parses long chain of "-" with reasonable performance' , function ( ) {
3985
+ this . timeout ( 500 )
3986
+ const s = ( new Array ( i ) . fill ( '-' ) . join ( '' ) ) + 'a'
3987
+ const arg = ( new Array ( i - 2 ) . fill ( '-' ) . join ( '' ) ) + 'a'
3988
+ const parsed = parser ( [ s ] )
3989
+ parsed [ arg ] . should . equal ( true )
3990
+ } )
3991
+ it ( 'parses long chain of "-a-a" with reasonable performance' , function ( ) {
3992
+ this . timeout ( 500 )
3993
+ const s = '-' + ( new Array ( i ) . fill ( '-a' ) . join ( '' ) ) + '=35'
3994
+ const arg = 'a' + ( new Array ( i - 1 ) . fill ( 'A' ) . join ( '' ) )
3995
+ const parsed = parser ( [ s ] )
3996
+ parsed [ arg ] . should . equal ( 35 )
3997
+ } )
3998
+ } )
3966
3999
} )
0 commit comments