diff --git a/tests/cli/base_url.rs b/tests/cli/base_url.rs index d84932f6..c5631661 100644 --- a/tests/cli/base_url.rs +++ b/tests/cli/base_url.rs @@ -28,9 +28,8 @@ mod passing { // STDOUT should contain newly added base URL assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - Hello, World!\n" + r#"Hello, World! +"# ); // Exit code should be 0 @@ -42,7 +41,7 @@ mod passing { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); let out = cmd .arg("-M") - .arg("data:text/html,Hello%2C%20World!") + .arg(r#"data:text/html,Hello%2C%20World!"#) .output() .unwrap(); @@ -52,9 +51,8 @@ mod passing { // STDOUT should contain newly added base URL assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - Hello, World!\n" + r#"Hello, World! +"# ); // Exit code should be 0 @@ -68,7 +66,7 @@ mod passing { .arg("-M") .arg("-b") .arg("http://localhost/") - .arg("data:text/html,Hello%2C%20World!") + .arg(r#"data:text/html,Hello%2C%20World!"#) .output() .unwrap(); @@ -78,9 +76,8 @@ mod passing { // STDOUT should contain newly added base URL assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - Hello, World!\n" + r#"Hello, World! +"# ); // Exit code should be 0 @@ -94,7 +91,7 @@ mod passing { .arg("-M") .arg("-b") .arg("") - .arg("data:text/html,Hello%2C%20World!") + .arg(r#"data:text/html,Hello%2C%20World!"#) .output() .unwrap(); @@ -104,9 +101,8 @@ mod passing { // STDOUT should contain newly added base URL assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - Hello, World!\n" + r#"Hello, World! +"# ); // Exit code should be 0 diff --git a/tests/cli/basic.rs b/tests/cli/basic.rs index 96cff8b6..d3e2dbaa 100644 --- a/tests/cli/basic.rs +++ b/tests/cli/basic.rs @@ -67,7 +67,9 @@ mod passing { // STDOUT should contain HTML created out of STDIN assert_eq!( String::from_utf8_lossy(&out.stdout), - "Hello from STDIN\n\n" + r#"Hello from STDIN + +"# ); // Exit code should be 0 @@ -103,7 +105,19 @@ mod passing { // STDOUT should contain embedded CSS url()'s assert_eq!( String::from_utf8_lossy(&out.stdout), - "\n\n" + r##" + +"## ); // Exit code should be 0 diff --git a/tests/cli/data_url.rs b/tests/cli/data_url.rs index 78ed811a..9f55ea5e 100644 --- a/tests/cli/data_url.rs +++ b/tests/cli/data_url.rs @@ -29,9 +29,8 @@ mod passing { // STDOUT should contain isolated HTML assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - Hello, World!\n" + r#"Hello, World! +"# ); // Exit code should be 0 @@ -54,10 +53,8 @@ mod passing { // STDOUT should contain HTML with no CSS assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - \ - Hello\n" + r#"Hello +"# ); // Exit code should be 0 @@ -80,10 +77,8 @@ mod passing { // STDOUT should contain HTML with no web fonts assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - \ - Hi\n" + r#"Hi +"# ); // Exit code should be 0 @@ -96,7 +91,7 @@ mod passing { let out = cmd .arg("-M") .arg("-f") - .arg("data:text/html,Hi") + .arg(r#"data:text/html,Hi"#) .output() .unwrap(); @@ -106,9 +101,8 @@ mod passing { // STDOUT should contain HTML with no iframes assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - Hi\n" + r#"Hi +"# ); // Exit code should be 0 @@ -132,15 +126,8 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stdout), format!( - "\ - \ - \ - \ - \ - \ - Hi\ - \ - \n", + r#"Hi +"#, empty_image = EMPTY_IMAGE_DATA_URL, ) ); @@ -165,12 +152,8 @@ mod passing { // STDOUT should contain HTML with no JS assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - \ - \ - Hi\ - \n" + r#"Hi +"# ); // Exit code should be 0 @@ -211,7 +194,7 @@ mod failing { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); let out = cmd .arg("-M") - .arg("data:text/html,%3Cscript%20src=\"src/tests/data/basic/local-script.js\"%3E%3C/script%3E") + .arg(r#"data:text/html,%3Cscript%20src="src/tests/data/basic/local-script.js"%3E%3C/script%3E"#) .output() .unwrap(); diff --git a/tests/cli/local_files.rs b/tests/cli/local_files.rs index f0adb6de..07f89290 100644 --- a/tests/cli/local_files.rs +++ b/tests/cli/local_files.rs @@ -38,13 +38,12 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stderr), format!( - "\ - {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 (file not found)\n\ - {file}{cwd}/tests/_data_/basic/monolith.png (file not found)\n\ - {file}{cwd}/tests/_data_/basic/local-script.js\n\ - ", + r#"{file}{cwd}/tests/_data_/basic/local-file.html +{file}{cwd}/tests/_data_/basic/local-style.css +{file}{cwd}/tests/_data_/basic/local-style-does-not-exist.css (file not found) +{file}{cwd}/tests/_data_/basic/monolith.png (file not found) +{file}{cwd}/tests/_data_/basic/local-script.js +"#, file = file_url_protocol, cwd = cwd_normalized ) @@ -53,18 +52,25 @@ mod passing { // STDOUT should contain HTML from the local file assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \n \ - \n \ - Local HTML file\n \ - \n \ - \n\n\n\n \ - \"\"\n \ - Tricky href\n \ - Remote URL\n \ - \n\n\n\n\ - \n\ - " + r##" + + Local HTML file + + + + + + + Tricky href + Remote URL + + + + + +"## ); // Exit code should be 0 @@ -96,19 +102,23 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stdout), format!( - "\ - \ - \n \ - \n \ - Local HTML file\n \ - \n \ - \n\n\n\n \ - \"\"\n \ - Tricky href\n \ - Remote URL\n \ - \n\n\n\n\ - \n\ - ", + r##" + + Local HTML file + + + + + + + Tricky href + Remote URL + + + + + +"##, empty_image = EMPTY_IMAGE_DATA_URL ) ); @@ -151,19 +161,23 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stdout), format!( - "\ - \ - \n \ - \n \ - Local HTML file\n \ - \n \ - \n\n\n\n \ - \"\"\n \ - Tricky href\n \ - Remote URL\n \ - \n\n\n\n\ - \n\ - ", + r##" + + Local HTML file + + + + + + + Tricky href + Remote URL + + + + + +"##, empty_image = EMPTY_IMAGE_DATA_URL ) ); @@ -184,10 +198,9 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stderr), format!( - "\ - {file_url_html}\n\ - {file_url_svg}\n\ - ", + r#"{file_url_html} +{file_url_svg} +"#, file_url_html = Url::from_file_path(fs::canonicalize(path_html).unwrap()).unwrap(), file_url_svg = Url::from_file_path(fs::canonicalize(path_svg).unwrap()).unwrap(), ) @@ -196,7 +209,9 @@ mod passing { // STDOUT should contain HTML with date URL for background-image in it assert_eq!( String::from_utf8_lossy(&out.stdout), - "
\n\n" + r##"
+ +"## ); // Exit code should be 0 @@ -215,10 +230,9 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stderr), format!( - "\ - {file_url_html}\n\ - {file_url_svg}\n\ - ", + r#"{file_url_html} +{file_url_svg} +"#, file_url_html = Url::from_file_path(fs::canonicalize(path_html).unwrap()).unwrap(), file_url_svg = Url::from_file_path(fs::canonicalize(path_svg).unwrap()).unwrap(), ) @@ -227,7 +241,19 @@ mod passing { // STDOUT should contain HTML with one symbol extracted from SVG file assert_eq!( String::from_utf8_lossy(&out.stdout), - "\n\n\n\n\n" + r##" + + + + +"## ); // Exit code should be 0 @@ -246,10 +272,9 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stderr), format!( - "\ - {file_url_html}\n\ - {file_url_svg}\n\ - ", + r#"{file_url_html} +{file_url_svg} +"#, file_url_html = Url::from_file_path(fs::canonicalize(path_html).unwrap()).unwrap(), file_url_svg = Url::from_file_path(fs::canonicalize(path_svg).unwrap()).unwrap(), ) @@ -258,7 +283,14 @@ mod passing { // STDOUT should contain HTML with data URL of SVG file assert_eq!( String::from_utf8_lossy(&out.stdout), - "\n \n \n \n \n\n\n" + r##" + + + + + + +"## ); // Exit code should be 0 @@ -297,13 +329,12 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stderr), format!( - "\ - {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\ - ", + r#"{file}{cwd}/tests/_data_/integrity/index.html +{file}{cwd}/tests/_data_/integrity/style.css +{file}{cwd}/tests/_data_/integrity/style.css +{file}{cwd}/tests/_data_/integrity/script.js +{file}{cwd}/tests/_data_/integrity/script.js +"#, file = file_url_protocol, cwd = cwd_normalized, ) @@ -313,17 +344,24 @@ mod passing { assert_eq!( String::from_utf8_lossy(&out.stdout), format!( - "\ - \ - \n \ - Local HTML file\n \ - \n \ - \n\n\n\n \ -

This page should have black background and white foreground, but only when served via http: (not via file:)

\n \ - \n \ - \n\n\n\n\ - \n\ - " + r##" + Local HTML file + + + + + +

This page should have black background and white foreground, but only when served via http: (not via file:)

+ + + + + + +"## ) ); diff --git a/tests/cli/noscript.rs b/tests/cli/noscript.rs index 902895cb..1e3a6c08 100644 --- a/tests/cli/noscript.rs +++ b/tests/cli/noscript.rs @@ -131,14 +131,9 @@ mod passing { // STDOUT should contain HTML with no CSS assert_eq!( String::from_utf8_lossy(&out.stdout), - "\ - \ - \ - \ - \ - \n\ - \ - \n" + r#" + +"# ); // Exit code should be 0 diff --git a/tests/cookies/parse_cookie_file_contents.rs b/tests/cookies/parse_cookie_file_contents.rs index e7067d37..58217f7c 100644 --- a/tests/cookies/parse_cookie_file_contents.rs +++ b/tests/cookies/parse_cookie_file_contents.rs @@ -11,8 +11,8 @@ mod passing { #[test] fn parse_file() { - let file_contents = - "# Netscape HTTP Cookie File\n127.0.0.1\tFALSE\t/\tFALSE\t0\tUSER_TOKEN\tin"; + let file_contents = r#"# Netscape HTTP Cookie File +127.0.0.1 FALSE / FALSE 0 USER_TOKEN in"#; let result = cookies::parse_cookie_file_contents(file_contents).unwrap(); assert_eq!(result.len(), 1); assert_eq!(result[0].domain, "127.0.0.1"); @@ -26,7 +26,11 @@ mod passing { #[test] fn parse_multiline_file() { - let file_contents = "# HTTP Cookie File\n127.0.0.1\tFALSE\t/\tFALSE\t0\tUSER_TOKEN\tin\n127.0.0.1\tTRUE\t/\tTRUE\t9\tUSER_TOKEN\tout\n\n"; + let file_contents = r#"# HTTP Cookie File +127.0.0.1 FALSE / FALSE 0 USER_TOKEN in +127.0.0.1 TRUE / TRUE 9 USER_TOKEN out + +"#; let result = cookies::parse_cookie_file_contents(file_contents).unwrap(); assert_eq!(result.len(), 2); assert_eq!(result[0].domain, "127.0.0.1"); @@ -66,7 +70,7 @@ mod failing { #[test] fn no_header() { - let file_contents = "127.0.0.1 FALSE / FALSE 0 USER_TOKEN in"; + let file_contents = "127.0.0.1 FALSE / FALSE 0 USER_TOKEN in"; match cookies::parse_cookie_file_contents(file_contents) { Ok(_result) => { assert!(false); diff --git a/tests/core/retrieve_asset.rs b/tests/core/retrieve_asset.rs index 4381bdbd..c962a2ac 100644 --- a/tests/core/retrieve_asset.rs +++ b/tests/core/retrieve_asset.rs @@ -77,7 +77,11 @@ mod passing { .unwrap(); assert_eq!(&media_type, "text/javascript"); assert_eq!(&charset, ""); - assert_eq!(url::create_data_url(&media_type, &charset, &data, &final_url), Url::parse("data:text/javascript;base64,ZG9jdW1lbnQuYm9keS5zdHlsZS5iYWNrZ3JvdW5kQ29sb3IgPSAiZ3JlZW4iOwpkb2N1bWVudC5ib2R5LnN0eWxlLmNvbG9yID0gInJlZCI7Cg==").unwrap()); + let data_url = "data:text/javascript;base64,ZG9jdW1lbnQuYm9keS5zdHlsZS5iYWNrZ3JvdW5kQ29sb3IgPSAiZ3JlZW4iOwpkb2N1bWVudC5ib2R5LnN0eWxlLmNvbG9yID0gInJlZCI7Cg=="; + assert_eq!( + url::create_data_url(&media_type, &charset, &data, &final_url), + Url::parse(data_url).unwrap() + ); assert_eq!( final_url, Url::parse(&format!( diff --git a/tests/html/has_favicon.rs b/tests/html/has_favicon.rs index 96f3d602..6601123f 100644 --- a/tests/html/has_favicon.rs +++ b/tests/html/has_favicon.rs @@ -11,7 +11,7 @@ mod passing { #[test] fn icon() { - let html = "
text
"; + let html = r#"
text
"#; let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string()); let res: bool = html::has_favicon(&dom.document); @@ -20,7 +20,7 @@ mod passing { #[test] fn shortcut_icon() { - let html = "
text
"; + let html = r#"
text
"#; let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string()); let res: bool = html::has_favicon(&dom.document);