Switched Universe to Global.
Some checks failed
MoreThanText/morethantext/pipeline/head There was a failure building this commit
Some checks failed
MoreThanText/morethantext/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -7,14 +7,14 @@ use crate::{data::database::Database, error::MTTError};
|
||||
use std::{collections::HashMap, fmt, ops::Deref};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum UniError {
|
||||
pub enum GblError {
|
||||
DuplicateDB(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for UniError {
|
||||
impl fmt::Display for GblError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
UniError::DuplicateDB(data) => write!(f, "database '{}' already exists", data),
|
||||
GblError::DuplicateDB(data) => write!(f, "database '{}' already exists", data),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ mod errors {
|
||||
#[test]
|
||||
fn duplicate_database() {
|
||||
let name = "name";
|
||||
let err = UniError::DuplicateDB(name.to_string());
|
||||
let err = GblError::DuplicateDB(name.to_string());
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
format!("database '{}' already exists", name)
|
||||
@@ -34,11 +34,11 @@ mod errors {
|
||||
}
|
||||
}
|
||||
|
||||
struct Universe {
|
||||
struct Global {
|
||||
databases: HashMap<String, Database>,
|
||||
}
|
||||
|
||||
impl Universe {
|
||||
impl Global {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
databases: HashMap::new(),
|
||||
@@ -48,7 +48,7 @@ impl Universe {
|
||||
fn add_database(&mut self, name: &str, db: Database) -> Result<(), MTTError> {
|
||||
match self.databases.get(name) {
|
||||
Some(_) => {
|
||||
let err = UniError::DuplicateDB(name.to_string());
|
||||
let err = GblError::DuplicateDB(name.to_string());
|
||||
Err(err.into())
|
||||
}
|
||||
None => {
|
||||
@@ -59,7 +59,7 @@ impl Universe {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Universe {
|
||||
impl Deref for Global {
|
||||
type Target = HashMap<String, Database>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@@ -68,31 +68,31 @@ impl Deref for Universe {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod universes {
|
||||
mod gblverses {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn create_universe() {
|
||||
let uni = Universe::new();
|
||||
assert_eq!(uni.len(), 0);
|
||||
fn create_gblverse() {
|
||||
let gbl = Global::new();
|
||||
assert_eq!(gbl.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_database() {
|
||||
let mut uni = Universe::new();
|
||||
let mut gbl = Global::new();
|
||||
let db = Database::new();
|
||||
uni.add_database("barney", db).unwrap();
|
||||
assert_eq!(uni.len(), 1);
|
||||
gbl.add_database("barney", db).unwrap();
|
||||
assert_eq!(gbl.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_duplicate_dbs() {
|
||||
let mut uni = Universe::new();
|
||||
let mut gbl = Global::new();
|
||||
let db1 = Database::new();
|
||||
let db2 = Database::new();
|
||||
let name = "duplicate";
|
||||
uni.add_database("barney", db2).unwrap();
|
||||
match uni.add_database("barney", db1) {
|
||||
gbl.add_database("barney", db2).unwrap();
|
||||
match gbl.add_database("barney", db1) {
|
||||
Ok(_) => unreachable!("should have been an error"),
|
||||
Err(err) => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user