docs(headers): Add examples to Accept* headers
This commit is contained in:
@@ -23,6 +23,10 @@ header! {
|
||||
#[doc="accept-ext = OWS \";\" OWS token [ \"=\" ( token / quoted-string ) ]"]
|
||||
#[doc="```"]
|
||||
#[doc=""]
|
||||
#[doc="# Example values"]
|
||||
#[doc="* `audio/*; q=0.2, audio/basic` (`*` value won't parse correctly)"]
|
||||
#[doc="* `text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c`"]
|
||||
#[doc=""]
|
||||
#[doc="# Notes"]
|
||||
#[doc="* Using always Mime types to represent `media-range` differs from the ABNF."]
|
||||
#[doc="* **FIXME**: `accept-ext` is not supported."]
|
||||
|
||||
@@ -15,9 +15,13 @@ header! {
|
||||
#[doc="```plain"]
|
||||
#[doc="Accept-Charset = 1#( ( charset / \"*\" ) [ weight ] )"]
|
||||
#[doc="```"]
|
||||
#[doc=""]
|
||||
#[doc="# Example values"]
|
||||
#[doc="* `iso-8859-5, unicode-1-1;q=0.8`"]
|
||||
(AcceptCharset, "Accept-Charset") => (QualityItem<Charset>)+
|
||||
|
||||
test_accept_charset {
|
||||
/// Testcase from RFC
|
||||
test_header!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,13 @@ header! {
|
||||
#[doc="Accept-Encoding = #( codings [ weight ] )"]
|
||||
#[doc="codings = content-coding / \"identity\" / \"*\""]
|
||||
#[doc="```"]
|
||||
#[doc=""]
|
||||
#[doc="# Example values"]
|
||||
#[doc="* `compress, gzip`"]
|
||||
#[doc="* ``"]
|
||||
#[doc="* `*`"]
|
||||
#[doc="* `compress;q=0.5, gzip;q=1`"]
|
||||
#[doc="* `gzip;q=1.0, identity; q=0.5, *;q=0`"]
|
||||
(AcceptEncoding, "Accept-Encoding") => (QualityItem<Encoding>)*
|
||||
|
||||
test_accept_encoding {
|
||||
|
||||
@@ -13,49 +13,23 @@ header! {
|
||||
#[doc="Accept-Language = 1#( language-range [ weight ] )"]
|
||||
#[doc="language-range = <language-range, see [RFC4647], Section 2.1>"]
|
||||
#[doc="```"]
|
||||
#[doc=""]
|
||||
#[doc="# Example values"]
|
||||
#[doc="* `da, en-gb;q=0.8, en;q=0.7`"]
|
||||
#[doc="* `en-us;q=1.0, en;q=0.5, fr`"]
|
||||
(AcceptLanguage, "Accept-Language") => (QualityItem<Language>)+
|
||||
|
||||
test_accept_language {
|
||||
// From the RFC
|
||||
test_header!(test1, vec![b"da, en-gb;q=0.8, en;q=0.7"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use header::{Header, Language, qitem, Quality, QualityItem};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_header() {
|
||||
let a: AcceptLanguage = Header::parse_header(
|
||||
[b"en-us;q=1.0, en;q=0.5, fr".to_vec()].as_ref()).unwrap();
|
||||
let b = AcceptLanguage(vec![
|
||||
qitem(Language{primary: "en".to_string(), sub: Some("us".to_string())}),
|
||||
QualityItem::new(Language{primary: "en".to_string(), sub: None},
|
||||
Quality(500)),
|
||||
qitem(Language{primary: "fr".to_string(), sub: None}),
|
||||
]);
|
||||
assert_eq!(format!("{}", a), format!("{}", b));
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_display() {
|
||||
assert_eq!("en".to_string(),
|
||||
format!("{}", Language{primary: "en".to_string(),
|
||||
sub: None}));
|
||||
assert_eq!("en-us".to_string(),
|
||||
format!("{}", Language{primary: "en".to_string(),
|
||||
sub: Some("us".to_string())}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
assert_eq!(Language { primary: "en".to_string(), sub: None },
|
||||
"en".parse().unwrap());
|
||||
assert_eq!(Language { primary: "en".to_string(),
|
||||
sub: Some("us".to_string()) },
|
||||
"en-us".parse().unwrap());
|
||||
// Own test
|
||||
test_header!(
|
||||
test2, vec![b"en-us, en; q=0.5, fr"],
|
||||
Some(AcceptLanguage(vec![
|
||||
qitem(Language {primary: "en".to_string(), sub: Some("us".to_string())}),
|
||||
QualityItem::new(Language{primary: "en".to_string(), sub: None}, Quality(500)),
|
||||
qitem(Language {primary: "fr".to_string(), sub: None}),
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user