Still setting up document additions.
This commit is contained in:
parent
20f798043f
commit
11455ee118
@ -920,6 +920,7 @@ enum FieldType {
|
|||||||
Uuid,
|
Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
enum Field {
|
enum Field {
|
||||||
StaticString(String),
|
StaticString(String),
|
||||||
Uuid(Uuid),
|
Uuid(Uuid),
|
||||||
@ -929,19 +930,47 @@ impl Field {
|
|||||||
fn get_type(&self) -> FieldType {
|
fn get_type(&self) -> FieldType {
|
||||||
match self {
|
match self {
|
||||||
Self::StaticString(_) => FieldType::StaticString,
|
Self::StaticString(_) => FieldType::StaticString,
|
||||||
|
Self::Uuid(_) => FieldType::Uuid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<String> for Field {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
Self::StaticString(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Uuid> for Field {
|
||||||
|
fn from(value: Uuid) -> Self {
|
||||||
|
Self::Uuid(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod fields {
|
mod fields {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_create_static_string() {
|
fn can_create_static_string() {
|
||||||
|
let data = Uuid::new_v4().to_string();
|
||||||
|
let result: Field = data.clone().into();
|
||||||
|
match result.clone() {
|
||||||
|
Field::StaticString(output) => assert_eq!(output, data),
|
||||||
|
_ => unreachable!("got {:?}: should have been static string", result),
|
||||||
|
}
|
||||||
|
assert_eq!(result.get_type(), FieldType::StaticString);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_uuid() {
|
||||||
let data = Uuid::new_v4();
|
let data = Uuid::new_v4();
|
||||||
let sstring = Field::StaticString(data.to_string());
|
let result: Field = data.clone().into();
|
||||||
assert_eq!(sstring.get_type(), FieldType::StaticString);
|
match result.clone() {
|
||||||
|
Field::Uuid(output) => assert_eq!(output, data),
|
||||||
|
_ => unreachable!("got {:?}: should have been uuid", result),
|
||||||
|
}
|
||||||
|
assert_eq!(result.get_type(), FieldType::Uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,11 +1007,53 @@ mod fieldsettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct Addition;
|
struct Addition {
|
||||||
|
data: HashMap<String, Field>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Addition {
|
impl Addition {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {}
|
Self {
|
||||||
|
data: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_field<F>(&mut self, name: String, field: F) where F: Into<Field> {
|
||||||
|
self.data.insert(name, field.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_field(&self, name: &str) -> Option<&Field> {
|
||||||
|
self.data.get(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod additions {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_add_static_string() {
|
||||||
|
let mut add = Addition::new();
|
||||||
|
let name = Uuid::new_v4().to_string();
|
||||||
|
let data = Uuid::new_v4().to_string();
|
||||||
|
add.add_field(name.clone(), data.clone());
|
||||||
|
let result = add.get_field(&name).unwrap();
|
||||||
|
match result {
|
||||||
|
Field::StaticString(result) => assert_eq!(result, &data),
|
||||||
|
_ => unreachable!("got {:?}: should have received static string", result),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn can_add_uuid() {
|
||||||
|
let mut add = Addition::new();
|
||||||
|
let name = Uuid::new_v4().to_string();
|
||||||
|
let data = Uuid::new_v4();
|
||||||
|
add.add_field(name.clone(), data.clone());
|
||||||
|
let result = add.get_field(&name).unwrap();
|
||||||
|
match result {
|
||||||
|
Field::Uuid(result) => assert_eq!(result, &data),
|
||||||
|
_ => unreachable!("got {:?}: should have received uuid", result),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user