diff --git a/src/const_utf8.rs b/src/const_utf8.rs index a3fc667..ff7cc9d 100644 --- a/src/const_utf8.rs +++ b/src/const_utf8.rs @@ -24,7 +24,7 @@ impl<'a> CharIterator<'a> { impl CharIterator<'_> { /// Gets a count of the number of Unicode characters (not graphemes) in the string. - pub(crate) const fn count(self) -> usize { + pub(crate) const fn count(&self) -> usize { let len = self.bytes.len(); let mut count = 0; let mut i = 0; @@ -123,3 +123,19 @@ impl CharIterator<'_> { Some(result) } } + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test() { + for s in ["pizza", "/ˈpitt͡sə/", "pizzaskjærer", "🍕", "比薩", "ピザ", "Ćevapi", "🏳️‍⚧️"] { + let mut it = CharIterator::from(s); + assert_eq!(it.count(), s.chars().count()); + s.chars().for_each(|c| assert_eq!(it.next(), Some(c))); + assert_eq!(it.next(), None); + } + } +}