@@ -603,26 +603,39 @@ describe("constructOpenOptions", () => {
603
603
} )
604
604
605
605
describe ( "splitOnFirstEquals" , ( ) => {
606
- it ( "should split on the first equals" , ( ) => {
607
- const testStr = "enabled-proposed-api=test=value"
608
- const actual = util . splitOnFirstEquals ( testStr )
609
- const expected = [ "enabled-proposed-api" , "test=value" ]
610
- expect ( actual ) . toEqual ( expect . arrayContaining ( expected ) )
611
- } )
612
- it ( "should split on first equals regardless of multiple equals signs" , ( ) => {
613
- const testStr =
614
- "hashed-password=$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY"
615
- const actual = util . splitOnFirstEquals ( testStr )
616
- const expected = [
617
- "hashed-password" ,
618
- "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY" ,
619
- ]
620
- expect ( actual ) . toEqual ( expect . arrayContaining ( expected ) )
621
- } )
622
- it ( "should always return the first element before an equals" , ( ) => {
623
- const testStr = "auth="
624
- const actual = util . splitOnFirstEquals ( testStr )
625
- const expected = [ "auth" ]
626
- expect ( actual ) . toEqual ( expect . arrayContaining ( expected ) )
606
+ const tests = [
607
+ {
608
+ name : "empty" ,
609
+ key : "" ,
610
+ value : "" ,
611
+ } ,
612
+ {
613
+ name : "split on first equals" ,
614
+ key : "foo" ,
615
+ value : "bar" ,
616
+ } ,
617
+ {
618
+ name : "split on first equals even with multiple equals" ,
619
+ key : "foo" ,
620
+ value : "bar=baz" ,
621
+ } ,
622
+ {
623
+ name : "split with empty value" ,
624
+ key : "foo" ,
625
+ value : "" ,
626
+ } ,
627
+ {
628
+ name : "split with no value" ,
629
+ key : "foo" ,
630
+ value : undefined ,
631
+ } ,
632
+ ]
633
+ tests . forEach ( ( test ) => {
634
+ it ( "should ${test.name}" , ( ) => {
635
+ const input = test . key && typeof test . value !== "undefined" ? `${ test . key } =${ test . value } ` : test . key
636
+ const [ key , value ] = util . splitOnFirstEquals ( input )
637
+ expect ( key ) . toStrictEqual ( test . key )
638
+ expect ( value ) . toStrictEqual ( test . value || undefined )
639
+ } )
627
640
} )
628
641
} )
0 commit comments