Skip to content

Instantly share code, notes, and snippets.

@nuta
Created April 4, 2022 12:11
Show Gist options
  • Save nuta/3ce3e95a5b17106f802fa704857ee735 to your computer and use it in GitHub Desktop.
Save nuta/3ce3e95a5b17106f802fa704857ee735 to your computer and use it in GitHub Desktop.
#[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