From 766d2e753ada01dc90e8a7d4201ef0b914245912 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Mon, 23 Jan 2023 11:05:55 -0500 Subject: [PATCH] Removed databases with empty names. --- src/morethantext/databases.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/morethantext/databases.rs b/src/morethantext/databases.rs index 7c93e56..1623689 100644 --- a/src/morethantext/databases.rs +++ b/src/morethantext/databases.rs @@ -14,7 +14,7 @@ impl Databases { } fn add_database(&mut self, name: &str, id: &str) -> Option { - if self.db_map.contains_key(name) { + if name.len() == 0 || self.db_map.contains_key(name) { None } else { self.db_map.insert(name.to_string(), id.to_string()); @@ -96,6 +96,15 @@ mod functions { assert_eq!(output, Some(id.to_string())); } + #[test] + fn add_entry_no_name() { + let name = ""; + let id = "123456"; + let mut dbs = Databases::new(); + let output = dbs.add_database(name, id); + assert_eq!(output, None); + } + #[test] fn entry_cannot_be_over_written() { let name = "barney";