From 1b525560d6d159c162eaa41d9672f61f6496b56d Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 22 Aug 2021 16:17:51 +0200 Subject: [PATCH] test word_utils --- src/word_utils.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/word_utils.rs b/src/word_utils.rs index d087820..4da2eb0 100644 --- a/src/word_utils.rs +++ b/src/word_utils.rs @@ -17,3 +17,27 @@ pub fn second_word(s: &str) -> Option<&str> { return None; } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_first_word() { + assert_eq!(first_word(""), ""); + assert_eq!(first_word("one"), "one"); + assert_eq!(first_word("one two"), "one"); + + assert_eq!(first_word(&String::from("one two")), "one"); + } + + #[test] + fn test_second_word() { + assert_eq!(second_word(""), None); + assert_eq!(second_word("one"), None); + assert_eq!(second_word("one two"), Some("two")); + assert_eq!(second_word("one two three"), Some("two")); + + assert_eq!(second_word(&String::from("one two three")), Some("two")); + } +} -- 2.39.2