2020-03-23 03:08:41 +01:00
|
|
|
use crate::utils;
|
|
|
|
|
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn passing_encode_string_with_specific_media_type() {
|
|
|
|
let mime = "application/javascript";
|
|
|
|
let data = "var word = 'hello';\nalert(word);\n";
|
2020-03-29 09:54:20 +02:00
|
|
|
let data_url = utils::data_to_data_url(mime, data.as_bytes(), "", "");
|
2020-03-23 03:08:41 +01:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
&data_url,
|
|
|
|
"data:application/javascript;base64,dmFyIHdvcmQgPSAnaGVsbG8nOwphbGVydCh3b3JkKTsK"
|
|
|
|
);
|
|
|
|
}
|
2020-03-29 09:54:20 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn passing_encode_append_fragment() {
|
|
|
|
let data = "<svg></svg>\n";
|
|
|
|
let data_url = utils::data_to_data_url("text/css", data.as_bytes(), "", "fragment");
|
|
|
|
|
|
|
|
assert_eq!(&data_url, "data:text/css;base64,PHN2Zz48L3N2Zz4K#fragment");
|
|
|
|
}
|