From 2cc1870033db8564e7d9383b77d9bbb0a7ba9294 Mon Sep 17 00:00:00 2001 From: Sunshine Date: Sat, 16 Oct 2021 21:16:37 -1000 Subject: [PATCH] get rid of macros, move tests out of src --- src/css.rs | 36 +++++------ src/html.rs | 48 ++++++++------ src/lib.rs | 9 --- src/macros.rs | 17 ----- src/main.rs | 15 +++-- src/opts.rs | 8 +-- src/url.rs | 9 ++- src/utils.rs | 12 ++-- {src/tests => tests}/cli/base_url.rs | 0 {src/tests => tests}/cli/basic.rs | 4 +- {src/tests => tests}/cli/data_url.rs | 4 +- {src/tests => tests}/cli/local_files.rs | 63 +++++++++++-------- {src/tests => tests}/cli/mod.rs | 0 {src/tests => tests}/cli/noscript.rs | 16 ++--- {src/tests => tests}/cli/unusual_encodings.rs | 22 +++---- {src/tests => tests}/css/embed_css.rs | 9 +-- {src/tests => tests}/css/is_image_url_prop.rs | 4 +- {src/tests => tests}/css/mod.rs | 0 .../data/basic/local-file.html | 0 .../data/basic/local-script.js | 0 .../data/basic/local-style.css | 0 {src/tests => tests}/data/css/index.html | 0 {src/tests => tests}/data/css/style.css | 0 .../data/import-css-via-data-url/index.html | 0 .../data/import-css-via-data-url/style.css | 0 .../tests => tests}/data/integrity/index.html | 0 {src/tests => tests}/data/integrity/script.js | 0 {src/tests => tests}/data/integrity/style.css | 0 {src/tests => tests}/data/noscript/image.svg | 0 {src/tests => tests}/data/noscript/index.html | 0 .../tests => tests}/data/noscript/nested.html | 0 .../tests => tests}/data/noscript/script.html | 0 {src/tests => tests}/data/svg/image.svg | 0 {src/tests => tests}/data/svg/index.html | 0 .../data/unusual_encodings/gb2312.html | 0 .../data/unusual_encodings/iso-8859-1.html | 0 {src/tests => tests}/html/add_favicon.rs | 4 +- {src/tests => tests}/html/check_integrity.rs | 4 +- {src/tests => tests}/html/compose_csp.rs | 4 +- .../html/create_metadata_tag.rs | 2 +- {src/tests => tests}/html/embed_srcset.rs | 24 ++++--- {src/tests => tests}/html/get_base_url.rs | 20 +++--- {src/tests => tests}/html/get_charset.rs | 18 +++--- {src/tests => tests}/html/get_node_attr.rs | 6 +- {src/tests => tests}/html/get_node_name.rs | 4 +- {src/tests => tests}/html/has_favicon.rs | 10 +-- {src/tests => tests}/html/is_icon.rs | 4 +- {src/tests => tests}/html/mod.rs | 0 .../html/serialize_document.rs | 24 +++---- {src/tests => tests}/html/set_node_attr.rs | 25 ++++---- .../html/walk_and_embed_assets.rs | 39 ++++++------ .../js/attr_is_event_handler.rs | 4 +- {src/tests => tests}/js/mod.rs | 0 {src/tests => tests}/macros/empty_image.rs | 0 {src/tests => tests}/macros/mod.rs | 0 {src/tests => tests}/macros/str.rs | 0 {src/tests => tests}/mod.rs | 2 +- {src/tests => tests}/opts.rs | 6 +- {src/tests => tests}/url/clean_url.rs | 2 +- {src/tests => tests}/url/create_data_url.rs | 2 +- .../url/is_url_and_has_protocol.rs | 4 +- {src/tests => tests}/url/mod.rs | 0 {src/tests => tests}/url/parse_data_url.rs | 4 +- {src/tests => tests}/url/percent_decode.rs | 14 +++-- {src/tests => tests}/url/percent_encode.rs | 4 +- {src/tests => tests}/url/resolve_url.rs | 4 +- .../utils/detect_media_type.rs | 4 +- {src/tests => tests}/utils/indent.rs | 2 +- {src/tests => tests}/utils/mod.rs | 0 .../utils/parse_content_type.rs | 2 +- {src/tests => tests}/utils/retrieve_asset.rs | 16 ++--- 71 files changed, 272 insertions(+), 262 deletions(-) delete mode 100644 src/macros.rs rename {src/tests => tests}/cli/base_url.rs (100%) rename {src/tests => tests}/cli/basic.rs (97%) rename {src/tests => tests}/cli/data_url.rs (98%) rename {src/tests => tests}/cli/local_files.rs (84%) rename {src/tests => tests}/cli/mod.rs (100%) rename {src/tests => tests}/cli/noscript.rs (92%) rename {src/tests => tests}/cli/unusual_encodings.rs (91%) rename {src/tests => tests}/css/embed_css.rs (98%) rename {src/tests => tests}/css/is_image_url_prop.rs (98%) rename {src/tests => tests}/css/mod.rs (100%) rename {src/tests => tests}/data/basic/local-file.html (100%) rename {src/tests => tests}/data/basic/local-script.js (100%) rename {src/tests => tests}/data/basic/local-style.css (100%) rename {src/tests => tests}/data/css/index.html (100%) rename {src/tests => tests}/data/css/style.css (100%) rename {src/tests => tests}/data/import-css-via-data-url/index.html (100%) rename {src/tests => tests}/data/import-css-via-data-url/style.css (100%) rename {src/tests => tests}/data/integrity/index.html (100%) rename {src/tests => tests}/data/integrity/script.js (100%) rename {src/tests => tests}/data/integrity/style.css (100%) rename {src/tests => tests}/data/noscript/image.svg (100%) rename {src/tests => tests}/data/noscript/index.html (100%) rename {src/tests => tests}/data/noscript/nested.html (100%) rename {src/tests => tests}/data/noscript/script.html (100%) rename {src/tests => tests}/data/svg/image.svg (100%) rename {src/tests => tests}/data/svg/index.html (100%) rename {src/tests => tests}/data/unusual_encodings/gb2312.html (100%) rename {src/tests => tests}/data/unusual_encodings/iso-8859-1.html (100%) rename {src/tests => tests}/html/add_favicon.rs (97%) rename {src/tests => tests}/html/check_integrity.rs (98%) rename {src/tests => tests}/html/compose_csp.rs (98%) rename {src/tests => tests}/html/create_metadata_tag.rs (99%) rename {src/tests => tests}/html/embed_srcset.rs (89%) rename {src/tests => tests}/html/get_base_url.rs (82%) rename {src/tests => tests}/html/get_charset.rs (74%) rename {src/tests => tests}/html/get_node_attr.rs (93%) rename {src/tests => tests}/html/get_node_name.rs (95%) rename {src/tests => tests}/html/has_favicon.rs (88%) rename {src/tests => tests}/html/is_icon.rs (98%) rename {src/tests => tests}/html/mod.rs (100%) rename {src/tests => tests}/html/serialize_document.rs (90%) rename {src/tests => tests}/html/set_node_attr.rs (84%) rename {src/tests => tests}/html/walk_and_embed_assets.rs (92%) rename {src/tests => tests}/js/attr_is_event_handler.rs (98%) rename {src/tests => tests}/js/mod.rs (100%) rename {src/tests => tests}/macros/empty_image.rs (100%) rename {src/tests => tests}/macros/mod.rs (100%) rename {src/tests => tests}/macros/str.rs (100%) rename {src/tests => tests}/mod.rs (81%) rename {src/tests => tests}/opts.rs (92%) rename {src/tests => tests}/url/clean_url.rs (99%) rename {src/tests => tests}/url/create_data_url.rs (99%) rename {src/tests => tests}/url/is_url_and_has_protocol.rs (98%) rename {src/tests => tests}/url/mod.rs (100%) rename {src/tests => tests}/url/parse_data_url.rs (99%) rename {src/tests => tests}/url/percent_decode.rs (85%) rename {src/tests => tests}/url/percent_encode.rs (91%) rename {src/tests => tests}/url/resolve_url.rs (99%) rename {src/tests => tests}/utils/detect_media_type.rs (99%) rename {src/tests => tests}/utils/indent.rs (98%) rename {src/tests => tests}/utils/mod.rs (100%) rename {src/tests => tests}/utils/parse_content_type.rs (99%) rename {src/tests => tests}/utils/retrieve_asset.rs (94%) diff --git a/src/css.rs b/src/css.rs index 40f5810..2e16df7 100644 --- a/src/css.rs +++ b/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> { - 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( diff --git a/src/html.rs b/src/html.rs index 25abcf3..36654ea 100644 --- a/src/html.rs +++ b/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 { 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, diff --git a/src/lib.rs b/src/lib.rs index cfe8147..57cd530 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/macros.rs b/src/macros.rs deleted file mode 100644 index b93329c..0000000 --- a/src/macros.rs +++ /dev/null @@ -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=" - }; -} diff --git a/src/main.rs b/src/main.rs index d3b88b1..d0fe745 100644 --- a/src/main.rs +++ b/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 { 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; - 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 diff --git a/src/opts.rs b/src/opts.rs index 2ca692b..58cd3c7 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -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::() .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()); } diff --git a/src/url.rs b/src/url.rs index 8f0221b..d360a81 100644 --- a/src/url.rs +++ b/src/url.rs @@ -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(), ] diff --git a/src/utils.rs b/src/utils.rs index 1bd2b65..4985ed4 100644 --- a/src/utils.rs +++ b/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 diff --git a/src/tests/cli/base_url.rs b/tests/cli/base_url.rs similarity index 100% rename from src/tests/cli/base_url.rs rename to tests/cli/base_url.rs diff --git a/src/tests/cli/basic.rs b/tests/cli/basic.rs similarity index 97% rename from src/tests/cli/basic.rs rename to tests/cli/basic.rs index df7390a..0304626 100644 --- a/src/tests/cli/basic.rs +++ b/tests/cli/basic.rs @@ -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()); diff --git a/src/tests/cli/data_url.rs b/tests/cli/data_url.rs similarity index 98% rename from src/tests/cli/data_url.rs rename to tests/cli/data_url.rs index c89c9d4..9c65a53 100644 --- a/src/tests/cli/data_url.rs +++ b/tests/cli/data_url.rs @@ -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\ \ \n", - empty_image = empty_image!() + empty_image = EMPTY_IMAGE_DATA_URL, ) ); diff --git a/src/tests/cli/local_files.rs b/tests/cli/local_files.rs similarity index 84% rename from src/tests/cli/local_files.rs rename to tests/cli/local_files.rs index d27af67..5304059 100644 --- a/src/tests/cli/local_files.rs +++ b/tests/cli/local_files.rs @@ -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 { \n\n\n\n\ \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 { \n\n\n\n\ \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, diff --git a/src/tests/cli/mod.rs b/tests/cli/mod.rs similarity index 100% rename from src/tests/cli/mod.rs rename to tests/cli/mod.rs diff --git a/src/tests/cli/noscript.rs b/tests/cli/noscript.rs similarity index 92% rename from src/tests/cli/noscript.rs rename to tests/cli/noscript.rs index 85ebfdd..f988eda 100644 --- a/src/tests/cli/noscript.rs +++ b/tests/cli/noscript.rs @@ -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(); diff --git a/src/tests/cli/unusual_encodings.rs b/tests/cli/unusual_encodings.rs similarity index 91% rename from src/tests/cli/unusual_encodings.rs rename to tests/cli/unusual_encodings.rs index 9a1dca3..acfa849 100644 --- a/src/tests/cli/unusual_encodings.rs +++ b/tests/cli/unusual_encodings.rs @@ -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, ) diff --git a/src/tests/css/embed_css.rs b/tests/css/embed_css.rs similarity index 98% rename from src/tests/css/embed_css.rs rename to tests/css/embed_css.rs index aeae5dc..b8e2a97 100644 --- a/src/tests/css/embed_css.rs +++ b/tests/css/embed_css.rs @@ -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 ) ); } diff --git a/src/tests/css/is_image_url_prop.rs b/tests/css/is_image_url_prop.rs similarity index 98% rename from src/tests/css/is_image_url_prop.rs rename to tests/css/is_image_url_prop.rs index 19f71fd..64fb9e6 100644 --- a/src/tests/css/is_image_url_prop.rs +++ b/tests/css/is_image_url_prop.rs @@ -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() { diff --git a/src/tests/css/mod.rs b/tests/css/mod.rs similarity index 100% rename from src/tests/css/mod.rs rename to tests/css/mod.rs diff --git a/src/tests/data/basic/local-file.html b/tests/data/basic/local-file.html similarity index 100% rename from src/tests/data/basic/local-file.html rename to tests/data/basic/local-file.html diff --git a/src/tests/data/basic/local-script.js b/tests/data/basic/local-script.js similarity index 100% rename from src/tests/data/basic/local-script.js rename to tests/data/basic/local-script.js diff --git a/src/tests/data/basic/local-style.css b/tests/data/basic/local-style.css similarity index 100% rename from src/tests/data/basic/local-style.css rename to tests/data/basic/local-style.css diff --git a/src/tests/data/css/index.html b/tests/data/css/index.html similarity index 100% rename from src/tests/data/css/index.html rename to tests/data/css/index.html diff --git a/src/tests/data/css/style.css b/tests/data/css/style.css similarity index 100% rename from src/tests/data/css/style.css rename to tests/data/css/style.css diff --git a/src/tests/data/import-css-via-data-url/index.html b/tests/data/import-css-via-data-url/index.html similarity index 100% rename from src/tests/data/import-css-via-data-url/index.html rename to tests/data/import-css-via-data-url/index.html diff --git a/src/tests/data/import-css-via-data-url/style.css b/tests/data/import-css-via-data-url/style.css similarity index 100% rename from src/tests/data/import-css-via-data-url/style.css rename to tests/data/import-css-via-data-url/style.css diff --git a/src/tests/data/integrity/index.html b/tests/data/integrity/index.html similarity index 100% rename from src/tests/data/integrity/index.html rename to tests/data/integrity/index.html diff --git a/src/tests/data/integrity/script.js b/tests/data/integrity/script.js similarity index 100% rename from src/tests/data/integrity/script.js rename to tests/data/integrity/script.js diff --git a/src/tests/data/integrity/style.css b/tests/data/integrity/style.css similarity index 100% rename from src/tests/data/integrity/style.css rename to tests/data/integrity/style.css diff --git a/src/tests/data/noscript/image.svg b/tests/data/noscript/image.svg similarity index 100% rename from src/tests/data/noscript/image.svg rename to tests/data/noscript/image.svg diff --git a/src/tests/data/noscript/index.html b/tests/data/noscript/index.html similarity index 100% rename from src/tests/data/noscript/index.html rename to tests/data/noscript/index.html diff --git a/src/tests/data/noscript/nested.html b/tests/data/noscript/nested.html similarity index 100% rename from src/tests/data/noscript/nested.html rename to tests/data/noscript/nested.html diff --git a/src/tests/data/noscript/script.html b/tests/data/noscript/script.html similarity index 100% rename from src/tests/data/noscript/script.html rename to tests/data/noscript/script.html diff --git a/src/tests/data/svg/image.svg b/tests/data/svg/image.svg similarity index 100% rename from src/tests/data/svg/image.svg rename to tests/data/svg/image.svg diff --git a/src/tests/data/svg/index.html b/tests/data/svg/index.html similarity index 100% rename from src/tests/data/svg/index.html rename to tests/data/svg/index.html diff --git a/src/tests/data/unusual_encodings/gb2312.html b/tests/data/unusual_encodings/gb2312.html similarity index 100% rename from src/tests/data/unusual_encodings/gb2312.html rename to tests/data/unusual_encodings/gb2312.html diff --git a/src/tests/data/unusual_encodings/iso-8859-1.html b/tests/data/unusual_encodings/iso-8859-1.html similarity index 100% rename from src/tests/data/unusual_encodings/iso-8859-1.html rename to tests/data/unusual_encodings/iso-8859-1.html diff --git a/src/tests/html/add_favicon.rs b/tests/html/add_favicon.rs similarity index 97% rename from src/tests/html/add_favicon.rs rename to tests/html/add_favicon.rs index ef83553..a276aca 100644 --- a/src/tests/html/add_favicon.rs +++ b/tests/html/add_favicon.rs @@ -9,12 +9,12 @@ mod passing { use html5ever::serialize::{serialize, SerializeOpts}; - use crate::html; + use monolith::html; #[test] fn basic() { let html = "
text
"; - 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()); diff --git a/src/tests/html/check_integrity.rs b/tests/html/check_integrity.rs similarity index 98% rename from src/tests/html/check_integrity.rs rename to tests/html/check_integrity.rs index 121e412..cb93071 100644 --- a/src/tests/html/check_integrity.rs +++ b/tests/html/check_integrity.rs @@ -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() { diff --git a/src/tests/html/compose_csp.rs b/tests/html/compose_csp.rs similarity index 98% rename from src/tests/html/compose_csp.rs rename to tests/html/compose_csp.rs index a05b450..ae3e7a4 100644 --- a/src/tests/html/compose_csp.rs +++ b/tests/html/compose_csp.rs @@ -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() { diff --git a/src/tests/html/create_metadata_tag.rs b/tests/html/create_metadata_tag.rs similarity index 99% rename from src/tests/html/create_metadata_tag.rs rename to tests/html/create_metadata_tag.rs index 12a11d2..fa12a36 100644 --- a/src/tests/html/create_metadata_tag.rs +++ b/tests/html/create_metadata_tag.rs @@ -10,7 +10,7 @@ mod passing { use chrono::prelude::*; use reqwest::Url; - use crate::html; + use monolith::html; #[test] fn http_url() { diff --git a/src/tests/html/embed_srcset.rs b/tests/html/embed_srcset.rs similarity index 89% rename from src/tests/html/embed_srcset.rs rename to tests/html/embed_srcset.rs index 1f920cd..f130c19 100644 --- a/src/tests/html/embed_srcset.rs +++ b/tests/html/embed_srcset.rs @@ -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), ); } } diff --git a/src/tests/html/get_base_url.rs b/tests/html/get_base_url.rs similarity index 82% rename from src/tests/html/get_base_url.rs rename to tests/html/get_base_url.rs index d240040..a87799e 100644 --- a/src/tests/html/get_base_url.rs +++ b/tests/html/get_base_url.rs @@ -7,7 +7,7 @@ #[cfg(test)] mod passing { - use crate::html; + use monolith::html; #[test] fn present() { @@ -19,11 +19,11 @@ mod passing { "; - 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 { "; - 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 { "; - 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 { "; - 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 { "; - 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())); } } diff --git a/src/tests/html/get_charset.rs b/tests/html/get_charset.rs similarity index 74% rename from src/tests/html/get_charset.rs rename to tests/html/get_charset.rs index 89751ba..9232f99 100644 --- a/src/tests/html/get_charset.rs +++ b/tests/html/get_charset.rs @@ -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 { "; - 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 { "; - 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 { "; - 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 { "; - 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())); } } diff --git a/src/tests/html/get_node_attr.rs b/tests/html/get_node_attr.rs similarity index 93% rename from src/tests/html/get_node_attr.rs rename to tests/html/get_node_attr.rs index f7823b9..2be351c 100644 --- a/src/tests/html/get_node_attr.rs +++ b/tests/html/get_node_attr.rs @@ -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 = "
"; - 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()) ); } diff --git a/src/tests/html/get_node_name.rs b/tests/html/get_node_name.rs similarity index 95% rename from src/tests/html/get_node_name.rs rename to tests/html/get_node_name.rs index 49ffbed..7019206 100644 --- a/src/tests/html/get_node_name.rs +++ b/tests/html/get_node_name.rs @@ -9,12 +9,12 @@ mod passing { use html5ever::rcdom::{Handle, NodeData}; - use crate::html; + use monolith::html; #[test] fn parent_node_names() { let 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) { diff --git a/src/tests/html/has_favicon.rs b/tests/html/has_favicon.rs similarity index 88% rename from src/tests/html/has_favicon.rs rename to tests/html/has_favicon.rs index f9f7541..96f3d60 100644 --- a/src/tests/html/has_favicon.rs +++ b/tests/html/has_favicon.rs @@ -7,12 +7,12 @@ #[cfg(test)] mod passing { - use crate::html; + use monolith::html; #[test] fn icon() { let html = "
text
"; - 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 = "
text
"; - 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 = "
text
"; - 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); diff --git a/src/tests/html/is_icon.rs b/tests/html/is_icon.rs similarity index 98% rename from src/tests/html/is_icon.rs rename to tests/html/is_icon.rs index cc531bf..a29f136 100644 --- a/src/tests/html/is_icon.rs +++ b/tests/html/is_icon.rs @@ -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() { diff --git a/src/tests/html/mod.rs b/tests/html/mod.rs similarity index 100% rename from src/tests/html/mod.rs rename to tests/html/mod.rs diff --git a/src/tests/html/serialize_document.rs b/tests/html/serialize_document.rs similarity index 90% rename from src/tests/html/serialize_document.rs rename to tests/html/serialize_document.rs index 11ae0c5..3cf648b 100644 --- a/src/tests/html/serialize_document.rs +++ b/tests/html/serialize_document.rs @@ -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 = "
"; - 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)), "
" ); } @@ -28,14 +28,14 @@ mod passing { \ \
"; - 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 )), "\ @@ -60,12 +60,12 @@ mod passing { Unstyled document\ \
"; - 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)), "\ \ \ @@ -84,14 +84,14 @@ mod passing { Frameless document\ \
"; - 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 )), "\ @@ -117,7 +117,7 @@ mod passing { \ \ "; - 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 )), "\ diff --git a/src/tests/html/set_node_attr.rs b/tests/html/set_node_attr.rs similarity index 84% rename from src/tests/html/set_node_attr.rs rename to tests/html/set_node_attr.rs index 9366f20..120e44d 100644 --- a/src/tests/html/set_node_attr.rs +++ b/tests/html/set_node_attr.rs @@ -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 = ""; - 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 = ""; - 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); diff --git a/src/tests/html/walk_and_embed_assets.rs b/tests/html/walk_and_embed_assets.rs similarity index 92% rename from src/tests/html/walk_and_embed_assets.rs rename to tests/html/walk_and_embed_assets.rs index d06e2a1..5db25a5 100644 --- a/src/tests/html/walk_and_embed_assets.rs +++ b/tests/html/walk_and_embed_assets.rs @@ -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 = "

