Skip to content

Commit f0a1ea2

Browse files
committed
Add test for is_char_boundary
1 parent a09f386 commit f0a1ea2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcollectionstest/str.rs

+16
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,22 @@ fn test_slice_fail() {
346346
&"中华Việt Nam"[0..2];
347347
}
348348

349+
350+
#[test]
351+
fn test_is_char_boundary() {
352+
let s = "ศไทย中华Việt Nam β-release 🐱123";
353+
assert!(s.is_char_boundary(0));
354+
assert!(s.is_char_boundary(s.len()));
355+
assert!(!s.is_char_boundary(s.len() + 1));
356+
for (i, ch) in s.char_indices() {
357+
// ensure character locations are boundaries and continuation bytes are not
358+
assert!(s.is_char_boundary(i), "{} is a char boundary in {:?}", i, s);
359+
for j in 1..ch.len_utf8() {
360+
assert!(!s.is_char_boundary(i + j),
361+
"{} should not be a char boundary in {:?}", i + j, s);
362+
}
363+
}
364+
}
349365
const LOREM_PARAGRAPH: &'static str = "\
350366
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis lorem sit amet dolor \
351367
ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis sed orci \

0 commit comments

Comments
 (0)