Skip to content

Commit

Permalink
Add a test for char::DecodeUtf16::size_hint
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Jan 26, 2022
1 parent cd4245d commit 9c8cd1f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions library/core/tests/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,31 @@ fn test_decode_utf16() {
check(&[0xD800, 0], &[Err(0xD800), Ok('\0')]);
}

#[test]
fn test_decode_utf16_size_hint() {
fn check(s: &[u16]) {
let mut iter = char::decode_utf16(s.iter().cloned());

loop {
let count = iter.clone().count();
let (lower, upper) = iter.size_hint();

assert!(
lower <= count && count <= upper.unwrap(),
"lower = {lower}, upper = {upper:?}"
);

if let None = iter.next() {
break;
}
}
}

check(&[0xD800, 0x41, 0x42]);
check(&[0xD800, 0]);
check(&[0xD834, 0x006d]);
}

#[test]
fn ed_iterator_specializations() {
// Check counting
Expand Down

0 comments on commit 9c8cd1f

Please sign in to comment.