Created
April 4, 2022 12:11
-
-
Save nuta/3ce3e95a5b17106f802fa704857ee735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn grapheme_iter() { | |
let text = "a👩🔬"; | |
let mut c = unicode_segmentation::GraphemeCursor::new(text.len(), text.len(), true); | |
dbg!(text.len()); | |
dbg!(text.char_indices().map(|(i, c)| (i, c)).collect::<Vec<_>>()); | |
assert_eq!( | |
c.prev_boundary(&text[(text.len() - 4)..], text.len() - 4), | |
Err(GraphemeIncomplete::PrevChunk) | |
); | |
assert_eq!( | |
c.prev_boundary(&text[(text.len() - (4 + 3))..], text.len() - (4 + 3)), | |
Err(GraphemeIncomplete::PreContext(5)) | |
); | |
c.provide_context(&text[0..5], 0); | |
assert_eq!( | |
c.prev_boundary(&text[(text.len() - (4 + 3))..], text.len() - (4 + 3)), | |
Ok(Some(8)) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment