mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Fix content type unit test
This commit is contained in:
parent
ce4b8a0af7
commit
3dd48d214b
2 changed files with 11 additions and 5 deletions
|
@ -47,3 +47,4 @@ git = "https://github.com/servo/string-cache"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cookie = "*"
|
cookie = "*"
|
||||||
url = "*"
|
url = "*"
|
||||||
|
hyper = "0.3"
|
||||||
|
|
|
@ -2,12 +2,16 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
extern crate hyper;
|
||||||
|
|
||||||
use net_traits::LoadData;
|
use net_traits::LoadData;
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
|
use self::hyper::header::ContentType;
|
||||||
|
use self::hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn assert_parse(url: &'static str,
|
fn assert_parse(url: &'static str,
|
||||||
content_type: Option<(String, String)>,
|
content_type: Option<ContentType>,
|
||||||
charset: Option<String>,
|
charset: Option<String>,
|
||||||
data: Option<Vec<u8>>) {
|
data: Option<Vec<u8>>) {
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
@ -47,13 +51,14 @@ fn plain() {
|
||||||
#[test]
|
#[test]
|
||||||
fn plain_ct() {
|
fn plain_ct() {
|
||||||
assert_parse("data:text/plain,hello",
|
assert_parse("data:text/plain,hello",
|
||||||
Some(("text".to_string(), "plain".to_string())), None, Some(b"hello".iter().map(|&x| x).collect()));
|
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, vec!()))), None, Some(b"hello".iter().map(|&x| x).collect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn plain_charset() {
|
fn plain_charset() {
|
||||||
assert_parse("data:text/plain;charset=latin1,hello",
|
assert_parse("data:text/plain;charset=latin1,hello",
|
||||||
Some(("text".to_string(), "plain".to_string())), Some("latin1".to_string()), Some(b"hello".iter().map(|&x| x).collect()));
|
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, vec!((Attr::Charset, Value::Ext("latin1".to_string())))))),
|
||||||
|
Some("latin1".to_string()), Some(b"hello".iter().map(|&x| x).collect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -64,12 +69,12 @@ fn base64() {
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_ct() {
|
fn base64_ct() {
|
||||||
assert_parse("data:application/octet-stream;base64,C62+7w==",
|
assert_parse("data:application/octet-stream;base64,C62+7w==",
|
||||||
Some(("application".to_string(), "octet-stream".to_string())), None, Some(vec!(0x0B, 0xAD, 0xBE, 0xEF)));
|
Some(ContentType(Mime(TopLevel::Application, SubLevel::Ext("octet-stream".to_string()), vec!()))), None, Some(vec!(0x0B, 0xAD, 0xBE, 0xEF)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_charset() {
|
fn base64_charset() {
|
||||||
assert_parse("data:text/plain;charset=koi8-r;base64,8PLl9+XkIO3l5Pfl5A==",
|
assert_parse("data:text/plain;charset=koi8-r;base64,8PLl9+XkIO3l5Pfl5A==",
|
||||||
Some(("text".to_string(), "plain".to_string())), Some("koi8-r".to_string()),
|
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, vec!((Attr::Charset, Value::Ext("koi8-r".to_string())))))), Some("koi8-r".to_string()),
|
||||||
Some(vec!(0xF0, 0xF2, 0xE5, 0xF7, 0xE5, 0xE4, 0x20, 0xED, 0xE5, 0xE4, 0xF7, 0xE5, 0xE4)));
|
Some(vec!(0xF0, 0xF2, 0xE5, 0xF7, 0xE5, 0xE4, 0x20, 0xED, 0xE5, 0xE4, 0xF7, 0xE5, 0xE4)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue