Skip to content

Commit 2c247d0

Browse files
committed
test repeated HeaderMap::remove for comparison
1 parent 5575c13 commit 2c247d0

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/header_map.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,57 @@ fn value_htab() {
425425
HeaderValue::from_str("hello\tworld").unwrap();
426426
}
427427

428+
429+
#[test]
430+
fn remove_multiple_a() {
431+
let mut headers = HeaderMap::new();
432+
headers.insert(VIA, "1.1 example.com".parse().unwrap());
433+
headers.insert(SET_COOKIE, "cookie_1=value 1".parse().unwrap());
434+
headers.append(SET_COOKIE, "cookie_2=value 2".parse().unwrap());
435+
headers.append(VIA, "1.1 other.com".parse().unwrap());
436+
headers.append(SET_COOKIE, "cookie_3=value 3".parse().unwrap());
437+
headers.insert(VARY, "*".parse().unwrap());
438+
439+
assert_eq!(headers.len(), 6);
440+
441+
let cookie = headers.remove(SET_COOKIE);
442+
assert_eq!(cookie, Some("cookie_1=value 1".parse().unwrap()));
443+
assert_eq!(headers.len(), 3);
444+
445+
let via = headers.remove(VIA);
446+
assert_eq!(via, Some("1.1 example.com".parse().unwrap()));
447+
assert_eq!(headers.len(), 1);
448+
449+
let vary = headers.remove(VARY);
450+
assert_eq!(vary, Some("*".parse().unwrap()));
451+
assert_eq!(headers.len(), 0);
452+
}
453+
454+
#[test]
455+
fn remove_multiple_b() {
456+
let mut headers = HeaderMap::new();
457+
headers.insert(VIA, "1.1 example.com".parse().unwrap());
458+
headers.insert(SET_COOKIE, "cookie_1=value 1".parse().unwrap());
459+
headers.append(SET_COOKIE, "cookie_2=value 2".parse().unwrap());
460+
headers.append(VIA, "1.1 other.com".parse().unwrap());
461+
headers.append(SET_COOKIE, "cookie_3=value 3".parse().unwrap());
462+
headers.insert(VARY, "*".parse().unwrap());
463+
464+
assert_eq!(headers.len(), 6);
465+
466+
let vary = headers.remove(VARY);
467+
assert_eq!(vary, Some("*".parse().unwrap()));
468+
assert_eq!(headers.len(), 5);
469+
470+
let via = headers.remove(VIA);
471+
assert_eq!(via, Some("1.1 example.com".parse().unwrap()));
472+
assert_eq!(headers.len(), 3);
473+
474+
let cookie = headers.remove(SET_COOKIE);
475+
assert_eq!(cookie, Some("cookie_1=value 1".parse().unwrap()));
476+
assert_eq!(headers.len(), 0);
477+
}
478+
428479
#[test]
429480
fn remove_entry_multi_0() {
430481
let mut headers = HeaderMap::new();

0 commit comments

Comments
 (0)