Adding test coverage to src/info/info_field.rs
* Adding test coverage to src/info/info_field.rs
As requested as an item on task
* Implementing the suggested changes by reviewer
@@ -30,3 +30,40 @@ pub enum InfoType {
Size,
License,
}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ struct InfoFieldImpl(&'static str);
+
+ impl InfoField for InfoFieldImpl {
+ const TYPE: InfoType = InfoType::Project;
+
+ fn value(&self) -> String {
+ self.0.into()
+ }
+
+ fn title(&self) -> String {
+ String::from("title")
+ }
+ }
+
+ #[test]
+ fn test_info_field_get() {
+ 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("test");
+ assert_eq!(info.get(&[InfoType::Project]), None);
+ }
+
+ #[test]
+ fn test_info_field_get_none_when_value_is_empty() {
+ let info = InfoFieldImpl("");
+ assert_eq!(info.get(&[]), None);
+ }
+}
