From 46cf5ccd3b4f25a969aa4b8a87ecbbae651efe2b Mon Sep 17 00:00:00 2001 From: Sebastien Rousseau Date: Sun, 1 Dec 2024 21:54:42 +0000 Subject: [PATCH] =?UTF-8?q?test(html-generator):=20=E2=9C=85=20add=20unit?= =?UTF-8?q?=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/performance.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/performance.rs b/src/performance.rs index b427563..a8f8399 100644 --- a/src/performance.rs +++ b/src/performance.rs @@ -564,5 +564,73 @@ mod tests { ); } } + + #[test] + fn test_minify_html_empty_content() { + let html = ""; + let (dir, file_path) = create_test_file(html); + let result = minify_html(&file_path); + assert!(result.is_ok()); + assert!( + result.unwrap().is_empty(), + "Minified content should be empty" + ); + drop(dir); + } + + #[test] + fn test_minify_html_unusual_whitespace() { + let html = + "\n\n\t\t

Test

\n\n\n\n"; + let (dir, file_path) = create_test_file(html); + let result = minify_html(&file_path); + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + "

Test

", + "Unexpected minified result for unusual whitespace" + ); + drop(dir); + } + + #[test] + fn test_minify_html_with_special_characters() { + let html = "
<Special> & Characters
"; + let (dir, file_path) = create_test_file(html); + let result = minify_html(&file_path); + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + "
<Special> & Characters
", + "Special characters were unexpectedly modified during minification" + ); + drop(dir); + } + + #[tokio::test] + async fn test_async_generate_html_with_special_characters() { + let markdown = + "# Special & Characters\n\nContent with < > & \" '"; + let result = async_generate_html(markdown).await; + assert!(result.is_ok()); + let html = result.unwrap(); + assert!( + html.contains("<"), + "Less than sign not escaped" + ); + assert!( + html.contains(">"), + "Greater than sign not escaped" + ); + assert!(html.contains("&"), "Ampersand not escaped"); + assert!( + html.contains("""), + "Double quote not escaped" + ); + assert!( + html.contains("'") || html.contains("'"), + "Single quote not handled as expected" + ); + } } }