Quick 'n dirty test for const_utf8, also fix count signature

This commit is contained in:
2025-11-03 00:51:28 +11:00
parent ae7c12ad62
commit b3091583ed

View File

@@ -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);
}
}
}