@@ -79,12 +79,25 @@ test.each([
7979 { inp : "hello test" , searchValue : "hello" , replaceValue : "" } ,
8080 { inp : "hello test" , searchValue : "test" , replaceValue : "" } ,
8181 { inp : "hello test" , searchValue : "test" , replaceValue : "world" } ,
82+ { inp : "hello test" , searchValue : "test" , replaceValue : "%world" } ,
83+ { inp : "hello %test" , searchValue : "test" , replaceValue : "world" } ,
84+ { inp : "hello %test" , searchValue : "%test" , replaceValue : "world" } ,
85+ { inp : "hello test" , searchValue : "test" , replaceValue : ( ) : string => "a" } ,
86+ { inp : "hello test" , searchValue : "test" , replaceValue : ( ) : string => "%a" } ,
87+ { inp : "aaa" , searchValue : "a" , replaceValue : "b" } ,
8288] ) ( "string.replace (%p)" , ( { inp, searchValue, replaceValue } ) => {
89+ const replaceValueString =
90+ typeof replaceValue === "string" ? JSON . stringify ( replaceValue ) : replaceValue . toString ( ) ;
8391 const result = util . transpileAndExecute (
84- `return "${ inp } ".replace("${ searchValue } ", " ${ replaceValue } " );` ,
92+ `return "${ inp } ".replace("${ searchValue } ", ${ replaceValueString } );` ,
8593 ) ;
8694
87- expect ( result ) . toBe ( inp . replace ( searchValue , replaceValue ) ) ;
95+ // https://github.com/Microsoft/TypeScript/issues/22378
96+ if ( typeof replaceValue === "string" ) {
97+ expect ( result ) . toBe ( inp . replace ( searchValue , replaceValue ) ) ;
98+ } else {
99+ expect ( result ) . toBe ( inp . replace ( searchValue , replaceValue ) ) ;
100+ }
88101} ) ;
89102
90103test . each ( [
0 commit comments