#[cfg(test)] fn _eval(src: &'static [u8], expected: &'static [u8], cfg: &super::Cfg) -> () { let mut code = src.to_vec(); match super::with_friendly_error(&mut code, cfg) { Ok(len) => { assert_eq!(std::str::from_utf8(&code[..len]).unwrap(), std::str::from_utf8(expected).unwrap()); } Err(super::FriendlyError { code_context, message, .. }) => { println!("{}", message); println!("{}", code_context); assert!(false); } }; } #[cfg(test)] fn eval(src: &'static [u8], expected: &'static [u8]) -> () { _eval(src, expected, &super::Cfg { minify_js: false, }); } #[cfg(test)] #[cfg(feature = "js-esbuild")] fn eval_with_js_min(src: &'static [u8], expected: &'static [u8]) -> () { _eval(src, expected, &super::Cfg { minify_js: true, }); } #[test] fn test_collapse_whitespace() { eval(b" \n ", b" "); } #[test] fn test_collapse_and_trim_whitespace() { eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_collapse_destroy_whole_and_trim_whitespace() { eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_no_whitespace_minification() { eval(b"
   \n  \t   
", b"
   \n  \t   
"); } #[test] fn test_self_closing_svg_tag_whitespace_removal() { eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_removal_of_optional_tags() { eval(b"", b""); eval(b"", b""); eval(b"1
", b"1
"); eval(b"
", b"
"); eval(br#" "#, b""); } #[test] fn test_removal_of_optional_closing_p_tag() { eval(b"

", b"

"); eval(b"

", b"

"); eval(b"

", b"

"); eval(b"

", b"

"); } #[test] fn test_attr_double_quoted_value_minification() { eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_attr_single_quoted_value_minification() { eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_attr_unquoted_value_minification() { eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_class_attr_value_minification() { eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_d_attr_value_minification() { eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_boolean_attr_value_removal() { eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_empty_attr_removal() { eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); } #[test] fn test_default_attr_value_removal() { eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_script_type_attr_value_removal() { eval(b"", b""); eval(b"", b""); eval(b"", b""); } #[test] fn test_empty_attr_value_removal() { eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); } #[test] fn test_space_between_attrs_minification() { eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); eval(b"
", b"
"); } #[test] fn test_attr_value_backtick() { // The backtick is not interpreted as a quote; as such, the "b" attribute is interpreted as having an empty value, // and the "`hello`" attribute is a boolean attribute (also empty value). eval(b"", b""); } #[test] fn test_hexadecimal_entity_decoding() { eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"ᅑ", b"\xe1\x85\x91"); eval(b"�", b"\xef\xbf\xbd"); eval(b"�", b"\xef\xbf\xbd"); } #[test] fn test_decimal_entity_decoding() { eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"0", b"0"); eval(b"ᅑ", b"\xe1\x85\x91"); eval(b"�", b"\xef\xbf\xbd"); eval(b"�", b"\xef\xbf\xbd"); } #[test] fn test_named_entity_decoding() { eval(b">", b">"); eval(b">", b">"); eval(b"&", b"&"); eval(b"&", b"&"); eval(b"&xxxyyyzzz", b"&xxxyyyzzz"); eval(b"&ere", b"&ere"); eval(b"They & Co.", b"They & Co."); eval(b"if (this && that)", b"if (this && that)"); // These entities decode to longer UTF-8 sequences, so we keep them encoded. eval(b"≪⃒", b"≪⃒"); eval(b"≪⃒abc", b"≪⃒abc"); eval(b"≫⃒", b"≫⃒"); } #[test] fn test_unintentional_entity_prevention() { eval(b"&amp", b"&amp"); eval(b"&amp;", b"&amp;"); eval(b"&amp", b"&amp"); eval(b"&amp;", b"&amp;"); eval(b"&amp;", b"&amp;"); eval(b"&amp;", b"&amp;"); eval(b"&amp", b"&amp"); eval(b"&amp", b"&amp"); eval(b"&amp;", b"&amp;"); eval(b"&amp;", b"&amp;"); eval(b"&amp;", b"&amp;"); eval(b"&amp;", b"&amp;"); eval(b"&lt", b"&lt"); eval(b"&lt", b"&lt"); eval(b"&lt;", b"&lt;"); eval(b"&lt;", b"&lt;"); eval(b"&lt", b"&lt"); eval(b"&lt;", b"&lt;"); eval(b"&am&amp", b"&am&amp"); eval(b"&am&amp;", b"&am&amp;"); eval(b"&≪⃒", b"&≪⃒"); eval(b"&am≪⃒", b"&am≪⃒"); eval(b"&am≪⃒a", b"&am≪⃒a"); eval(b"&am&nLt", b"&am&nLt"); } #[test] fn test_left_chevron_entities_in_content() { eval(b"<", b"<"); eval(b"<", b"<"); eval(b"<;", b"<;"); eval(b"<;", b"<;"); eval(b"<;", b"<;"); eval(b"<", b"<"); eval(b"<", b"<"); eval(b"<;", b"<;"); eval(b"<;", b"<;"); eval(b"<;", b"<;"); } #[test] fn test_comments_removal() { eval(b"
a   b
", b"
a   b
"); eval(b"&amp", b"&"); eval(b"", b""); } #[test] fn test_processing_instructions() { eval(b"> ?>", b"> ?>"); eval(b"avg", b"avg"); } #[cfg(feature = "js-esbuild")] #[test] fn test_js_minification() { eval_with_js_min(b"", b""); eval_with_js_min(br#" "#, b""); }