From b5d3151720b3a7a1a89f348951cfcd92b30d40eb Mon Sep 17 00:00:00 2001 From: Alessandro Menezes Date: Fri, 7 Oct 2022 08:13:29 -0400 Subject: [PATCH 1/2] Adding test coverage to src/info/info_field.rs As requested as an item on task #700 --- src/info/info_field.rs | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/info/info_field.rs b/src/info/info_field.rs index 54e4d3482..e933fa598 100644 --- a/src/info/info_field.rs +++ b/src/info/info_field.rs @@ -30,3 +30,50 @@ pub enum InfoType { Size, License, } + +#[cfg(test)] +mod test { + use super::*; + + struct InfoFieldImpl { + pub val: String, + } + impl InfoField for InfoFieldImpl { + const TYPE: InfoType = InfoType::Project; + + fn value(&self) -> String { + self.val.clone() + } + + fn title(&self) -> String { + String::from("title") + } + } + + #[test] + fn test_info_field_get() { + let info = InfoFieldImpl { + val: String::from("test"), + }; + + assert_eq!(info.get(&[]), Some(String::from("test"))); + } + + #[test] + fn test_info_field_get_none_when_type_disabled() { + let info = InfoFieldImpl { + val: String::from("test"), + }; + + assert_eq!(info.get(&[InfoType::Project]), None); + } + + #[test] + fn test_info_field_get_none_when_value_is_empty() { + let info = InfoFieldImpl { + val: String::from(""), + }; + + assert_eq!(info.get(&[]), None); + } +} From db7ac25a23b0fee124759543ea9a64cd19bbb4d6 Mon Sep 17 00:00:00 2001 From: Alessandro Menezes Date: Fri, 7 Oct 2022 10:16:06 -0400 Subject: [PATCH 2/2] Implementing the suggested changes by reviewer --- src/info/info_field.rs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/info/info_field.rs b/src/info/info_field.rs index e933fa598..5d3b47c86 100644 --- a/src/info/info_field.rs +++ b/src/info/info_field.rs @@ -35,14 +35,13 @@ pub enum InfoType { mod test { use super::*; - struct InfoFieldImpl { - pub val: String, - } + struct InfoFieldImpl(&'static str); + impl InfoField for InfoFieldImpl { const TYPE: InfoType = InfoType::Project; fn value(&self) -> String { - self.val.clone() + self.0.into() } fn title(&self) -> String { @@ -52,28 +51,19 @@ mod test { #[test] fn test_info_field_get() { - let info = InfoFieldImpl { - val: String::from("test"), - }; - + let info = InfoFieldImpl("test"); assert_eq!(info.get(&[]), Some(String::from("test"))); } #[test] fn test_info_field_get_none_when_type_disabled() { - let info = InfoFieldImpl { - val: String::from("test"), - }; - + let info = InfoFieldImpl("test"); assert_eq!(info.get(&[InfoType::Project]), None); } #[test] fn test_info_field_get_none_when_value_is_empty() { - let info = InfoFieldImpl { - val: String::from(""), - }; - + let info = InfoFieldImpl(""); assert_eq!(info.get(&[]), None); } }