fn eval_with_cfg(src: &'static [u8], expected: &'static [u8], cfg: &super::Cfg) { let mut code = src.to_vec(); let min = super::minify(&mut code, cfg); assert_eq!( std::str::from_utf8(&min).unwrap(), std::str::from_utf8(expected).unwrap(), ); } fn eval(src: &'static [u8], expected: &'static [u8]) { eval_with_cfg(src, expected, &super::Cfg::new()); } fn eval_with_keep_html_head(src: &'static [u8], expected: &'static [u8]) -> () { let mut cfg = super::Cfg::new(); cfg.keep_html_and_head_opening_tags = true; eval_with_cfg(src, expected, &cfg); } #[cfg(feature = "js-esbuild")] fn eval_with_js_min(src: &'static [u8], expected: &'static [u8]) -> () { let mut cfg = super::Cfg::new(); cfg.minify_js = true; eval_with_cfg(src, expected, &cfg); } #[cfg(feature = "js-esbuild")] fn eval_with_css_min(src: &'static [u8], expected: &'static [u8]) -> () { let mut cfg = super::Cfg::new(); cfg.minify_css = true; eval_with_cfg(src, expected, &cfg); } #[test] fn test_collapse_whitespace() { eval(b" \n ", b" "); // Tag names should be case insensitive. eval(b" \n ", b" "); eval(b" \n ", b" "); } #[test] fn test_collapse_and_trim_whitespace() { eval(b" \n ", b""); eval(b" \n a ", b"a"); eval(b" \n a b ", b"a b"); // Tag names should be case insensitive. eval(b" \n a b ", b"a b"); } #[test] fn test_collapse_destroy_whole_and_trim_whitespace() { eval(b"
\n \t
1 2
1 \n 2
\n
fn main() { println!("Hello, world!"); loop { println!("Hello, world!"); } }
Foo
Goodbye"); eval_with_keep_html_head(b"HelloGoodbye", b"HelloGoodbye"); eval_with_keep_html_head(b"
Goodbye"); eval_with_keep_html_head(b"
"); eval_with_keep_html_head(b"
"); eval_with_keep_html_head( b"
", ); } #[test] fn test_removal_of_html_and_head_opening_tags() { // Even though `
"); eval(b"", b""); eval( b"", b"", ); } #[test] fn test_attr_double_quoted_value_minification() { eval(b"", b""); eval(b"", b""); eval(br#""#, br#""#); eval(br#""#, br#""#); eval(b"", b""); eval(b"", b""); } #[test] fn test_attr_single_quoted_value_minification() { eval(b"", b""); eval(b"", b""); eval(b"", b"a\">"); eval( b"", b"", ); } #[test] fn test_attr_unquoted_value_minification() { eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", b""); eval(b"", br#""#); eval(b"", br#""#); eval(b"", b""); } #[test] fn test_attr_whatwg_unquoted_value_minification() { let mut cfg = super::Cfg::new(); cfg.ensure_spec_compliant_unquoted_attribute_values = true; eval_with_cfg(b"", br#""#, &cfg); eval_with_cfg( br#""#, br#""#, &cfg, ); } #[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""); // Attribute names should be case insensitive. 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""); // Attribute names should be case insensitive. eval(b"", b""); } #[test] fn test_boolean_attr_value_removal() { eval(b"
<
<a
<a
<a
<a
<?
<?
<?
<?
</
</
<!
<!
a b