"; - 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 = "

"; - 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 = ""; - 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 { \
\ "; - 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 = "\
"; - 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 { \ \ ", - empty_image = empty_image!() + empty_image = EMPTY_IMAGE_DATA_URL ) ); } @@ -166,7 +167,7 @@ mod passing { fn no_body_background_images() { let 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(); @@ -190,7 +191,7 @@ mod passing { #[test] fn no_frames() { let 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(); @@ -222,7 +223,7 @@ mod passing { #[test] fn no_iframes() { let 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(); @@ -258,7 +259,7 @@ mod passing { \ \ "; - 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 = "Has integrity\ "; - 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 { \ \ "; - 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 { \ \ "; - 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 { \ \ "; - 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 { \ \ "; - 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 { \ \ ", - empty_image!(), + EMPTY_IMAGE_DATA_URL, ) ); } @@ -488,7 +489,7 @@ mod passing { #[test] fn preserves_script_type_json() { let 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(); diff --git a/src/tests/js/attr_is_event_handler.rs b/tests/js/attr_is_event_handler.rs similarity index 98% rename from src/tests/js/attr_is_event_handler.rs rename to tests/js/attr_is_event_handler.rs index a64604d..6eee38e 100644 --- a/src/tests/js/attr_is_event_handler.rs +++ b/tests/js/attr_is_event_handler.rs @@ -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() { diff --git a/src/tests/js/mod.rs b/tests/js/mod.rs similarity index 100% rename from src/tests/js/mod.rs rename to tests/js/mod.rs diff --git a/src/tests/macros/empty_image.rs b/tests/macros/empty_image.rs similarity index 100% rename from src/tests/macros/empty_image.rs rename to tests/macros/empty_image.rs diff --git a/src/tests/macros/mod.rs b/tests/macros/mod.rs similarity index 100% rename from src/tests/macros/mod.rs rename to tests/macros/mod.rs diff --git a/src/tests/macros/str.rs b/tests/macros/str.rs similarity index 100% rename from src/tests/macros/str.rs rename to tests/macros/str.rs diff --git a/src/tests/mod.rs b/tests/mod.rs similarity index 81% rename from src/tests/mod.rs rename to tests/mod.rs index cc7d93b..3ce2821 100644 --- a/src/tests/mod.rs +++ b/tests/mod.rs @@ -2,7 +2,7 @@ mod cli; mod css; mod html; mod js; -mod macros; +// mod macros; mod opts; mod url; mod utils; diff --git a/src/tests/opts.rs b/tests/opts.rs similarity index 92% rename from src/tests/opts.rs rename to tests/opts.rs index b138b57..f307ec3 100644 --- a/src/tests/opts.rs +++ b/tests/opts.rs @@ -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()); } } diff --git a/src/tests/url/clean_url.rs b/tests/url/clean_url.rs similarity index 99% rename from src/tests/url/clean_url.rs rename to tests/url/clean_url.rs index 1f31bd7..33c494f 100644 --- a/src/tests/url/clean_url.rs +++ b/tests/url/clean_url.rs @@ -9,7 +9,7 @@ mod passing { use reqwest::Url; - use crate::url; + use monolith::url; #[test] fn preserve_original() { diff --git a/src/tests/url/create_data_url.rs b/tests/url/create_data_url.rs similarity index 99% rename from src/tests/url/create_data_url.rs rename to tests/url/create_data_url.rs index f6c3cd5..c5b72ca 100644 --- a/src/tests/url/create_data_url.rs +++ b/tests/url/create_data_url.rs @@ -9,7 +9,7 @@ mod passing { use reqwest::Url; - use crate::url; + use monolith::url; #[test] fn encode_string_with_specific_media_type() { diff --git a/src/tests/url/is_url_and_has_protocol.rs b/tests/url/is_url_and_has_protocol.rs similarity index 98% rename from src/tests/url/is_url_and_has_protocol.rs rename to tests/url/is_url_and_has_protocol.rs index a46690b..38a1d8f 100644 --- a/src/tests/url/is_url_and_has_protocol.rs +++ b/tests/url/is_url_and_has_protocol.rs @@ -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() { diff --git a/src/tests/url/mod.rs b/tests/url/mod.rs similarity index 100% rename from src/tests/url/mod.rs rename to tests/url/mod.rs diff --git a/src/tests/url/parse_data_url.rs b/tests/url/parse_data_url.rs similarity index 99% rename from src/tests/url/parse_data_url.rs rename to tests/url/parse_data_url.rs index c4a6063..dc6f5af 100644 --- a/src/tests/url/parse_data_url.rs +++ b/tests/url/parse_data_url.rs @@ -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() { diff --git a/src/tests/url/percent_decode.rs b/tests/url/percent_decode.rs similarity index 85% rename from src/tests/url/percent_decode.rs rename to tests/url/percent_decode.rs index 8972f58..d884bad 100644 --- a/src/tests/url/percent_decode.rs +++ b/tests/url/percent_decode.rs @@ -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" ); } diff --git a/src/tests/url/percent_encode.rs b/tests/url/percent_encode.rs similarity index 91% rename from src/tests/url/percent_encode.rs rename to tests/url/percent_encode.rs index 3fa1c21..fb3555d 100644 --- a/src/tests/url/percent_encode.rs +++ b/tests/url/percent_encode.rs @@ -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"); } } diff --git a/src/tests/url/resolve_url.rs b/tests/url/resolve_url.rs similarity index 99% rename from src/tests/url/resolve_url.rs rename to tests/url/resolve_url.rs index 4abede9..c2cc486 100644 --- a/src/tests/url/resolve_url.rs +++ b/tests/url/resolve_url.rs @@ -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() { diff --git a/src/tests/utils/detect_media_type.rs b/tests/utils/detect_media_type.rs similarity index 99% rename from src/tests/utils/detect_media_type.rs rename to tests/utils/detect_media_type.rs index 970af13..f1eeb09 100644 --- a/src/tests/utils/detect_media_type.rs +++ b/tests/utils/detect_media_type.rs @@ -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() { diff --git a/src/tests/utils/indent.rs b/tests/utils/indent.rs similarity index 98% rename from src/tests/utils/indent.rs rename to tests/utils/indent.rs index fb706b3..6879fd0 100644 --- a/src/tests/utils/indent.rs +++ b/tests/utils/indent.rs @@ -7,7 +7,7 @@ #[cfg(test)] mod passing { - use crate::utils; + use monolith::utils; #[test] fn zero() { diff --git a/src/tests/utils/mod.rs b/tests/utils/mod.rs similarity index 100% rename from src/tests/utils/mod.rs rename to tests/utils/mod.rs diff --git a/src/tests/utils/parse_content_type.rs b/tests/utils/parse_content_type.rs similarity index 99% rename from src/tests/utils/parse_content_type.rs rename to tests/utils/parse_content_type.rs index 07e4cc0..121a1b5 100644 --- a/src/tests/utils/parse_content_type.rs +++ b/tests/utils/parse_content_type.rs @@ -7,7 +7,7 @@ #[cfg(test)] mod passing { - use crate::utils; + use monolith::utils; #[test] fn text_plain_utf8() { diff --git a/src/tests/utils/retrieve_asset.rs b/tests/utils/retrieve_asset.rs similarity index 94% rename from src/tests/utils/retrieve_asset.rs rename to tests/utils/retrieve_asset.rs index 1d12559..2c61a0d 100644 --- a/src/tests/utils/retrieve_asset.rs +++ b/tests/utils/retrieve_asset.rs @@ -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() {