Improve test for article FromHashMap

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 4 years ago
parent 2bfff98ce7
commit 8341b77fee
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -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<String, String>) -> Option<Box<Self>> {
if map.contains_key("type") {

@ -32,7 +32,7 @@ mod tests {
}
#[test]
fn it_converts_articles() {
fn it_creates_articles_from_hashmaps() {
let mut map: HashMap<String, String> = 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())
}
}

Loading…
Cancel
Save