From 1367c5072c78d7b89a2d3a8771ac5206d6333566 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Wed, 1 Feb 2023 21:08:18 +0100 Subject: [PATCH] refactoring: refactored tests and removed redundant condition in splitcommand --- src/builtins/help.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/builtins/help.rs b/src/builtins/help.rs index afd6321..86e3fdd 100644 --- a/src/builtins/help.rs +++ b/src/builtins/help.rs @@ -27,7 +27,7 @@ impl Builtin for Help { } fn split_command(commands: &str) -> Vec<&str> { - if !commands.is_empty() && commands.trim().len() >= 1 { + if commands.trim_start().len() >= 1 { let splitted_command = commands.trim_start().splitn(2, " ").collect(); return splitted_command; } @@ -38,24 +38,25 @@ fn split_command(commands: &str) -> Vec<&str> { mod tests { use super::*; - #[test] - fn test_split_command_split(){ + fn test_split_command_split() { let test_string1 = "Hallo, Marcel Davis 1&1."; - assert_eq!(split_command(test_string1),vec!["Hallo,","Marcel Davis 1&1."]); + assert_eq!(split_command(test_string1), vec!["Hallo,", "Marcel Davis 1&1."]); let test_string2 = "Leiter1 23für Kundenzufriedenheit."; assert_eq!(split_command(test_string2), vec!["Leiter1", "23für Kundenzufriedenheit."]); let test_string3 = "Wir# $%gehen erst wieder, wenn ihre Leitung läuft!"; - assert_eq!(split_command(test_string3),vec!["Wir#", "$%gehen erst wieder, wenn ihre Leitung läuft!"]); + assert_eq!(split_command(test_string3), vec!["Wir#", "$%gehen erst wieder, wenn ihre Leitung läuft!"]); } #[test] - fn test_split_command_empty(){assert_eq!(split_command(""),vec!["",""])} + fn test_split_command_empty() { + assert_eq!(split_command(""), vec!["", ""]); + } #[test] - fn test_split_command_only_space(){ - assert_eq!(split_command(" "),vec!["",""]); + fn test_split_command_only_space() { + assert_eq!(split_command(" "), vec!["", ""]); } } \ No newline at end of file