2020-03-23 03:08:41 +01:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
2020-06-24 09:16:40 +02:00
|
|
|
use crate::url;
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_html_base64() {
|
2020-11-23 06:12:26 +01:00
|
|
|
let (media_type, data) = url::parse_data_url("data:text/html;base64,V29yayBleHBhbmRzIHNvIGFzIHRvIGZpbGwgdGhlIHRpbWUgYXZhaWxhYmxlIGZvciBpdHMgY29tcGxldGlvbg==");
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(media_type, "text/html");
|
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&data),
|
|
|
|
"Work expands so as to fill the time available for its completion"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_html_utf8() {
|
2020-11-23 06:12:26 +01:00
|
|
|
let (media_type, data) = url::parse_data_url(
|
2020-05-23 09:49:04 +02:00
|
|
|
"data:text/html;utf8,Work expands so as to fill the time available for its completion",
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(media_type, "text/html");
|
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&data),
|
|
|
|
"Work expands so as to fill the time available for its completion"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_html_plaintext() {
|
2020-11-23 06:12:26 +01:00
|
|
|
let (media_type, data) = url::parse_data_url(
|
2020-05-23 09:49:04 +02:00
|
|
|
"data:text/html,Work expands so as to fill the time available for its completion",
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(media_type, "text/html");
|
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&data),
|
|
|
|
"Work expands so as to fill the time available for its completion"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_html_charset_utf_8_between_two_whitespaces() {
|
2020-11-23 06:12:26 +01:00
|
|
|
let (media_type, data) = url::parse_data_url(" data:text/html;charset=utf-8,Work expands so as to fill the time available for its completion ");
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(media_type, "text/html");
|
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&data),
|
|
|
|
"Work expands so as to fill the time available for its completion"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_css_url_encoded() {
|
2020-12-26 08:23:29 +01:00
|
|
|
let (media_type, data) = url::parse_data_url("data:text/css,div{background-color:%23000}");
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(media_type, "text/css");
|
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "div{background-color:#000}");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_no_media_type_base64() {
|
2020-11-23 06:12:26 +01:00
|
|
|
let (media_type, data) = url::parse_data_url("data:;base64,dGVzdA==");
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(media_type, "");
|
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "test");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_no_media_type_no_encoding() {
|
2020-11-23 06:12:26 +01:00
|
|
|
let (media_type, data) = url::parse_data_url("data:;,test%20test");
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(media_type, "");
|
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "test test");
|
|
|
|
}
|
2020-04-10 02:27:07 +02:00
|
|
|
}
|
|
|
|
|
2020-03-23 03:08:41 +01:00
|
|
|
// ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔════╝██╔══██╗██║██║ ██║████╗ ██║██╔════╝
|
|
|
|
// █████╗ ███████║██║██║ ██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔══╝ ██╔══██║██║██║ ██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║██║███████╗██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod failing {
|
2020-06-24 09:16:40 +02:00
|
|
|
use crate::url;
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn just_word_data() {
|
2020-11-23 06:12:26 +01:00
|
|
|
let (media_type, data) = url::parse_data_url("data");
|
2020-04-10 11:06:07 +02:00
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(media_type, "");
|
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "");
|
|
|
|
}
|
2020-03-23 03:08:41 +01:00
|
|
|
}
|