@@ -351,4 +351,34 @@ mod tests {
351
351
"fn main() {\n return 92;\n }\n "
352
352
) ;
353
353
}
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
+ }
354
384
}
0 commit comments