Merge pull request #284 from snshn/move-tests-to-upper-level
Get rid of macros, move tests out of src
This commit is contained in:
commit
a11c4496b0
71 changed files with 272 additions and 262 deletions
36
src/css.rs
36
src/css.rs
|
@ -6,7 +6,7 @@ use std::collections::HashMap;
|
|||
use url::Url;
|
||||
|
||||
use crate::opts::Options;
|
||||
use crate::url::{create_data_url, resolve_url};
|
||||
use crate::url::{create_data_url, resolve_url, EMPTY_IMAGE_DATA_URL};
|
||||
use crate::utils::retrieve_asset;
|
||||
|
||||
const CSS_PROPS_WITH_IMAGE_URLS: &[&str] = &[
|
||||
|
@ -56,14 +56,14 @@ pub fn embed_css(
|
|||
}
|
||||
|
||||
pub fn format_ident(ident: &str) -> String {
|
||||
let mut res: String = String::new();
|
||||
let mut res: String = "".to_string();
|
||||
let _ = serialize_identifier(ident, &mut res);
|
||||
res = res.trim_end().to_string();
|
||||
res
|
||||
}
|
||||
|
||||
pub fn format_quoted_string(string: &str) -> String {
|
||||
let mut res: String = String::new();
|
||||
let mut res: String = "".to_string();
|
||||
let _ = serialize_string(string, &mut res);
|
||||
res
|
||||
}
|
||||
|
@ -86,10 +86,10 @@ pub fn process_css<'a>(
|
|||
prop_name: &str,
|
||||
func_name: &str,
|
||||
) -> Result<String, ParseError<'a, String>> {
|
||||
let mut result: String = str!();
|
||||
let mut result: String = "".to_string();
|
||||
|
||||
let mut curr_rule: String = str!(rule_name.clone());
|
||||
let mut curr_prop: String = str!(prop_name.clone());
|
||||
let mut curr_rule: String = rule_name.clone().to_string();
|
||||
let mut curr_prop: String = prop_name.clone().to_string();
|
||||
let mut token: &Token;
|
||||
let mut token_offset: SourcePosition;
|
||||
|
||||
|
@ -105,7 +105,7 @@ pub fn process_css<'a>(
|
|||
match *token {
|
||||
Token::Comment(_) => {
|
||||
let token_slice = parser.slice_from(token_offset);
|
||||
result.push_str(str!(token_slice).as_str());
|
||||
result.push_str(token_slice);
|
||||
}
|
||||
Token::Semicolon => result.push_str(";"),
|
||||
Token::Colon => result.push_str(":"),
|
||||
|
@ -161,13 +161,13 @@ pub fn process_css<'a>(
|
|||
}
|
||||
// div...
|
||||
Token::Ident(ref value) => {
|
||||
curr_rule = str!();
|
||||
curr_prop = str!(value);
|
||||
curr_rule = "".to_string();
|
||||
curr_prop = value.to_string();
|
||||
result.push_str(&format_ident(value));
|
||||
}
|
||||
// @import, @font-face, @charset, @media...
|
||||
Token::AtKeyword(ref value) => {
|
||||
curr_rule = str!(value);
|
||||
curr_rule = value.to_string();
|
||||
if options.no_fonts && curr_rule == "font-face" {
|
||||
continue;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ pub fn process_css<'a>(
|
|||
Token::QuotedString(ref value) => {
|
||||
if curr_rule == "import" {
|
||||
// Reset current at-rule value
|
||||
curr_rule = str!();
|
||||
curr_rule = "".to_string();
|
||||
|
||||
// Skip empty import values
|
||||
if value.len() == 0 {
|
||||
|
@ -242,7 +242,7 @@ pub fn process_css<'a>(
|
|||
}
|
||||
|
||||
if options.no_images && is_image_url_prop(curr_prop.as_str()) {
|
||||
result.push_str(format_quoted_string(empty_image!()).as_str());
|
||||
result.push_str(format_quoted_string(EMPTY_IMAGE_DATA_URL).as_str());
|
||||
} else {
|
||||
let resolved_url: Url = resolve_url(&document_url, value);
|
||||
match retrieve_asset(
|
||||
|
@ -297,7 +297,7 @@ pub fn process_css<'a>(
|
|||
if *has_sign && *unit_value >= 0. {
|
||||
result.push_str("+");
|
||||
}
|
||||
result.push_str(str!(unit_value * 100.0).as_str());
|
||||
result.push_str(&(unit_value * 100.0).to_string());
|
||||
result.push_str("%");
|
||||
}
|
||||
Token::Dimension {
|
||||
|
@ -309,12 +309,12 @@ pub fn process_css<'a>(
|
|||
if *has_sign && *value >= 0. {
|
||||
result.push_str("+");
|
||||
}
|
||||
result.push_str(str!(value).as_str());
|
||||
result.push_str(str!(unit).as_str());
|
||||
result.push_str(&value.to_string());
|
||||
result.push_str(&unit.to_string());
|
||||
}
|
||||
// #selector, #id...
|
||||
Token::IDHash(ref value) => {
|
||||
curr_rule = str!();
|
||||
curr_rule = "".to_string();
|
||||
result.push_str("#");
|
||||
result.push_str(&format_ident(value));
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ pub fn process_css<'a>(
|
|||
|
||||
if is_import {
|
||||
// Reset current at-rule value
|
||||
curr_rule = str!();
|
||||
curr_rule = "".to_string();
|
||||
}
|
||||
|
||||
// Skip empty url()'s
|
||||
|
@ -377,7 +377,7 @@ pub fn process_css<'a>(
|
|||
}
|
||||
} else {
|
||||
if is_image_url_prop(curr_prop.as_str()) && options.no_images {
|
||||
result.push_str(format_quoted_string(empty_image!()).as_str());
|
||||
result.push_str(format_quoted_string(EMPTY_IMAGE_DATA_URL).as_str());
|
||||
} else {
|
||||
let full_url: Url = resolve_url(&document_url, value);
|
||||
match retrieve_asset(
|
||||
|
|
48
src/html.rs
48
src/html.rs
|
@ -18,7 +18,9 @@ use std::default::Default;
|
|||
use crate::css::embed_css;
|
||||
use crate::js::attr_is_event_handler;
|
||||
use crate::opts::Options;
|
||||
use crate::url::{clean_url, create_data_url, is_url_and_has_protocol, resolve_url};
|
||||
use crate::url::{
|
||||
clean_url, create_data_url, is_url_and_has_protocol, resolve_url, EMPTY_IMAGE_DATA_URL,
|
||||
};
|
||||
use crate::utils::{parse_content_type, retrieve_asset};
|
||||
|
||||
struct SrcSetItem<'a> {
|
||||
|
@ -173,11 +175,11 @@ pub fn embed_srcset(
|
|||
}
|
||||
}
|
||||
|
||||
let mut result: String = str!();
|
||||
let mut result: String = "".to_string();
|
||||
let mut i: usize = array.len();
|
||||
for part in array {
|
||||
if options.no_images {
|
||||
result.push_str(empty_image!());
|
||||
result.push_str(EMPTY_IMAGE_DATA_URL);
|
||||
} else {
|
||||
let image_full_url: Url = resolve_url(&document_url, part.path);
|
||||
match retrieve_asset(
|
||||
|
@ -205,7 +207,7 @@ pub fn embed_srcset(
|
|||
result.push_str(image_full_url.as_ref());
|
||||
} else {
|
||||
// Avoid breaking the structure in case if not an HTTP(S) URL
|
||||
result.push_str(empty_image!());
|
||||
result.push_str(EMPTY_IMAGE_DATA_URL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +344,7 @@ pub fn get_node_attr(node: &Handle, attr_name: &str) -> Option<String> {
|
|||
NodeData::Element { ref attrs, .. } => {
|
||||
for attr in attrs.borrow().iter() {
|
||||
if &*attr.name.local == attr_name {
|
||||
return Some(str!(&*attr.value));
|
||||
return Some(attr.value.to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -827,10 +829,10 @@ pub fn walk_and_embed_assets(
|
|||
if options.no_images {
|
||||
// Put empty images into src and data-src attributes
|
||||
if img_attr_src_value != None {
|
||||
set_node_attr(node, "src", Some(str!(empty_image!())));
|
||||
set_node_attr(node, "src", Some(EMPTY_IMAGE_DATA_URL.to_string()));
|
||||
}
|
||||
if img_attr_data_src_value != None {
|
||||
set_node_attr(node, "data-src", Some(str!(empty_image!())));
|
||||
set_node_attr(node, "data-src", Some(EMPTY_IMAGE_DATA_URL.to_string()));
|
||||
}
|
||||
} else {
|
||||
if img_attr_src_value.clone().unwrap_or_default().is_empty()
|
||||
|
@ -840,7 +842,7 @@ pub fn walk_and_embed_assets(
|
|||
.is_empty()
|
||||
{
|
||||
// Add empty src attribute
|
||||
set_node_attr(node, "src", Some(str!()));
|
||||
set_node_attr(node, "src", Some("".to_string()));
|
||||
} else {
|
||||
// Add data URL src attribute
|
||||
let img_full_url: String = if !img_attr_data_src_value
|
||||
|
@ -891,11 +893,11 @@ pub fn walk_and_embed_assets(
|
|||
if let Some(input_attr_src_value) = get_node_attr(node, "src") {
|
||||
if options.no_images || input_attr_src_value.is_empty() {
|
||||
let value = if input_attr_src_value.is_empty() {
|
||||
str!()
|
||||
""
|
||||
} else {
|
||||
str!(empty_image!())
|
||||
EMPTY_IMAGE_DATA_URL
|
||||
};
|
||||
set_node_attr(node, "src", Some(value));
|
||||
set_node_attr(node, "src", Some(value.to_string()));
|
||||
} else {
|
||||
retrieve_and_embed_asset(
|
||||
cache,
|
||||
|
@ -913,7 +915,7 @@ pub fn walk_and_embed_assets(
|
|||
}
|
||||
}
|
||||
"image" => {
|
||||
let mut image_href: String = str!();
|
||||
let mut image_href: String = "".to_string();
|
||||
|
||||
if let Some(image_attr_href_value) = get_node_attr(node, "href") {
|
||||
image_href = image_attr_href_value;
|
||||
|
@ -984,7 +986,11 @@ pub fn walk_and_embed_assets(
|
|||
if parent_node_name == "picture" {
|
||||
if !source_attr_srcset_value.is_empty() {
|
||||
if options.no_images {
|
||||
set_node_attr(node, "srcset", Some(str!(empty_image!())));
|
||||
set_node_attr(
|
||||
node,
|
||||
"srcset",
|
||||
Some(EMPTY_IMAGE_DATA_URL.to_string()),
|
||||
);
|
||||
} else {
|
||||
let resolved_srcset: String = embed_srcset(
|
||||
cache,
|
||||
|
@ -1009,7 +1015,7 @@ pub fn walk_and_embed_assets(
|
|||
{
|
||||
if options.no_js {
|
||||
// Replace with empty JS call to preserve original behavior
|
||||
set_node_attr(node, "href", Some(str!("javascript:;")));
|
||||
set_node_attr(node, "href", Some("javascript:;".to_string()));
|
||||
}
|
||||
} else {
|
||||
// Don't touch mailto: links or hrefs which begin with a hash sign
|
||||
|
@ -1083,7 +1089,7 @@ pub fn walk_and_embed_assets(
|
|||
if let Some(frame_attr_src_value) = get_node_attr(node, "src") {
|
||||
if options.no_frames {
|
||||
// Empty the src attribute
|
||||
set_node_attr(node, "src", Some(str!()));
|
||||
set_node_attr(node, "src", Some("".to_string()));
|
||||
} else {
|
||||
// Ignore (i)frames with empty source (they cause infinite loops)
|
||||
if !frame_attr_src_value.trim().is_empty() {
|
||||
|
@ -1144,7 +1150,11 @@ pub fn walk_and_embed_assets(
|
|||
// Skip posters with empty source
|
||||
if !video_attr_poster_value.is_empty() {
|
||||
if options.no_images {
|
||||
set_node_attr(node, "poster", Some(str!(empty_image!())));
|
||||
set_node_attr(
|
||||
node,
|
||||
"poster",
|
||||
Some(EMPTY_IMAGE_DATA_URL.to_string()),
|
||||
);
|
||||
} else {
|
||||
retrieve_and_embed_asset(
|
||||
cache,
|
||||
|
@ -1167,8 +1177,10 @@ pub fn walk_and_embed_assets(
|
|||
// Get contents of NOSCRIPT node
|
||||
let mut noscript_contents = contents.borrow_mut();
|
||||
// Parse contents of NOSCRIPT node as DOM
|
||||
let noscript_contents_dom: RcDom =
|
||||
html_to_dom(&noscript_contents.as_bytes().to_vec(), str!());
|
||||
let noscript_contents_dom: RcDom = html_to_dom(
|
||||
&noscript_contents.as_bytes().to_vec(),
|
||||
"".to_string(),
|
||||
);
|
||||
// Embed assets of NOSCRIPT node contents
|
||||
walk_and_embed_assets(
|
||||
cache,
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
#[macro_use]
|
||||
extern crate clap;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
pub mod css;
|
||||
pub mod html;
|
||||
pub mod js;
|
||||
pub mod opts;
|
||||
pub mod url;
|
||||
pub mod utils;
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests;
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
#[macro_export]
|
||||
macro_rules! str {
|
||||
() => {
|
||||
String::new()
|
||||
};
|
||||
($val: expr) => {
|
||||
ToString::to_string(&$val)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! empty_image {
|
||||
() => {
|
||||
"data:image/png;base64,\
|
||||
iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAQAAADY4iz3AAAAEUlEQVR42mNkwAkYR6UolgIACvgADsuK6xYAAAAASUVORK5CYII="
|
||||
};
|
||||
}
|
15
src/main.rs
15
src/main.rs
|
@ -18,8 +18,6 @@ use monolith::opts::Options;
|
|||
use monolith::url::{create_data_url, resolve_url};
|
||||
use monolith::utils::retrieve_asset;
|
||||
|
||||
mod macros;
|
||||
|
||||
enum Output {
|
||||
Stdout(io::Stdout),
|
||||
File(fs::File),
|
||||
|
@ -67,7 +65,7 @@ pub fn read_stdin() -> Vec<u8> {
|
|||
|
||||
fn main() {
|
||||
let options = Options::from_args();
|
||||
let mut target: String = str!(&options.target.clone());
|
||||
let mut target: String = options.target.clone();
|
||||
|
||||
// Check if target was provided
|
||||
if target.len() == 0 {
|
||||
|
@ -170,7 +168,7 @@ fn main() {
|
|||
let mut base_url: Url = target_url.clone();
|
||||
|
||||
let data: Vec<u8>;
|
||||
let mut document_encoding: String = str!();
|
||||
let mut document_encoding: String = "".to_string();
|
||||
let mut dom: RcDom;
|
||||
|
||||
// Retrieve target document
|
||||
|
@ -190,7 +188,12 @@ fn main() {
|
|||
process::exit(1);
|
||||
}
|
||||
|
||||
if options.base_url.clone().unwrap_or(str!()).is_empty() {
|
||||
if options
|
||||
.base_url
|
||||
.clone()
|
||||
.unwrap_or("".to_string())
|
||||
.is_empty()
|
||||
{
|
||||
base_url = final_url;
|
||||
}
|
||||
|
||||
|
@ -226,7 +229,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Use custom base URL if specified, read and use what's in the DOM otherwise
|
||||
let custom_base_url: String = options.base_url.clone().unwrap_or(str!());
|
||||
let custom_base_url: String = options.base_url.clone().unwrap_or("".to_string());
|
||||
if custom_base_url.is_empty() {
|
||||
// No custom base URL is specified
|
||||
// Try to see if document has BASE element
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::{App, Arg};
|
||||
use clap::{crate_authors, crate_description, crate_version, App, Arg};
|
||||
use std::env;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -85,11 +85,11 @@ impl Options {
|
|||
.to_string();
|
||||
options.no_audio = app.is_present("no-audio");
|
||||
if let Some(base_url) = app.value_of("base-url") {
|
||||
options.base_url = Some(str!(base_url));
|
||||
options.base_url = Some(base_url.to_string());
|
||||
}
|
||||
options.no_css = app.is_present("no-css");
|
||||
if let Some(charset) = app.value_of("charset") {
|
||||
options.charset = Some(str!(charset));
|
||||
options.charset = Some(charset.to_string());
|
||||
}
|
||||
options.ignore_errors = app.is_present("ignore-errors");
|
||||
options.no_frames = app.is_present("no-frames");
|
||||
|
@ -107,7 +107,7 @@ impl Options {
|
|||
.parse::<u64>()
|
||||
.unwrap();
|
||||
if let Some(user_agent) = app.value_of("user-agent") {
|
||||
options.user_agent = Some(str!(user_agent));
|
||||
options.user_agent = Some(user_agent.to_string());
|
||||
} else {
|
||||
options.user_agent = Some(DEFAULT_USER_AGENT.to_string());
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ use url::{form_urlencoded, Url};
|
|||
|
||||
use crate::utils::{detect_media_type, parse_content_type};
|
||||
|
||||
pub const EMPTY_IMAGE_DATA_URL: &'static str = "data:image/png;base64,\
|
||||
iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAQAAADY4iz3AAAAEUlEQVR42mNkwAkYR6UolgIACvgADsuK6xYAAAAASUVORK5CYII=";
|
||||
|
||||
pub fn clean_url(url: Url) -> Url {
|
||||
let mut url = url.clone();
|
||||
|
||||
|
@ -26,7 +29,7 @@ pub fn create_data_url(media_type: &str, charset: &str, data: &[u8], final_asset
|
|||
if !charset.trim().is_empty() && !charset.trim().eq_ignore_ascii_case("US-ASCII") {
|
||||
format!(";charset={}", charset.trim())
|
||||
} else {
|
||||
str!()
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
data_url.set_path(format!("{}{};base64,{}", media_type, c, base64::encode(data)).as_str());
|
||||
|
@ -75,9 +78,9 @@ pub fn percent_decode(input: String) -> String {
|
|||
[
|
||||
key.to_string(),
|
||||
if val.to_string().len() == 0 {
|
||||
str!()
|
||||
"".to_string()
|
||||
} else {
|
||||
str!('=')
|
||||
"=".to_string()
|
||||
},
|
||||
val.to_string(),
|
||||
]
|
||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -110,8 +110,8 @@ pub fn is_plaintext_media_type(media_type: &str) -> bool {
|
|||
}
|
||||
|
||||
pub fn parse_content_type(content_type: &str) -> (String, String, bool) {
|
||||
let mut media_type: String = str!("text/plain");
|
||||
let mut charset: String = str!("US-ASCII");
|
||||
let mut media_type: String = "text/plain".to_string();
|
||||
let mut charset: String = "US-ASCII".to_string();
|
||||
let mut is_base64: bool = false;
|
||||
|
||||
// Parse meta data
|
||||
|
@ -120,7 +120,7 @@ pub fn parse_content_type(content_type: &str) -> (String, String, bool) {
|
|||
for item in &content_type_items {
|
||||
if i == 0 {
|
||||
if item.trim().len() > 0 {
|
||||
media_type = str!(item.trim());
|
||||
media_type = item.trim().to_string();
|
||||
}
|
||||
} else {
|
||||
if item.trim().eq_ignore_ascii_case("base64") {
|
||||
|
@ -199,7 +199,7 @@ pub fn retrieve_asset(
|
|||
file_blob.clone(),
|
||||
url.clone(),
|
||||
detect_media_type(&file_blob, url),
|
||||
str!(),
|
||||
"".to_string(),
|
||||
))
|
||||
}
|
||||
} else {
|
||||
|
@ -232,8 +232,8 @@ pub fn retrieve_asset(
|
|||
Ok((
|
||||
cache.get(&cache_key).unwrap().to_vec(),
|
||||
url.clone(),
|
||||
str!(),
|
||||
str!(),
|
||||
"".to_string(),
|
||||
"".to_string(),
|
||||
))
|
||||
} else {
|
||||
// URL not in cache, we retrieve the file
|
||||
|
|
|
@ -77,8 +77,8 @@ mod passing {
|
|||
#[test]
|
||||
fn css_import_string() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let path_html: &Path = Path::new("src/tests/data/css/index.html");
|
||||
let path_css: &Path = Path::new("src/tests/data/css/style.css");
|
||||
let path_html: &Path = Path::new("tests/data/css/index.html");
|
||||
let path_css: &Path = Path::new("tests/data/css/style.css");
|
||||
|
||||
assert!(path_html.is_file());
|
||||
assert!(path_css.is_file());
|
|
@ -11,6 +11,8 @@ mod passing {
|
|||
use std::env;
|
||||
use std::process::Command;
|
||||
|
||||
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||
|
||||
#[test]
|
||||
fn isolate_data_url() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
|
@ -139,7 +141,7 @@ mod passing {
|
|||
Hi\
|
||||
</body>\
|
||||
</html>\n",
|
||||
empty_image = empty_image!()
|
||||
empty_image = EMPTY_IMAGE_DATA_URL,
|
||||
)
|
||||
);
|
||||
|
|
@ -14,15 +14,20 @@ mod passing {
|
|||
use std::process::Command;
|
||||
use url::Url;
|
||||
|
||||
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||
|
||||
#[test]
|
||||
fn local_file_target_input_relative_target_path() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let cwd_normalized: String =
|
||||
str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/");
|
||||
let cwd_normalized: String = env::current_dir()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.replace("\\", "/");
|
||||
let out = cmd
|
||||
.arg("-M")
|
||||
.arg(format!(
|
||||
"src{s}tests{s}data{s}basic{s}local-file.html",
|
||||
"tests{s}data{s}basic{s}local-file.html",
|
||||
s = MAIN_SEPARATOR
|
||||
))
|
||||
.output()
|
||||
|
@ -34,11 +39,11 @@ mod passing {
|
|||
String::from_utf8_lossy(&out.stderr),
|
||||
format!(
|
||||
"\
|
||||
{file}{cwd}/src/tests/data/basic/local-file.html\n \
|
||||
{file}{cwd}/src/tests/data/basic/local-style.css\n \
|
||||
{file}{cwd}/src/tests/data/basic/local-style-does-not-exist.css (not found)\n \
|
||||
{file}{cwd}/src/tests/data/basic/monolith.png (not found)\n \
|
||||
{file}{cwd}/src/tests/data/basic/local-script.js\n\
|
||||
{file}{cwd}/tests/data/basic/local-file.html\n \
|
||||
{file}{cwd}/tests/data/basic/local-style.css\n \
|
||||
{file}{cwd}/tests/data/basic/local-style-does-not-exist.css (not found)\n \
|
||||
{file}{cwd}/tests/data/basic/monolith.png (not found)\n \
|
||||
{file}{cwd}/tests/data/basic/local-script.js\n\
|
||||
",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized
|
||||
|
@ -69,7 +74,7 @@ mod passing {
|
|||
#[test]
|
||||
fn local_file_target_input_absolute_target_path() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let path_html: &Path = Path::new("src/tests/data/basic/local-file.html");
|
||||
let path_html: &Path = Path::new("tests/data/basic/local-file.html");
|
||||
|
||||
let out = cmd
|
||||
.arg("-M")
|
||||
|
@ -104,7 +109,7 @@ mod passing {
|
|||
<script></script>\n\n\n\n\
|
||||
</body></html>\n\
|
||||
",
|
||||
empty_image = empty_image!()
|
||||
empty_image = EMPTY_IMAGE_DATA_URL
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -115,14 +120,17 @@ mod passing {
|
|||
#[test]
|
||||
fn local_file_url_target_input() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let cwd_normalized: String =
|
||||
str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/");
|
||||
let cwd_normalized: String = env::current_dir()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.replace("\\", "/");
|
||||
let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" };
|
||||
let out = cmd
|
||||
.arg("-M")
|
||||
.arg("-cji")
|
||||
.arg(format!(
|
||||
"{file}{cwd}/src/tests/data/basic/local-file.html",
|
||||
"{file}{cwd}/tests/data/basic/local-file.html",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
||||
))
|
||||
|
@ -133,7 +141,7 @@ mod passing {
|
|||
assert_eq!(
|
||||
String::from_utf8_lossy(&out.stderr),
|
||||
format!(
|
||||
"{file}{cwd}/src/tests/data/basic/local-file.html\n",
|
||||
"{file}{cwd}/tests/data/basic/local-file.html\n",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
||||
)
|
||||
|
@ -156,7 +164,7 @@ mod passing {
|
|||
<script></script>\n\n\n\n\
|
||||
</body></html>\n\
|
||||
",
|
||||
empty_image = empty_image!()
|
||||
empty_image = EMPTY_IMAGE_DATA_URL
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -167,8 +175,8 @@ mod passing {
|
|||
#[test]
|
||||
fn embed_file_url_local_asset_within_style_attribute() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let path_html: &Path = Path::new("src/tests/data/svg/index.html");
|
||||
let path_svg: &Path = Path::new("src/tests/data/svg/image.svg");
|
||||
let path_html: &Path = Path::new("tests/data/svg/index.html");
|
||||
let path_svg: &Path = Path::new("tests/data/svg/image.svg");
|
||||
|
||||
let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap();
|
||||
|
||||
|
@ -198,21 +206,24 @@ mod passing {
|
|||
#[test]
|
||||
fn discard_integrity_for_local_files() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let cwd_normalized: String =
|
||||
str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/");
|
||||
let cwd_normalized: String = env::current_dir()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.replace("\\", "/");
|
||||
let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" };
|
||||
let out = cmd
|
||||
.arg("-M")
|
||||
.arg("-i")
|
||||
.arg(if cfg!(windows) {
|
||||
format!(
|
||||
"{file}{cwd}/src/tests/data/integrity/index.html",
|
||||
"{file}{cwd}/tests/data/integrity/index.html",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{file}{cwd}/src/tests/data/integrity/index.html",
|
||||
"{file}{cwd}/tests/data/integrity/index.html",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
||||
)
|
||||
|
@ -225,11 +236,11 @@ mod passing {
|
|||
String::from_utf8_lossy(&out.stderr),
|
||||
format!(
|
||||
"\
|
||||
{file}{cwd}/src/tests/data/integrity/index.html\n \
|
||||
{file}{cwd}/src/tests/data/integrity/style.css\n \
|
||||
{file}{cwd}/src/tests/data/integrity/style.css\n \
|
||||
{file}{cwd}/src/tests/data/integrity/script.js\n \
|
||||
{file}{cwd}/src/tests/data/integrity/script.js\n\
|
||||
{file}{cwd}/tests/data/integrity/index.html\n \
|
||||
{file}{cwd}/tests/data/integrity/style.css\n \
|
||||
{file}{cwd}/tests/data/integrity/style.css\n \
|
||||
{file}{cwd}/tests/data/integrity/script.js\n \
|
||||
{file}{cwd}/tests/data/integrity/script.js\n\
|
||||
",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
|
@ -17,8 +17,8 @@ mod passing {
|
|||
#[test]
|
||||
fn parse_noscript_contents() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let path_html: &Path = Path::new("src/tests/data/noscript/index.html");
|
||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
||||
let path_html: &Path = Path::new("tests/data/noscript/index.html");
|
||||
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||
|
||||
let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap();
|
||||
|
||||
|
@ -48,8 +48,8 @@ mod passing {
|
|||
#[test]
|
||||
fn unwrap_noscript_contents() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let path_html: &Path = Path::new("src/tests/data/noscript/index.html");
|
||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
||||
let path_html: &Path = Path::new("tests/data/noscript/index.html");
|
||||
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||
|
||||
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
||||
|
||||
|
@ -79,8 +79,8 @@ mod passing {
|
|||
#[test]
|
||||
fn unwrap_noscript_contents_nested() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let path_html: &Path = Path::new("src/tests/data/noscript/nested.html");
|
||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
||||
let path_html: &Path = Path::new("tests/data/noscript/nested.html");
|
||||
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||
|
||||
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
||||
|
||||
|
@ -110,8 +110,8 @@ mod passing {
|
|||
#[test]
|
||||
fn unwrap_noscript_contents_with_script() {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let path_html: &Path = Path::new("src/tests/data/noscript/script.html");
|
||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
||||
let path_html: &Path = Path::new("tests/data/noscript/script.html");
|
||||
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||
|
||||
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
||||
|
|
@ -16,12 +16,12 @@ mod passing {
|
|||
#[test]
|
||||
fn properly_save_document_with_gb2312() {
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let cwd_normalized: String = str!(cwd.to_str().unwrap()).replace("\\", "/");
|
||||
let cwd_normalized: String = cwd.to_str().unwrap().replace("\\", "/");
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let out = cmd
|
||||
.arg("-M")
|
||||
.arg(format!(
|
||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
s = MAIN_SEPARATOR
|
||||
))
|
||||
.output()
|
||||
|
@ -32,7 +32,7 @@ mod passing {
|
|||
assert_eq!(
|
||||
String::from_utf8_lossy(&out.stderr),
|
||||
format!(
|
||||
"{file}{cwd}/src/tests/data/unusual_encodings/gb2312.html\n",
|
||||
"{file}{cwd}/tests/data/unusual_encodings/gb2312.html\n",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
||||
)
|
||||
|
@ -67,7 +67,7 @@ mod passing {
|
|||
fn properly_save_document_with_gb2312_from_stdin() {
|
||||
let mut echo = Command::new("cat")
|
||||
.arg(format!(
|
||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
s = MAIN_SEPARATOR
|
||||
))
|
||||
.stdout(Stdio::piped())
|
||||
|
@ -111,14 +111,14 @@ mod passing {
|
|||
#[test]
|
||||
fn properly_save_document_with_gb2312_custom_charset() {
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let cwd_normalized: String = str!(cwd.to_str().unwrap()).replace("\\", "/");
|
||||
let cwd_normalized: String = cwd.to_str().unwrap().replace("\\", "/");
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let out = cmd
|
||||
.arg("-M")
|
||||
.arg("-C")
|
||||
.arg("utf8")
|
||||
.arg(format!(
|
||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
s = MAIN_SEPARATOR
|
||||
))
|
||||
.output()
|
||||
|
@ -129,7 +129,7 @@ mod passing {
|
|||
assert_eq!(
|
||||
String::from_utf8_lossy(&out.stderr),
|
||||
format!(
|
||||
"{file}{cwd}/src/tests/data/unusual_encodings/gb2312.html\n",
|
||||
"{file}{cwd}/tests/data/unusual_encodings/gb2312.html\n",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
||||
)
|
||||
|
@ -161,7 +161,7 @@ mod passing {
|
|||
.arg("-C")
|
||||
.arg("utf0")
|
||||
.arg(format!(
|
||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||
s = MAIN_SEPARATOR
|
||||
))
|
||||
.output()
|
||||
|
@ -198,12 +198,12 @@ mod failing {
|
|||
#[test]
|
||||
fn change_iso88591_to_utf8_to_properly_display_html_entities() {
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let cwd_normalized: String = str!(cwd.to_str().unwrap()).replace("\\", "/");
|
||||
let cwd_normalized: String = cwd.to_str().unwrap().replace("\\", "/");
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let out = cmd
|
||||
.arg("-M")
|
||||
.arg(format!(
|
||||
"src{s}tests{s}data{s}unusual_encodings{s}iso-8859-1.html",
|
||||
"tests{s}data{s}unusual_encodings{s}iso-8859-1.html",
|
||||
s = MAIN_SEPARATOR
|
||||
))
|
||||
.output()
|
||||
|
@ -214,7 +214,7 @@ mod failing {
|
|||
assert_eq!(
|
||||
String::from_utf8_lossy(&out.stderr),
|
||||
format!(
|
||||
"{file}{cwd}/src/tests/data/unusual_encodings/iso-8859-1.html\n",
|
||||
"{file}{cwd}/tests/data/unusual_encodings/iso-8859-1.html\n",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd_normalized,
|
||||
)
|
|
@ -11,8 +11,9 @@ mod passing {
|
|||
use reqwest::Url;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::css;
|
||||
use crate::opts::Options;
|
||||
use monolith::css;
|
||||
use monolith::opts::Options;
|
||||
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||
|
||||
#[test]
|
||||
fn empty_input() {
|
||||
|
@ -67,7 +68,7 @@ mod passing {
|
|||
margin-top: -20px; \
|
||||
line-height: -1; \
|
||||
height: calc(100vh - 10pt)",
|
||||
empty_image = empty_image!()
|
||||
empty_image = EMPTY_IMAGE_DATA_URL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ mod passing {
|
|||
margin-top: -20px; \
|
||||
line-height: -1; \
|
||||
height: calc(100vh - 10pt)",
|
||||
empty_image = empty_image!()
|
||||
empty_image = EMPTY_IMAGE_DATA_URL
|
||||
)
|
||||
);
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::css;
|
||||
use monolith::css;
|
||||
|
||||
#[test]
|
||||
fn backrgound() {
|
||||
|
@ -64,7 +64,7 @@ mod passing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use crate::css;
|
||||
use monolith::css;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
|
@ -9,12 +9,12 @@
|
|||
mod passing {
|
||||
use html5ever::serialize::{serialize, SerializeOpts};
|
||||
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
let html = "<div>text</div>";
|
||||
let mut dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let mut dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
dom = html::add_favicon(&dom.document, "I_AM_A_FAVICON_DATA_URL".to_string());
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn empty_input_sha256() {
|
||||
|
@ -51,7 +51,7 @@ mod passing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn empty_hash() {
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::html;
|
||||
use crate::opts::Options;
|
||||
use monolith::html;
|
||||
use monolith::opts::Options;
|
||||
|
||||
#[test]
|
||||
fn isolated() {
|
|
@ -10,7 +10,7 @@ mod passing {
|
|||
use chrono::prelude::*;
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn http_url() {
|
|
@ -11,8 +11,9 @@ mod passing {
|
|||
use reqwest::Url;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::html;
|
||||
use crate::opts::Options;
|
||||
use monolith::html;
|
||||
use monolith::opts::Options;
|
||||
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||
|
||||
#[test]
|
||||
fn small_medium_large() {
|
||||
|
@ -35,9 +36,7 @@ mod passing {
|
|||
embedded_css,
|
||||
format!(
|
||||
"{} 1x, {} 1.5x, {} 2x",
|
||||
empty_image!(),
|
||||
empty_image!(),
|
||||
empty_image!(),
|
||||
EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ mod passing {
|
|||
|
||||
assert_eq!(
|
||||
embedded_css,
|
||||
format!("{}, {} 1.5x", empty_image!(), empty_image!()),
|
||||
format!("{}, {} 1.5x", EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -84,7 +83,7 @@ mod passing {
|
|||
|
||||
assert_eq!(
|
||||
embedded_css,
|
||||
format!("{} 1x, {} 2x", empty_image!(), empty_image!()),
|
||||
format!("{} 1x, {} 2x", EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -109,9 +108,7 @@ mod passing {
|
|||
embedded_css,
|
||||
format!(
|
||||
"{} 1x, {} 2x, {} 3x",
|
||||
empty_image!(),
|
||||
empty_image!(),
|
||||
empty_image!()
|
||||
EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -130,8 +127,9 @@ mod failing {
|
|||
use reqwest::Url;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::html;
|
||||
use crate::opts::Options;
|
||||
use monolith::html;
|
||||
use monolith::opts::Options;
|
||||
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||
|
||||
#[test]
|
||||
fn trailing_comma() {
|
||||
|
@ -152,7 +150,7 @@ mod failing {
|
|||
|
||||
assert_eq!(
|
||||
embedded_css,
|
||||
format!("{} 1x, {} 2x,", empty_image!(), empty_image!()),
|
||||
format!("{} 1x, {} 2x,", EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn present() {
|
||||
|
@ -19,11 +19,11 @@ mod passing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(
|
||||
html::get_base_url(&dom.document),
|
||||
Some(str!("https://musicbrainz.org"))
|
||||
Some("https://musicbrainz.org".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,11 @@ mod passing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(
|
||||
html::get_base_url(&dom.document),
|
||||
Some(str!("https://www.discogs.com/"))
|
||||
Some("https://www.discogs.com/".to_string())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ mod passing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn absent() {
|
||||
|
@ -67,7 +67,7 @@ mod failing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(html::get_base_url(&dom.document), None);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ mod failing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(html::get_base_url(&dom.document), None);
|
||||
}
|
||||
|
@ -97,8 +97,8 @@ mod failing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(html::get_base_url(&dom.document), Some(str!()));
|
||||
assert_eq!(html::get_base_url(&dom.document), Some("".to_string()));
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn meta_content_type() {
|
||||
|
@ -19,9 +19,9 @@ mod passing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(html::get_charset(&dom.document), Some(str!("GB2312")));
|
||||
assert_eq!(html::get_charset(&dom.document), Some("GB2312".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -34,9 +34,9 @@ mod passing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(html::get_charset(&dom.document), Some(str!("GB2312")));
|
||||
assert_eq!(html::get_charset(&dom.document), Some("GB2312".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -50,9 +50,9 @@ mod passing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(html::get_charset(&dom.document), Some(str!("utf-8")));
|
||||
assert_eq!(html::get_charset(&dom.document), Some("utf-8".to_string()));
|
||||
}
|
||||
#[test]
|
||||
fn multiple_conflicting_meta_content_type_first() {
|
||||
|
@ -65,8 +65,8 @@ mod passing {
|
|||
<body>
|
||||
</body>
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
|
||||
assert_eq!(html::get_charset(&dom.document), Some(str!("GB2312")));
|
||||
assert_eq!(html::get_charset(&dom.document), Some("GB2312".to_string()));
|
||||
}
|
||||
}
|
|
@ -9,12 +9,12 @@
|
|||
mod passing {
|
||||
use html5ever::rcdom::{Handle, NodeData};
|
||||
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn div_two_style_attributes() {
|
||||
let html = "<!doctype html><html><head></head><body><DIV STYLE=\"color: blue;\" style=\"display: none;\"></div></body></html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut count = 0;
|
||||
|
||||
fn test_walk(node: &Handle, i: &mut i8) {
|
||||
|
@ -35,7 +35,7 @@ mod passing {
|
|||
} else if node_name == "div" {
|
||||
assert_eq!(
|
||||
html::get_node_attr(node, "style"),
|
||||
Some(str!("color: blue;"))
|
||||
Some("color: blue;".to_string())
|
||||
);
|
||||
}
|
||||
|
|
@ -9,12 +9,12 @@
|
|||
mod passing {
|
||||
use html5ever::rcdom::{Handle, NodeData};
|
||||
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn parent_node_names() {
|
||||
let html = "<!doctype html><html><HEAD></HEAD><body><div><P></P></div></body></html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut count = 0;
|
||||
|
||||
fn test_walk(node: &Handle, i: &mut i8) {
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn icon() {
|
||||
let html = "<link rel=\"icon\" href=\"\" /><div>text</div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let res: bool = html::has_favicon(&dom.document);
|
||||
|
||||
assert!(res);
|
||||
|
@ -21,7 +21,7 @@ mod passing {
|
|||
#[test]
|
||||
fn shortcut_icon() {
|
||||
let html = "<link rel=\"shortcut icon\" href=\"\" /><div>text</div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let res: bool = html::has_favicon(&dom.document);
|
||||
|
||||
assert!(res);
|
||||
|
@ -37,12 +37,12 @@ mod passing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn absent() {
|
||||
let html = "<div>text</div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let res: bool = html::has_favicon(&dom.document);
|
||||
|
||||
assert!(!res);
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn icon() {
|
||||
|
@ -34,7 +34,7 @@ mod passing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn mask_icon() {
|
|
@ -7,17 +7,17 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::html;
|
||||
use crate::opts::Options;
|
||||
use monolith::html;
|
||||
use monolith::opts::Options;
|
||||
|
||||
#[test]
|
||||
fn div_as_root_element() {
|
||||
let html = "<div><script src=\"some.js\"></script></div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let options = Options::default();
|
||||
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&html::serialize_document(dom, str!(), &options)),
|
||||
String::from_utf8_lossy(&html::serialize_document(dom, "".to_string(), &options)),
|
||||
"<html><head></head><body><div><script src=\"some.js\"></script></div></body></html>"
|
||||
);
|
||||
}
|
||||
|
@ -28,14 +28,14 @@ mod passing {
|
|||
<link rel=\"something\" href=\"some.css\" />\
|
||||
<meta http-equiv=\"Content-Security-Policy\" content=\"default-src https:\">\
|
||||
<div><script src=\"some.js\"></script></div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut options = Options::default();
|
||||
options.isolate = true;
|
||||
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&html::serialize_document(
|
||||
dom,
|
||||
str!(),
|
||||
"".to_string(),
|
||||
&options
|
||||
)),
|
||||
"<html>\
|
||||
|
@ -60,12 +60,12 @@ mod passing {
|
|||
<title>Unstyled document</title>\
|
||||
<link rel=\"stylesheet\" href=\"main.css\"/>\
|
||||
<div style=\"display: none;\"></div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut options = Options::default();
|
||||
options.no_css = true;
|
||||
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&html::serialize_document(dom, str!(), &options)),
|
||||
String::from_utf8_lossy(&html::serialize_document(dom, "".to_string(), &options)),
|
||||
"<!DOCTYPE html>\
|
||||
<html>\
|
||||
<head>\
|
||||
|
@ -84,14 +84,14 @@ mod passing {
|
|||
<title>Frameless document</title>\
|
||||
<link rel=\"something\"/>\
|
||||
<div><script src=\"some.js\"></script></div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut options = Options::default();
|
||||
options.no_frames = true;
|
||||
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(&html::serialize_document(
|
||||
dom,
|
||||
str!(),
|
||||
"".to_string(),
|
||||
&options
|
||||
)),
|
||||
"<!DOCTYPE html>\
|
||||
|
@ -117,7 +117,7 @@ mod passing {
|
|||
<img style=\"width: 100%;\" src=\"some.png\" />\
|
||||
<iframe src=\"some.html\"></iframe>\
|
||||
</div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut options = Options::default();
|
||||
options.isolate = true;
|
||||
options.no_css = true;
|
||||
|
@ -129,7 +129,7 @@ mod passing {
|
|||
assert_eq!(
|
||||
String::from_utf8_lossy(&html::serialize_document(
|
||||
dom,
|
||||
str!(),
|
||||
"".to_string(),
|
||||
&options
|
||||
)),
|
||||
"<!DOCTYPE html>\
|
|
@ -9,12 +9,12 @@
|
|||
mod passing {
|
||||
use html5ever::rcdom::{Handle, NodeData};
|
||||
|
||||
use crate::html;
|
||||
use monolith::html;
|
||||
|
||||
#[test]
|
||||
fn html_lang_and_body_style() {
|
||||
let html = "<!doctype html><html lang=\"en\"><head></head><body></body></html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut count = 0;
|
||||
|
||||
fn test_walk(node: &Handle, i: &mut i8) {
|
||||
|
@ -31,23 +31,23 @@ mod passing {
|
|||
let node_name = name.local.as_ref().to_string();
|
||||
|
||||
if node_name == "html" {
|
||||
assert_eq!(html::get_node_attr(node, "lang"), Some(str!("en")));
|
||||
assert_eq!(html::get_node_attr(node, "lang"), Some("en".to_string()));
|
||||
|
||||
html::set_node_attr(node, "lang", Some(str!("de")));
|
||||
assert_eq!(html::get_node_attr(node, "lang"), Some(str!("de")));
|
||||
html::set_node_attr(node, "lang", Some("de".to_string()));
|
||||
assert_eq!(html::get_node_attr(node, "lang"), Some("de".to_string()));
|
||||
|
||||
html::set_node_attr(node, "lang", None);
|
||||
assert_eq!(html::get_node_attr(node, "lang"), None);
|
||||
|
||||
html::set_node_attr(node, "lang", Some(str!("")));
|
||||
assert_eq!(html::get_node_attr(node, "lang"), Some(str!("")));
|
||||
html::set_node_attr(node, "lang", Some("".to_string()));
|
||||
assert_eq!(html::get_node_attr(node, "lang"), Some("".to_string()));
|
||||
} else if node_name == "body" {
|
||||
assert_eq!(html::get_node_attr(node, "style"), None);
|
||||
|
||||
html::set_node_attr(node, "style", Some(str!("display: none;")));
|
||||
html::set_node_attr(node, "style", Some("display: none;".to_string()));
|
||||
assert_eq!(
|
||||
html::get_node_attr(node, "style"),
|
||||
Some(str!("display: none;"))
|
||||
Some("display: none;".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ mod passing {
|
|||
#[test]
|
||||
fn body_background() {
|
||||
let html = "<!doctype html><html lang=\"en\"><head></head><body background=\"1\" background=\"2\"></body></html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let mut count = 0;
|
||||
|
||||
fn test_walk(node: &Handle, i: &mut i8) {
|
||||
|
@ -84,7 +84,10 @@ mod passing {
|
|||
let node_name = name.local.as_ref().to_string();
|
||||
|
||||
if node_name == "body" {
|
||||
assert_eq!(html::get_node_attr(node, "background"), Some(str!("1")));
|
||||
assert_eq!(
|
||||
html::get_node_attr(node, "background"),
|
||||
Some("1".to_string())
|
||||
);
|
||||
|
||||
html::set_node_attr(node, "background", None);
|
||||
assert_eq!(html::get_node_attr(node, "background"), None);
|
|
@ -12,15 +12,16 @@ mod passing {
|
|||
use std::collections::HashMap;
|
||||
use url::Url;
|
||||
|
||||
use crate::html;
|
||||
use crate::opts::Options;
|
||||
use monolith::html;
|
||||
use monolith::opts::Options;
|
||||
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
let html: &str = "<div><P></P></div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
|
||||
let mut options = Options::default();
|
||||
|
@ -42,7 +43,7 @@ mod passing {
|
|||
#[test]
|
||||
fn ensure_no_recursive_iframe() {
|
||||
let html = "<div><P></P><iframe src=\"\"></iframe></div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -65,7 +66,7 @@ mod passing {
|
|||
#[test]
|
||||
fn ensure_no_recursive_frame() {
|
||||
let html = "<frameset><frame src=\"\"></frameset>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -93,7 +94,7 @@ mod passing {
|
|||
<style>html{background-color: #000;}</style>\
|
||||
<div style=\"display: none;\"></div>\
|
||||
";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -129,7 +130,7 @@ mod passing {
|
|||
fn no_images() {
|
||||
let html = "<link rel=\"icon\" href=\"favicon.ico\">\
|
||||
<div><img src=\"http://localhost/assets/mono_lisa.png\" /></div>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -157,7 +158,7 @@ mod passing {
|
|||
</div>\
|
||||
</body>\
|
||||
</html>",
|
||||
empty_image = empty_image!()
|
||||
empty_image = EMPTY_IMAGE_DATA_URL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ mod passing {
|
|||
fn no_body_background_images() {
|
||||
let html =
|
||||
"<body background=\"no/such/image.png\" background=\"no/such/image2.png\"></body>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -190,7 +191,7 @@ mod passing {
|
|||
#[test]
|
||||
fn no_frames() {
|
||||
let html = "<frameset><frame src=\"http://trackbook.com\"></frameset>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -222,7 +223,7 @@ mod passing {
|
|||
#[test]
|
||||
fn no_iframes() {
|
||||
let html = "<iframe src=\"http://trackbook.com\"></iframe>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -258,7 +259,7 @@ mod passing {
|
|||
<script>alert(1)</script>\
|
||||
</div>\
|
||||
";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -293,7 +294,7 @@ mod passing {
|
|||
fn keeps_integrity_for_unfamiliar_links() {
|
||||
let html = "<title>Has integrity</title>\
|
||||
<link integrity=\"sha384-12345\" rel=\"something\" href=\"https://some-site.com/some-file.ext\" />";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -328,7 +329,7 @@ mod passing {
|
|||
<link integrity=\"\" rel=\"stylesheet\" href=\"data:;\"/>\
|
||||
<script integrity=\"\" src=\"some.js\"></script>\
|
||||
";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -366,7 +367,7 @@ mod passing {
|
|||
<link integrity=\"sha384-123\" rel=\"something\" href=\"data:;\"/>\
|
||||
<script integrity=\"sha384-456\" src=\"some.js\"></script>\
|
||||
";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -410,7 +411,7 @@ mod passing {
|
|||
</body>\
|
||||
</html>\
|
||||
";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -452,7 +453,7 @@ mod passing {
|
|||
</noscript>\
|
||||
</body>\
|
||||
</html>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
||||
|
@ -480,7 +481,7 @@ mod passing {
|
|||
</noscript>\
|
||||
</body>\
|
||||
</html>",
|
||||
empty_image!(),
|
||||
EMPTY_IMAGE_DATA_URL,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -488,7 +489,7 @@ mod passing {
|
|||
#[test]
|
||||
fn preserves_script_type_json() {
|
||||
let html = "<script id=\"data\" type=\"application/json\">{\"mono\":\"lith\"}</script>";
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||
let url: Url = Url::parse("http://localhost").unwrap();
|
||||
let cache = &mut HashMap::new();
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::js;
|
||||
use monolith::js;
|
||||
|
||||
#[test]
|
||||
fn onblur_camelcase() {
|
||||
|
@ -34,7 +34,7 @@ mod passing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use crate::js;
|
||||
use monolith::js;
|
||||
|
||||
#[test]
|
||||
fn href() {
|
|
@ -2,7 +2,7 @@ mod cli;
|
|||
mod css;
|
||||
mod html;
|
||||
mod js;
|
||||
mod macros;
|
||||
// mod macros;
|
||||
mod opts;
|
||||
mod url;
|
||||
mod utils;
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::opts::Options;
|
||||
use monolith::opts::Options;
|
||||
|
||||
#[test]
|
||||
fn defaults() {
|
||||
|
@ -24,12 +24,12 @@ mod passing {
|
|||
assert_eq!(options.no_js, false);
|
||||
assert_eq!(options.insecure, false);
|
||||
assert_eq!(options.no_metadata, false);
|
||||
assert_eq!(options.output, str!());
|
||||
assert_eq!(options.output, "".to_string());
|
||||
assert_eq!(options.silent, false);
|
||||
assert_eq!(options.timeout, 0);
|
||||
assert_eq!(options.user_agent, None);
|
||||
assert_eq!(options.no_video, false);
|
||||
|
||||
assert_eq!(options.target, str!());
|
||||
assert_eq!(options.target, "".to_string());
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
mod passing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn preserve_original() {
|
|
@ -9,7 +9,7 @@
|
|||
mod passing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn encode_string_with_specific_media_type() {
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn mailto() {
|
||||
|
@ -80,7 +80,7 @@ mod passing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn url_with_no_protocol() {
|
|
@ -9,7 +9,7 @@
|
|||
mod passing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn parse_text_html_base64() {
|
||||
|
@ -96,7 +96,7 @@ mod passing {
|
|||
mod failing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn empty_data_url() {
|
|
@ -7,14 +7,15 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn decode_unicode_characters() {
|
||||
assert_eq!(
|
||||
url::percent_decode(str!(
|
||||
url::percent_decode(
|
||||
"%E6%A4%9C%E3%83%92%E3%83%A0%E8%A7%A3%E5%A1%97%E3%82%83%E3%83%83%20%3D%20%E3%82%B5"
|
||||
)),
|
||||
.to_string()
|
||||
),
|
||||
"検ヒム解塗ゃッ = サ"
|
||||
);
|
||||
}
|
||||
|
@ -22,7 +23,7 @@ mod passing {
|
|||
#[test]
|
||||
fn decode_file_url() {
|
||||
assert_eq!(
|
||||
url::percent_decode(str!("file:///tmp/space%20here/test%231.html")),
|
||||
url::percent_decode("file:///tmp/space%20here/test%231.html".to_string()),
|
||||
"file:///tmp/space here/test#1.html"
|
||||
);
|
||||
}
|
||||
|
@ -30,9 +31,10 @@ mod passing {
|
|||
#[test]
|
||||
fn plus_sign() {
|
||||
assert_eq!(
|
||||
url::percent_decode(str!(
|
||||
url::percent_decode(
|
||||
"fonts.somewhere.com/css?family=Open+Sans:300,400,400italic,600,600italic"
|
||||
)),
|
||||
.to_string()
|
||||
),
|
||||
"fonts.somewhere.com/css?family=Open+Sans:300,400,400italic,600,600italic"
|
||||
);
|
||||
}
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn apostrophe() {
|
||||
assert_eq!(url::percent_encode(str!("'")), "%27");
|
||||
assert_eq!(url::percent_encode("'".to_string()), "%27");
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
mod passing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn basic_httsp_relative() {
|
||||
|
@ -211,7 +211,7 @@ mod passing {
|
|||
mod failing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::url;
|
||||
use monolith::url;
|
||||
|
||||
#[test]
|
||||
fn from_data_url_to_url_with_no_protocol() {
|
|
@ -9,7 +9,7 @@
|
|||
mod passing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::utils;
|
||||
use monolith::utils;
|
||||
|
||||
#[test]
|
||||
fn image_gif87() {
|
||||
|
@ -188,7 +188,7 @@ mod passing {
|
|||
mod failing {
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::utils;
|
||||
use monolith::utils;
|
||||
|
||||
#[test]
|
||||
fn unknown_media_type() {
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::utils;
|
||||
use monolith::utils;
|
||||
|
||||
#[test]
|
||||
fn zero() {
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
mod passing {
|
||||
use crate::utils;
|
||||
use monolith::utils;
|
||||
|
||||
#[test]
|
||||
fn text_plain_utf8() {
|
|
@ -12,9 +12,9 @@ mod passing {
|
|||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
|
||||
use crate::opts::Options;
|
||||
use crate::url;
|
||||
use crate::utils;
|
||||
use monolith::opts::Options;
|
||||
use monolith::url;
|
||||
use monolith::utils;
|
||||
|
||||
#[test]
|
||||
fn read_data_url() {
|
||||
|
@ -63,13 +63,13 @@ mod passing {
|
|||
cache,
|
||||
&client,
|
||||
&Url::parse(&format!(
|
||||
"{file}{cwd}/src/tests/data/basic/local-file.html",
|
||||
"{file}{cwd}/tests/data/basic/local-file.html",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd.to_str().unwrap()
|
||||
))
|
||||
.unwrap(),
|
||||
&Url::parse(&format!(
|
||||
"{file}{cwd}/src/tests/data/basic/local-script.js",
|
||||
"{file}{cwd}/tests/data/basic/local-script.js",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd.to_str().unwrap()
|
||||
))
|
||||
|
@ -84,7 +84,7 @@ mod passing {
|
|||
assert_eq!(
|
||||
final_url,
|
||||
Url::parse(&format!(
|
||||
"{file}{cwd}/src/tests/data/basic/local-script.js",
|
||||
"{file}{cwd}/tests/data/basic/local-script.js",
|
||||
file = file_url_protocol,
|
||||
cwd = cwd.to_str().unwrap()
|
||||
))
|
||||
|
@ -106,8 +106,8 @@ mod failing {
|
|||
use reqwest::Url;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::opts::Options;
|
||||
use crate::utils;
|
||||
use monolith::opts::Options;
|
||||
use monolith::utils;
|
||||
|
||||
#[test]
|
||||
fn read_local_file_with_data_url_parent() {
|
Loading…
Reference in a new issue