test(headers): Add tests for headers with "*" value
This commit is contained in:
@@ -21,24 +21,21 @@ header! {
|
||||
#[doc="If-Match = \"*\" / 1#entity-tag"]
|
||||
#[doc="```"]
|
||||
(IfMatch, "If-Match") => {Any / (EntityTag)+}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_header() {
|
||||
use header::Header;
|
||||
{
|
||||
let a: IfMatch = Header::parse_header(
|
||||
[b"*".to_vec()].as_ref()).unwrap();
|
||||
assert_eq!(a, IfMatch::Any);
|
||||
}
|
||||
{
|
||||
let a: IfMatch = Header::parse_header(
|
||||
[b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\"".to_vec()].as_ref()).unwrap();
|
||||
let b = IfMatch::Items(
|
||||
vec![EntityTag::new(false, "xyzzy".to_string()),
|
||||
EntityTag::new(false, "r2d2xxxx".to_string()),
|
||||
EntityTag::new(false, "c3piozzzz".to_string())]);
|
||||
assert_eq!(a, b);
|
||||
test_if_match {
|
||||
test_header!(
|
||||
test1,
|
||||
vec![b"\"xyzzy\""],
|
||||
Some(HeaderField::Items(
|
||||
vec![EntityTag::new(false, "xyzzy".to_string())])));
|
||||
test_header!(
|
||||
test2,
|
||||
vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
|
||||
Some(HeaderField::Items(
|
||||
vec![EntityTag::new(false, "xyzzy".to_string()),
|
||||
EntityTag::new(false, "r2d2xxxx".to_string()),
|
||||
EntityTag::new(false, "c3piozzzz".to_string())])));
|
||||
test_header!(test3, vec![b"*"], Some(IfMatch::Any));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,14 @@ header! {
|
||||
#[doc="If-None-Match = \"*\" / 1#entity-tag"]
|
||||
#[doc="```"]
|
||||
(IfNoneMatch, "If-None-Match") => {Any / (EntityTag)+}
|
||||
|
||||
test_if_none_match {
|
||||
test_header!(test1, vec![b"\"xyzzy\""]);
|
||||
test_header!(test2, vec![b"W/\"xyzzy\""]);
|
||||
test_header!(test3, vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]);
|
||||
test_header!(test4, vec![b"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\""]);
|
||||
test_header!(test5, vec![b"*"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -176,7 +176,6 @@ macro_rules! header {
|
||||
self.fmt_header(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
mod $tm{
|
||||
use $crate::header::*;
|
||||
@@ -211,7 +210,7 @@ macro_rules! header {
|
||||
}
|
||||
};
|
||||
// List header, one or more items with "*" option
|
||||
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+}) => {
|
||||
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+} $tm:ident{$($tf:item)*}) => {
|
||||
$(#[$a])*
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum $id {
|
||||
@@ -250,6 +249,13 @@ macro_rules! header {
|
||||
self.fmt_header(f)
|
||||
}
|
||||
}
|
||||
#[allow(unused_imports)]
|
||||
mod $tm{
|
||||
use $crate::header::*;
|
||||
use $crate::mime::*;
|
||||
use super::$id as HeaderField;
|
||||
$($tf)*
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ header! {
|
||||
#[doc="Vary = \"*\" / 1#field-name"]
|
||||
#[doc="```"]
|
||||
(Vary, "Vary") => {Any / (UniCase<String>)+}
|
||||
|
||||
test_vary {
|
||||
test_header!(test1, vec![b"accept-encoding, accept-language"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user