2020-03-23 03:08:41 +01:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
2021-03-11 23:44:02 +01:00
|
|
|
use reqwest::Url;
|
|
|
|
|
2020-06-24 09:16:40 +02:00
|
|
|
use crate::url;
|
2020-03-23 03:08:41 +01:00
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[test]
|
|
|
|
fn encode_string_with_specific_media_type() {
|
|
|
|
let mime = "application/javascript";
|
|
|
|
let data = "var word = 'hello';\nalert(word);\n";
|
2021-03-15 06:42:36 +01:00
|
|
|
let data_url = url::create_data_url(mime, data.as_bytes(), &Url::parse("data:,").unwrap());
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(
|
2021-03-11 23:44:02 +01:00
|
|
|
data_url.as_str(),
|
2020-05-23 09:49:04 +02:00
|
|
|
"data:application/javascript;base64,dmFyIHdvcmQgPSAnaGVsbG8nOwphbGVydCh3b3JkKTsK"
|
|
|
|
);
|
|
|
|
}
|
2020-03-29 09:54:20 +02:00
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[test]
|
|
|
|
fn encode_append_fragment() {
|
|
|
|
let data = "<svg></svg>\n";
|
2021-03-15 06:42:36 +01:00
|
|
|
let data_url = url::create_data_url(
|
2021-03-11 23:44:02 +01:00
|
|
|
"image/svg+xml",
|
|
|
|
data.as_bytes(),
|
|
|
|
&Url::parse("data:,").unwrap(),
|
|
|
|
);
|
2020-03-29 09:54:20 +02:00
|
|
|
|
2021-03-11 23:44:02 +01:00
|
|
|
assert_eq!(
|
|
|
|
data_url.as_str(),
|
|
|
|
"data:image/svg+xml;base64,PHN2Zz48L3N2Zz4K"
|
|
|
|
);
|
2020-05-23 09:49:04 +02:00
|
|
|
}
|
2020-03-29 09:54:20 +02:00
|
|
|
}
|