test(headers): Add tests for single value headers.
This commit is contained in:
@@ -21,17 +21,3 @@ header! {
|
|||||||
test_header!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
|
test_header!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_header() {
|
|
||||||
use header::{self, q};
|
|
||||||
let a: AcceptCharset = header::Header::parse_header(
|
|
||||||
[b"iso-8859-5, iso-8859-6;q=0.8".to_vec()].as_ref()).unwrap();
|
|
||||||
let b = AcceptCharset(vec![
|
|
||||||
QualityItem { item: Charset::Iso_8859_5, quality: q(1.0) },
|
|
||||||
QualityItem { item: Charset::Iso_8859_6, quality: q(0.8) },
|
|
||||||
]);
|
|
||||||
assert_eq!(format!("{}", a), format!("{}", b));
|
|
||||||
assert_eq!(a, b);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ header! {
|
|||||||
#[doc="The `Access-Control-Max-Age` header indicates how long the results of a"]
|
#[doc="The `Access-Control-Max-Age` header indicates how long the results of a"]
|
||||||
#[doc="preflight request can be cached in a preflight result cache."]
|
#[doc="preflight request can be cached in a preflight result cache."]
|
||||||
(AccessControlMaxAge, "Access-Control-Max-Age") => [u32]
|
(AccessControlMaxAge, "Access-Control-Max-Age") => [u32]
|
||||||
|
|
||||||
|
test_access_control_max_age {}
|
||||||
}
|
}
|
||||||
@@ -7,4 +7,6 @@ header! {
|
|||||||
#[doc="The `Access-Control-Request-Method` header indicates which method will be"]
|
#[doc="The `Access-Control-Request-Method` header indicates which method will be"]
|
||||||
#[doc="used in the actual request as part of the preflight request."]
|
#[doc="used in the actual request as part of the preflight request."]
|
||||||
(AccessControlRequestMethod, "Access-Control-Request-Method") => [Method]
|
(AccessControlRequestMethod, "Access-Control-Request-Method") => [Method]
|
||||||
|
|
||||||
|
test_access_control_request_method {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ header! {
|
|||||||
#[doc="Content-Length = 1*DIGIT"]
|
#[doc="Content-Length = 1*DIGIT"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(ContentLength, "Content-Length") => [u64]
|
(ContentLength, "Content-Length") => [u64]
|
||||||
|
|
||||||
|
test_content_length {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"3495"], Some(HeaderField(3495)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(bench, ContentLength, { vec![b"42349984".to_vec()] });
|
bench_header!(bench, ContentLength, { vec![b"42349984".to_vec()] });
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ header! {
|
|||||||
#[doc="Content-Type = media-type"]
|
#[doc="Content-Type = media-type"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(ContentType, "Content-Type") => [Mime]
|
(ContentType, "Content-Type") => [Mime]
|
||||||
|
|
||||||
|
test_content_type {
|
||||||
|
test_header!(
|
||||||
|
test1,
|
||||||
|
// FIXME: Should be b"text/html; charset=ISO-8859-4" but mime crate lowercases
|
||||||
|
// the whole value so parsing and formatting the value gives a different result
|
||||||
|
vec![b"text/html; charset=iso-8859-4"],
|
||||||
|
Some(HeaderField(Mime(TopLevel::Text, SubLevel::Html, vec![(Attr::Charset, Value::Ext("iso-8859-4".to_string()))]))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(bench, ContentType, { vec![b"application/json; charset=utf-8".to_vec()] });
|
bench_header!(bench, ContentType, { vec![b"application/json; charset=utf-8".to_vec()] });
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ header! {
|
|||||||
#[doc="Date = HTTP-date"]
|
#[doc="Date = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(Date, "Date") => [HttpDate]
|
(Date, "Date") => [HttpDate]
|
||||||
|
|
||||||
|
test_date {
|
||||||
|
test_header!(test1, vec![b"Tue, 15 Nov 1994 08:12:31 GMT"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(imf_fixdate, Date, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
bench_header!(imf_fixdate, Date, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ header! {
|
|||||||
#[doc="ETag = entity-tag"]
|
#[doc="ETag = entity-tag"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(ETag, "ETag") => [EntityTag]
|
(ETag, "ETag") => [EntityTag]
|
||||||
|
|
||||||
|
test_etag {
|
||||||
|
test_header!(test1, vec![b"\"xyzzy\""], Some(HeaderField(EntityTag::new(false, "xyzzy".to_string()))));
|
||||||
|
test_header!(test2, vec![b"W/\"xyzzy\""], Some(HeaderField(EntityTag::new(true, "xyzzy".to_string()))));
|
||||||
|
test_header!(test3, vec![b"\"\""], Some(HeaderField(EntityTag::new(false, "".to_string()))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ header! {
|
|||||||
#[doc="Expires = HTTP-date"]
|
#[doc="Expires = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(Expires, "Expires") => [HttpDate]
|
(Expires, "Expires") => [HttpDate]
|
||||||
|
|
||||||
|
test_expires {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"Thu, 01 Dec 1994 16:00:00 GMT"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(imf_fixdate, Expires, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
bench_header!(imf_fixdate, Expires, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ header! {
|
|||||||
#[doc="If-Unmodified-Since = HTTP-date"]
|
#[doc="If-Unmodified-Since = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(IfModifiedSince, "If-Modified-Since") => [HttpDate]
|
(IfModifiedSince, "If-Modified-Since") => [HttpDate]
|
||||||
|
|
||||||
|
test_if_modified_since {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(imf_fixdate, IfModifiedSince, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
bench_header!(imf_fixdate, IfModifiedSince, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ header! {
|
|||||||
#[doc="If-Unmodified-Since = HTTP-date"]
|
#[doc="If-Unmodified-Since = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(IfUnmodifiedSince, "If-Unmodified-Since") => [HttpDate]
|
(IfUnmodifiedSince, "If-Unmodified-Since") => [HttpDate]
|
||||||
|
|
||||||
|
test_if_unmodified_since {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(imf_fixdate, IfUnmodifiedSince, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
bench_header!(imf_fixdate, IfUnmodifiedSince, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ header! {
|
|||||||
#[doc="Expires = HTTP-date"]
|
#[doc="Expires = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
(LastModified, "Last-Modified") => [HttpDate]
|
(LastModified, "Last-Modified") => [HttpDate]
|
||||||
|
|
||||||
|
test_last_modified {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(imf_fixdate, LastModified, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
bench_header!(imf_fixdate, LastModified, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] });
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ header! {
|
|||||||
// TODO: Use URL
|
// TODO: Use URL
|
||||||
(Location, "Location") => [String]
|
(Location, "Location") => [String]
|
||||||
|
|
||||||
|
test_location {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"/People.html#tim"]);
|
||||||
|
test_header!(test2, vec![b"http://www.example.net/index.html"]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(bench, Location, { vec![b"http://foo.com/hello:3000".to_vec()] });
|
bench_header!(bench, Location, { vec![b"http://foo.com/hello:3000".to_vec()] });
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ macro_rules! header {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Single value header
|
// Single value header
|
||||||
($(#[$a:meta])*($id:ident, $n:expr) => [$value:ty]) => {
|
($(#[$a:meta])*($id:ident, $n:expr) => [$value:ty] $tm:ident{$($tf:item)*}) => {
|
||||||
$(#[$a])*
|
$(#[$a])*
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct $id(pub $value);
|
pub struct $id(pub $value);
|
||||||
@@ -225,6 +225,15 @@ macro_rules! header {
|
|||||||
::std::fmt::Display::fmt(&**self, f)
|
::std::fmt::Display::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
mod $tm{
|
||||||
|
use std::str;
|
||||||
|
use $crate::header::*;
|
||||||
|
use $crate::mime::*;
|
||||||
|
use $crate::method::Method;
|
||||||
|
use super::$id as HeaderField;
|
||||||
|
$($tf)*
|
||||||
|
}
|
||||||
};
|
};
|
||||||
// List header, one or more items with "*" option
|
// List header, one or more items with "*" option
|
||||||
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+} $tm:ident{$($tf:item)*}) => {
|
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+} $tm:ident{$($tf:item)*}) => {
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ header! {
|
|||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
// TODO: Use URL
|
// TODO: Use URL
|
||||||
(Referer, "Referer") => [String]
|
(Referer, "Referer") => [String]
|
||||||
|
|
||||||
|
test_referer {
|
||||||
|
// Testcase from the RFC
|
||||||
|
test_header!(test1, vec![b"http://www.example.org/hypertext/Overview.html"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(bench, Referer, { vec![b"http://foo.com/hello:3000".to_vec()] });
|
bench_header!(bench, Referer, { vec![b"http://foo.com/hello:3000".to_vec()] });
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ header! {
|
|||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
// TODO: Maybe parse as defined in the spec?
|
// TODO: Maybe parse as defined in the spec?
|
||||||
(Server, "Server") => [String]
|
(Server, "Server") => [String]
|
||||||
|
|
||||||
|
test_server {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"CERN/3.0 libwww/2.17"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(bench, Server, { vec![b"Some String".to_vec()] });
|
bench_header!(bench, Server, { vec![b"Some String".to_vec()] });
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ header! {
|
|||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
// TODO: Maybe write parsing according to the spec? (Split the String)
|
// TODO: Maybe write parsing according to the spec? (Split the String)
|
||||||
(UserAgent, "User-Agent") => [String]
|
(UserAgent, "User-Agent") => [String]
|
||||||
|
|
||||||
|
test_user_agent {
|
||||||
|
// Testcase from RFC
|
||||||
|
test_header!(test1, vec![b"CERN-LineMode/2.15 libwww/2.17b3"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn test_format() {
|
#[test] fn test_format() {
|
||||||
|
|||||||
Reference in New Issue
Block a user