From b3091583ede9b28ff664f5799b5c2b5a48783e69 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Mon, 3 Nov 2025 00:51:28 +1100 Subject: [PATCH] Quick 'n dirty test for const_utf8, also fix count signature --- src/const_utf8.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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); + } + } +}