Skip to content

Commit ebda770

Browse files
author
knight42
committed
Add tests for str::replacen
1 parent be2fa70 commit ebda770

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/libcollectionstest/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
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)]

src/libcollectionstest/str.rs

+14
Original file line numberDiff line numberDiff 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]
222236
fn test_replace() {
223237
let a = "a";

0 commit comments

Comments
 (0)