From 4cf136a004285262fe641446a35d3efe7806b4e8 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Wed, 1 Mar 2023 03:52:48 +0100 Subject: Split up wget tests --- src/renderer.rs | 58 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'src/renderer.rs') diff --git a/src/renderer.rs b/src/renderer.rs index 90b00fe..1257a67 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -702,52 +702,64 @@ pub fn render_error( mod tests { use super::*; use pretty_assertions::assert_eq; - #[test] - fn test_wget_footer() { - fn to_html(x: &str) -> String { - format!( - r#"

Download folder:

wget -rcnHp -R 'index.html*' {0}/?raw=true'
"#, - x - ) - } - fn uri(x: &str) -> Uri { - Uri::try_from(x).unwrap() - } + fn to_html(wget_part: &str) -> String { + format!( + r#"

Download folder:

wget -rcnHp -R 'index.html*' {wget_part}/?raw=true'
"# + ) + } + + fn uri(x: &str) -> Uri { + Uri::try_from(x).unwrap() + } + + #[test] + fn test_wget_footer_trivial() { + let to_be_tested: String = wget_footer(&uri("https://github.com/"), None, None).into(); + let expected = to_html("-P 'github.com' 'https://github.com"); + assert_eq!(to_be_tested, expected); + } + #[test] + fn test_wget_footer_with_root_dir() { let to_be_tested: String = wget_footer( &uri("https://github.com/svenstaro/miniserve/"), Some("Miniserve"), None, ) .into(); - let solution = to_html("--cut-dirs=1 'https://github.com/svenstaro/miniserve"); - assert_eq!(to_be_tested, solution); - - let to_be_tested: String = wget_footer(&uri("https://github.com/"), None, None).into(); - let solution = to_html("-P 'github.com' 'https://github.com"); - assert_eq!(to_be_tested, solution); + let expected = to_html("--cut-dirs=1 'https://github.com/svenstaro/miniserve"); + assert_eq!(to_be_tested, expected); + } + #[test] + fn test_wget_footer_with_root_dir_and_user() { let to_be_tested: String = wget_footer( &uri("http://1und1.de/"), Some("1&1 - Willkommen!!!"), Some("Marcell D'Avis"), ) .into(); - let solution = to_html("-P '1&1 - Willkommen!!!' --ask-password --user 'Marcell D'"'"'Avis' 'http://1und1.de"); - assert_eq!(to_be_tested, solution); + let expected = to_html("-P '1&1 - Willkommen!!!' --ask-password --user 'Marcell D'"'"'Avis' 'http://1und1.de"); + assert_eq!(to_be_tested, expected); + } + #[test] + fn test_wget_footer_escaping() { let to_be_tested: String = wget_footer( &uri("http://127.0.0.1:1234/geheime_dokumente.php/"), Some("Streng Geheim!!!"), Some("uøý`¶'7ÅÛé"), ) .into(); - let solution = to_html("--ask-password --user 'uøý`¶'"'"'7ÅÛé' 'http://127.0.0.1:1234/geheime_dokumente.php"); - assert_eq!(to_be_tested, solution); + let expected = to_html("--ask-password --user 'uøý`¶'"'"'7ÅÛé' 'http://127.0.0.1:1234/geheime_dokumente.php"); + assert_eq!(to_be_tested, expected); + } + #[test] + fn test_wget_footer_ip() { let to_be_tested: String = wget_footer(&uri("http://127.0.0.1:420/"), None, None).into(); - let solution = to_html("-P '127.0.0.1:420' 'http://127.0.0.1:420"); - assert_eq!(to_be_tested, solution); + let expected = to_html("-P '127.0.0.1:420' 'http://127.0.0.1:420"); + assert_eq!(to_be_tested, expected); } } -- cgit v1.2.3