From e9f7188c1ceb7fe9ae0247b9c04f6d4ff4626f82 Mon Sep 17 00:00:00 2001 From: Daniel Tomlinson Date: Mon, 16 Nov 2020 23:04:36 +0000 Subject: [PATCH] Adding empty string case + test --- src/hands.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/hands.rs b/src/hands.rs index 333ec1c..f03a88d 100644 --- a/src/hands.rs +++ b/src/hands.rs @@ -1,8 +1,10 @@ pub fn handify(input: &str) -> String { let input = input.to_uppercase(); let input = input.trim().to_owned(); - let input = input.replace(" ", " 👏 "); - let input = format!("👏 {} 👏", input); + let mut input = input.replace(" ", " 👏 "); + if !input.is_empty() { + input = format!("👏 {} 👏", input); + } input } @@ -17,3 +19,9 @@ fn handify_test_with_trailing_spaces() { let input = " hello world "; assert_eq!(handify(input), "👏 HELLO 👏 WORLD 👏") } + +#[test] +fn handify_test_empty_string() { + let input = ""; + assert_eq!(handify(input), ""); +}