@@ -351,4 +351,34 @@ mod tests {
351351 "fn main() {\n return 92;\n }\n "
352352 ) ;
353353 }
354+
355+ #[ test]
356+ fn test_replace ( ) {
357+ #[ track_caller]
358+ fn test_replace ( src : & str , from : char , to : & str , expected : & str ) {
359+ let mut s = src. to_owned ( ) ;
360+ replace ( & mut s, from, to) ;
361+ assert_eq ! ( s, expected, "from: {from:?}, to: {to:?}" ) ;
362+ }
363+
364+ test_replace ( "" , 'a' , "b" , "" ) ;
365+ test_replace ( "" , 'a' , "😀" , "" ) ;
366+ test_replace ( "" , '😀' , "a" , "" ) ;
367+ test_replace ( "a" , 'a' , "b" , "b" ) ;
368+ test_replace ( "aa" , 'a' , "b" , "bb" ) ;
369+ test_replace ( "ada" , 'a' , "b" , "bdb" ) ;
370+ test_replace ( "a" , 'a' , "😀" , "😀" ) ;
371+ test_replace ( "😀" , '😀' , "a" , "a" ) ;
372+ test_replace ( "😀x" , '😀' , "a" , "ax" ) ;
373+ test_replace ( "y😀x" , '😀' , "a" , "yax" ) ;
374+ test_replace ( "a,b,c" , ',' , "." , "a.b.c" ) ;
375+ test_replace ( "a,b,c" , ',' , ".." , "a..b..c" ) ;
376+ test_replace ( "a.b.c" , '.' , ".." , "a..b..c" ) ;
377+ test_replace ( "a.b.c" , '.' , ".." , "a..b..c" ) ;
378+ test_replace ( "a😀b😀c" , '😀' , "." , "a.b.c" ) ;
379+ test_replace ( "a.b.c" , '.' , "😀" , "a😀b😀c" ) ;
380+ test_replace ( "a.b.c" , '.' , "😀😀" , "a😀😀b😀😀c" ) ;
381+ test_replace ( ".a.b.c." , '.' , "()" , "()a()b()c()" ) ;
382+ test_replace ( ".a.b.c." , '.' , "" , "abc" ) ;
383+ }
354384}
0 commit comments