about summary refs log tree commit diff
diff options
context:
space:
mode:
authorknight42 <knight42@mail.ustc.edu.cn>2016-09-08 18:55:04 +0800
committerknight42 <knight42@mail.ustc.edu.cn>2016-09-13 10:16:31 +0800
commitebda77072a56a43d33d5723196a5ae37544a1ab9 (patch)
tree85e268b1e577f7b269e57a440897f593d8586282
parentbe2fa70c1604f4383463fa4e64cd9f4567ff47e8 (diff)
downloadrust-ebda77072a56a43d33d5723196a5ae37544a1ab9.tar.gz
rust-ebda77072a56a43d33d5723196a5ae37544a1ab9.zip
Add tests for str::replacen
-rw-r--r--src/libcollectionstest/lib.rs1
-rw-r--r--src/libcollectionstest/str.rs14
2 files changed, 15 insertions, 0 deletions
diff --git a/src/libcollectionstest/lib.rs b/src/libcollectionstest/lib.rs
index 32a07e3e7e6..878581a4f29 100644
--- a/src/libcollectionstest/lib.rs
+++ b/src/libcollectionstest/lib.rs
@@ -21,6 +21,7 @@
 #![feature(rand)]
 #![feature(step_by)]
 #![feature(str_escape)]
+#![feature(str_replacen)]
 #![feature(test)]
 #![feature(unboxed_closures)]
 #![feature(unicode)]
diff --git a/src/libcollectionstest/str.rs b/src/libcollectionstest/str.rs
index a61925cd3be..62e164a569a 100644
--- a/src/libcollectionstest/str.rs
+++ b/src/libcollectionstest/str.rs
@@ -219,6 +219,20 @@ fn test_is_empty() {
 }
 
 #[test]
+fn test_replacen() {
+    assert_eq!("".replacen('a', "b", 5), "");
+    assert_eq!("acaaa".replacen("a", "b", 3), "bcbba");
+    assert_eq!("aaaa".replacen("a", "b", 0), "aaaa");
+
+    let test = "test";
+    assert_eq!(" test test ".replacen(test, "toast", 3), " toast toast ");
+    assert_eq!(" test test ".replacen(test, "toast", 0), " test test ");
+    assert_eq!(" test test ".replacen(test, "", 5), "   ");
+
+    assert_eq!("qwer123zxc789".replacen(char::is_numeric, "", 3), "qwerzxc789");
+}
+
+#[test]
 fn test_replace() {
     let a = "a";
     assert_eq!("".replace(a, "b"), "");