From: Ruben Beltran del Rio Date: Sat, 4 Jan 2025 01:25:11 +0000 (+0100) Subject: Use String::new() for empty strings X-Git-Tag: 1.4.0~4 X-Git-Url: https://git.r.bdr.sh/rbdr/page/commitdiff_plain/137b2e55c21459261d4fa0f909ccfc60f98117e5 Use String::new() for empty strings --- diff --git a/src/file_finder.rs b/src/file_finder.rs index 0512146..a834bd9 100644 --- a/src/file_finder.rs +++ b/src/file_finder.rs @@ -89,9 +89,9 @@ mod tests { Some("gmi") => assert_eq!(file.file_type, FileType::Gemini), Some("html") => { if file.path.ends_with("_layout.html") { - assert_eq!(file.file_type, FileType::Layout) + assert_eq!(file.file_type, FileType::Layout); } else { - assert_eq!(file.file_type, FileType::File) + assert_eq!(file.file_type, FileType::File); } } _ => assert_eq!(file.file_type, FileType::File), diff --git a/src/gemini_parser.rs b/src/gemini_parser.rs index 49d954a..f7aa0cc 100644 --- a/src/gemini_parser.rs +++ b/src/gemini_parser.rs @@ -82,7 +82,7 @@ mod tests { parse_line("# Heading"), GeminiLine::Heading(1, " Heading".to_string()) ); - assert_eq!(parse_line("###"), GeminiLine::Heading(3, "".to_string())); + assert_eq!(parse_line("###"), GeminiLine::Heading(3, String::new())); assert_eq!( parse_line("#####"), GeminiLine::Heading(3, "##".to_string()) @@ -111,16 +111,16 @@ mod tests { ); assert_eq!( parse_line("=> /local/path"), - GeminiLine::Link("/local/path".to_string(), "".to_string()) + GeminiLine::Link("/local/path".to_string(), String::new()) ); assert_eq!( parse_line("=>"), - GeminiLine::Link("".to_string(), "".to_string()) + GeminiLine::Link(String::new(), String::new()) ); assert_eq!( parse_line("=> "), - GeminiLine::Link("".to_string(), "".to_string()) + GeminiLine::Link(String::new(), String::new()) ); assert_eq!( parse_line("=> multiple spaces in text"), @@ -140,7 +140,7 @@ mod tests { GeminiLine::ListItem("List item".to_string()) ); - assert_eq!(parse_line("* "), GeminiLine::ListItem("".to_string())); + assert_eq!(parse_line("* "), GeminiLine::ListItem(String::new())); assert_eq!(parse_line("*"), GeminiLine::Text("*".to_string(), false)); assert_eq!( parse_line("*WithText"), @@ -159,7 +159,7 @@ mod tests { GeminiLine::Quote("Quote text".to_string()) ); - assert_eq!(parse_line(">"), GeminiLine::Quote("".to_string())); + assert_eq!(parse_line(">"), GeminiLine::Quote(String::new())); assert_eq!(parse_line("> "), GeminiLine::Quote(" ".to_string())); assert_eq!( parse_line(">>Nested"), @@ -176,7 +176,7 @@ mod tests { assert_eq!( parse_line("```"), - GeminiLine::PreformattedToggle(true, "".to_string()) + GeminiLine::PreformattedToggle(true, String::new()) ); assert_eq!( parse_line("``` "), @@ -189,11 +189,11 @@ mod tests { assert_eq!( parse_preformatted_line("```alt-text"), - GeminiLine::PreformattedToggle(false, "".to_string()) + GeminiLine::PreformattedToggle(false, String::new()) ); assert_eq!( parse_preformatted_line("```"), - GeminiLine::PreformattedToggle(false, "".to_string()) + GeminiLine::PreformattedToggle(false, String::new()) ); } @@ -206,7 +206,7 @@ mod tests { ); // Edge cases - assert_eq!(parse_line(""), GeminiLine::Text("".to_string(), false)); + assert_eq!(parse_line(""), GeminiLine::Text(String::new(), false)); assert_eq!(parse_line(" "), GeminiLine::Text(" ".to_string(), false)); assert_eq!(parse_line(" "), GeminiLine::Text(" ".to_string(), false)); } @@ -265,7 +265,7 @@ code GeminiLine::Text("=> https://example.com Link text".to_string(), true), GeminiLine::Text("* List item".to_string(), true), GeminiLine::Text(">Quote".to_string(), true), - GeminiLine::PreformattedToggle(false, "".to_string()), + GeminiLine::PreformattedToggle(false, String::new()), ] ); } diff --git a/src/html_renderer.rs b/src/html_renderer.rs index 7724131..6b9ce38 100644 --- a/src/html_renderer.rs +++ b/src/html_renderer.rs @@ -206,7 +206,7 @@ mod tests { fn test_links() { let input = vec![ GeminiLine::Link("https://example.com".to_string(), "Example".to_string()), - GeminiLine::Link("https://rust-lang.org".to_string(), "".to_string()), + GeminiLine::Link("https://rust-lang.org".to_string(), String::new()), ]; assert_eq!( render_html(&input),