From 8341b77fee35e0695ac0c4aa11a68ab1965e4244 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 1 Sep 2020 22:09:27 +0200 Subject: [PATCH] Improve test for article FromHashMap Signed-off-by: trivernis --- src/bibliography/bib_types/mod.rs | 20 ++++++++++++++++++++ src/lib.rs | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/bibliography/bib_types/mod.rs b/src/bibliography/bib_types/mod.rs index 33fc986..e18ceac 100644 --- a/src/bibliography/bib_types/mod.rs +++ b/src/bibliography/bib_types/mod.rs @@ -43,6 +43,26 @@ pub enum BibliographyType { Repository(Repository), } +impl BibliographyType { + /// Returns the name of the enums value as a string + pub fn name(&self) -> String { + match self { + Self::Article(_) => "article".to_string(), + Self::Book(_) => "book".to_string(), + Self::Booklet(_) => "booklet".to_string(), + Self::InBook(_) => "in_book".to_string(), + Self::InCollection(_) => "in_collection".to_string(), + Self::Manual(_) => "manual".to_string(), + Self::Thesis(_) => "thesis".to_string(), + Self::TechReport(_) => "tech_report".to_string(), + Self::Unpublished(_) => "unpublished".to_string(), + Self::Misc(_) => "misc".to_string(), + Self::Website(_) => "website".to_string(), + Self::Repository(_) => "repository".to_string(), + } + } +} + impl FromHashMap for BibliographyType { fn from_hash_map(map: &HashMap) -> Option> { if map.contains_key("type") { diff --git a/src/lib.rs b/src/lib.rs index ec69652..dcf9dff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ mod tests { } #[test] - fn it_converts_articles() { + fn it_creates_articles_from_hashmaps() { let mut map: HashMap = HashMap::new(); map.insert("key".to_string(), "test_entry".to_string()); map.insert("type".to_string(), "article".to_string()); @@ -42,6 +42,7 @@ mod tests { map.insert("date".to_string(), "01.09.2020".to_string()); map.insert("note".to_string(), "This is a test".to_string()); - BibliographyEntry::from_hash_map(&map).unwrap(); + let entry = BibliographyEntry::from_hash_map(&map).unwrap(); + assert_eq!(entry.bib_type.name(), "article".to_string()) } }