File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 2121#![ feature( rand) ]
2222#![ feature( step_by) ]
2323#![ feature( str_escape) ]
24+ #![ feature( str_replacen) ]
2425#![ feature( test) ]
2526#![ feature( unboxed_closures) ]
2627#![ feature( unicode) ]
Original file line number Diff line number Diff line change @@ -218,6 +218,20 @@ fn test_is_empty() {
218218 assert ! ( !"a" . is_empty( ) ) ;
219219}
220220
221+ #[ test]
222+ fn test_replacen ( ) {
223+ assert_eq ! ( "" . replacen( 'a' , "b" , 5 ) , "" ) ;
224+ assert_eq ! ( "acaaa" . replacen( "a" , "b" , 3 ) , "bcbba" ) ;
225+ assert_eq ! ( "aaaa" . replacen( "a" , "b" , 0 ) , "aaaa" ) ;
226+
227+ let test = "test" ;
228+ assert_eq ! ( " test test " . replacen( test, "toast" , 3 ) , " toast toast " ) ;
229+ assert_eq ! ( " test test " . replacen( test, "toast" , 0 ) , " test test " ) ;
230+ assert_eq ! ( " test test " . replacen( test, "" , 5 ) , " " ) ;
231+
232+ assert_eq ! ( "qwer123zxc789" . replacen( char :: is_numeric, "" , 3 ) , "qwerzxc789" ) ;
233+ }
234+
221235#[ test]
222236fn test_replace ( ) {
223237 let a = "a" ;
You can’t perform that action at this time.
0 commit comments