From 85d299b85236c54e7e6db02c6fea79e3f4aaa585 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Thu, 5 Jan 2023 11:01:05 -0500 Subject: [PATCH] Added pull record information. --- src/morethantext/cachetype.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/morethantext/cachetype.rs b/src/morethantext/cachetype.rs index f84d81c..7240216 100644 --- a/src/morethantext/cachetype.rs +++ b/src/morethantext/cachetype.rs @@ -9,7 +9,7 @@ pub enum CacheType { #[derive(Clone)] pub struct Record { - data: HashMap + data: HashMap, } impl Record { @@ -25,7 +25,14 @@ impl Record { None => { self.data.insert(col.to_string(), data.to_string()); Ok(()) - }, + } + } + } + + fn get_field(&self, col: &str) -> Result { + match self.data.get(col) { + Some(item) => Ok(item.to_string()), + None => Err(DBError::new("missing field")), } } } @@ -119,8 +126,11 @@ mod record { #[test] fn store() { + let data = "data"; let mut rec = Record::new(); - rec.add_field("column", "data").unwrap(); + rec.add_field("column", data).unwrap(); + let output = rec.get_field("column").unwrap(); + assert_eq!(output, data); } #[test] @@ -131,7 +141,16 @@ mod record { Ok(_) => assert!(false, "Should have raised an error."), Err(err) => { assert_eq!(err.to_string(), "duplicate field"); - }, + } + } + } + + #[test] + fn missing_field() { + let rec = Record::new(); + match rec.get_field("nothing") { + Ok(_) => assert!(false, "Should have errored."), + Err(err) => assert_eq!(err.to_string(), "missing field"), } } }