about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2016-04-14 14:49:09 -0400
committerSteve Klabnik <steve@steveklabnik.com>2016-04-14 14:49:09 -0400
commit657cae03e912b0b2548a2fcfe8811c3e69dc7684 (patch)
tree55662a0cd7aa9d92afa2b659af8549f9fa5629bd
parentc353eae4ac4707441afe1aa5ec6c41bd7a63a0a8 (diff)
parentf0a1ea27ccf17e2f63c496e868aa7614842c077b (diff)
Rollup merge of #32869 - bluss:char-boundary-test, r=brson
Add test for is_char_boundary

Add test for is_char_boundary

Apparently there was no test for this method. This test is rather simple, not exhaustive.
-rw-r--r--src/libcollectionstest/str.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcollectionstest/str.rs b/src/libcollectionstest/str.rs
index 929ac7a52ab..a1820a1cb96 100644
--- a/src/libcollectionstest/str.rs
+++ b/src/libcollectionstest/str.rs
@@ -346,6 +346,22 @@ fn test_slice_fail() {
     &"中华Việt Nam"[0..2];
 }
 
+
+#[test]
+fn test_is_char_boundary() {
+    let s = "ศไทย中华Việt Nam β-release 🐱123";
+    assert!(s.is_char_boundary(0));
+    assert!(s.is_char_boundary(s.len()));
+    assert!(!s.is_char_boundary(s.len() + 1));
+    for (i, ch) in s.char_indices() {
+        // ensure character locations are boundaries and continuation bytes are not
+        assert!(s.is_char_boundary(i), "{} is a char boundary in {:?}", i, s);
+        for j in 1..ch.len_utf8() {
+            assert!(!s.is_char_boundary(i + j),
+                    "{} should not be a char boundary in {:?}", i + j, s);
+        }
+    }
+}
 const LOREM_PARAGRAPH: &'static str = "\
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis lorem sit amet dolor \
 ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis sed orci \