Added a table field.
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:
@@ -1,11 +1,40 @@
|
||||
pub mod id;
|
||||
pub mod record;
|
||||
mod id;
|
||||
mod record;
|
||||
|
||||
struct Table;
|
||||
use crate::data::record::Record;
|
||||
use std::collections::HashMap;
|
||||
|
||||
struct FieldDef;
|
||||
|
||||
impl FieldDef {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
struct Table {
|
||||
fields: HashMap<String, FieldDef>,
|
||||
}
|
||||
|
||||
impl Table {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
Self {
|
||||
fields: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.fields.len()
|
||||
}
|
||||
|
||||
fn add_field(&mut self, name: &str, field_type: &str) -> Result<(), String> {
|
||||
match self.fields.get(name) {
|
||||
Some(_) => Err("duplicate field name".to_string()),
|
||||
None => {
|
||||
self.fields.insert(name.to_string(), FieldDef::new());
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +45,23 @@ mod table {
|
||||
#[test]
|
||||
fn new_table() {
|
||||
let tbl = Table::new();
|
||||
assert_eq!(tbl.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_field() {
|
||||
let mut tbl = Table::new();
|
||||
tbl.add_field("one", "id");
|
||||
assert_eq!(tbl.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_on_duplicate_name() {
|
||||
let mut tbl = Table::new();
|
||||
tbl.add_field("one", "id");
|
||||
match tbl.add_field("one", "id") {
|
||||
Ok(_) => unreachable!(" Should not duplicates."),
|
||||
Err(_) => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user