]> piware.de Git - learn-rust.git/commitdiff
test word_utils
authorMartin Pitt <martin@piware.de>
Sun, 22 Aug 2021 14:17:51 +0000 (16:17 +0200)
committerMartin Pitt <martin@piware.de>
Sun, 22 Aug 2021 14:17:51 +0000 (16:17 +0200)
src/word_utils.rs

index d087820a1ec0fcb2a517cef8599d5db550844fdc..4da2eb0f147aa37eb3f9338510ed595444181fe6 100644 (file)
@@ -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"));
+    }
+}