Skip to content

Commit

Permalink
test: add test to ensure HeaderMap::iter safety
Browse files Browse the repository at this point in the history
  • Loading branch information
hjr3 authored and seanmonstar committed Nov 13, 2023
1 parent 60c9b46 commit e5b80c1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/header_map.rs
Expand Up @@ -190,7 +190,7 @@ fn drain_entry() {
assert_eq!(vals[1], "world2");
}

assert_eq!(5-2+1, headers.len());
assert_eq!(5 - 2 + 1, headers.len());
}

#[test]
Expand Down Expand Up @@ -427,7 +427,6 @@ fn value_htab() {
HeaderValue::from_str("hello\tworld").unwrap();
}


#[test]
fn remove_multiple_a() {
let mut headers = HeaderMap::new();
Expand Down Expand Up @@ -570,7 +569,8 @@ fn remove_entry_multi_3_others() {
}

fn remove_all_values<K>(headers: &mut HeaderMap, key: K) -> Vec<HeaderValue>
where K: IntoHeaderName
where
K: IntoHeaderName,
{
match headers.entry(key) {
Entry::Occupied(e) => e.remove_entry_mult().1.collect(),
Expand Down Expand Up @@ -629,10 +629,22 @@ fn remove_entry_3_others_b() {
}

fn remove_values<K>(headers: &mut HeaderMap, key: K) -> Option<HeaderValue>
where K: IntoHeaderName
where
K: IntoHeaderName,
{
match headers.entry(key) {
Entry::Occupied(e) => Some(e.remove_entry().1),
Entry::Vacant(_) => None,
}
}

#[test]
fn ensure_miri_sharedreadonly_not_violated() {
let mut headers = HeaderMap::new();
headers.insert(
HeaderName::from_static("chunky-trailer"),
HeaderValue::from_static("header data"),
);

let _foo = &headers.iter().next();
}

0 comments on commit e5b80c1

Please sign in to comment.