Skip to content

Commit

Permalink
Add test for is_char_boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Apr 10, 2016
1 parent a09f386 commit f0a1ea2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libcollectionstest/str.rs
Expand Up @@ -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 \
Expand Down

0 comments on commit f0a1ea2

Please sign in to comment.