// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗ // ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝ // ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗ // ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║ // ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝ // ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ #[cfg(test)] mod passing { use assert_cmd::prelude::*; use std::env; use std::fs; use std::path::Path; use std::process::Command; use url::Url; #[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 out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap(); // STDERR should contain target HTML and embedded SVG files assert_eq!( String::from_utf8_lossy(&out.stderr), format!( "\ {file_url_html}\n \ {file_url_svg}\n\ ", 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(), ) ); // STDOUT should contain HTML with no CSS assert_eq!( String::from_utf8_lossy(&out.stdout), "\n\n" ); // Exit code should be 0 out.assert().code(0); } #[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 out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap(); // STDERR should contain target HTML and embedded SVG files assert_eq!( String::from_utf8_lossy(&out.stderr), format!( "\ {file_url_html}\n \ {file_url_svg}\n\ ", 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(), ) ); // STDOUT should contain HTML with no CSS assert_eq!( String::from_utf8_lossy(&out.stdout), "\n\n" ); // Exit code should be 0 out.assert().code(0); } #[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 out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap(); // STDERR should contain target HTML and embedded SVG files assert_eq!( String::from_utf8_lossy(&out.stderr), format!( "\ {file_url_html}\n \ {file_url_svg}\n\ ", 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(), ) ); // STDOUT should contain HTML with no CSS assert_eq!( String::from_utf8_lossy(&out.stdout), "

JS is not active

\n\n" ); // Exit code should be 0 out.assert().code(0); } #[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 out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap(); // STDERR should contain target HTML and embedded SVG files assert_eq!( String::from_utf8_lossy(&out.stderr), format!( "\ {file_url_html}\n \ {file_url_svg}\n\ ", 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(), ) ); // STDOUT should contain HTML with no CSS assert_eq!( String::from_utf8_lossy(&out.stdout), "\ \ \ \ \ \n\ \ \n" ); // Exit code should be 0 out.assert().code(0); } #[test] fn unwrap_noscript_contents_attr_data_url() { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); let out = cmd .arg("-M") .arg("-n") .arg("data:text/html,") .output() .unwrap(); // STDERR should be empty assert_eq!(String::from_utf8_lossy(&out.stderr), ""); // STDOUT should contain unwrapped contents of NOSCRIPT element assert_eq!( String::from_utf8_lossy(&out.stdout), "test\n" ); // Exit code should be 0 out.assert().code(0); } }