mirror of
https://github.com/gay-pizza/jaarg.git
synced 2025-12-19 07:20:18 +00:00
Quick 'n dirty test for const_utf8, also fix count signature
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user