test: add headermap iterator tests

confirmed new tests fail as expected
This commit is contained in:
Rob Ede 2026-03-10 06:31:35 +02:00
parent 245b511dfd
commit 91882861ed
No known key found for this signature in database
GPG Key ID: F5E3FCAA33CBF062
1 changed files with 34 additions and 0 deletions

View File

@ -1160,6 +1160,40 @@ mod tests {
assert!(vals.next().is_none()); assert!(vals.next().is_none());
} }
#[test]
fn iter_len_counts_values() {
let mut map = HeaderMap::new();
map.append(header::SET_COOKIE, HeaderValue::from_static("a=1"));
map.append(header::SET_COOKIE, HeaderValue::from_static("b=2"));
map.append(header::SET_COOKIE, HeaderValue::from_static("c=3"));
assert_eq!(map.iter().count(), 3);
assert_eq!(map.iter().len(), 3);
}
#[test]
fn into_iter_len_counts_values() {
let mut map = HeaderMap::new();
map.append(header::SET_COOKIE, HeaderValue::from_static("a=1"));
map.append(header::SET_COOKIE, HeaderValue::from_static("b=2"));
map.append(header::SET_COOKIE, HeaderValue::from_static("c=3"));
assert_eq!(map.clone().into_iter().count(), 3);
assert_eq!(map.into_iter().len(), 3);
}
#[test]
fn drain_len_counts_values() {
let mut map = HeaderMap::new();
map.append(header::SET_COOKIE, HeaderValue::from_static("a=1"));
map.append(header::SET_COOKIE, HeaderValue::from_static("b=2"));
map.append(header::SET_COOKIE, HeaderValue::from_static("c=3"));
let mut drained = map.clone();
assert_eq!(map.drain().count(), 3);
assert_eq!(drained.drain().len(), 3);
}
fn owned_pair<'a>((name, val): (&'a HeaderName, &'a HeaderValue)) -> (HeaderName, HeaderValue) { fn owned_pair<'a>((name, val): (&'a HeaderName, &'a HeaderValue)) -> (HeaderName, HeaderValue) {
(name.clone(), val.clone()) (name.clone(), val.clone())
} }