Moved addition into action.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
This commit is contained in:
@@ -237,100 +237,6 @@ mod messages {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Addition {
|
||||
data: Document,
|
||||
}
|
||||
|
||||
impl Addition {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: Document::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn add_field<NT, CV>(&mut self, name: NT, field: CV)
|
||||
where
|
||||
CV: Into<CalcValue>,
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
self.data.add_field(name, field);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_field<NT>(&self, name: NT) -> &CalcValue
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
self.data.get_field(name)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_document(&self) -> Document {
|
||||
self.data.clone()
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&NameType, &CalcValue)> {
|
||||
self.data.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod additions {
|
||||
use super::*;
|
||||
use crate::name::Name;
|
||||
|
||||
#[test]
|
||||
fn can_add_static_string() {
|
||||
let mut add = Addition::new();
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let data = Uuid::new_v4().to_string();
|
||||
add.add_field(name.clone(), data.clone());
|
||||
let result = add.get_field(&name);
|
||||
match result {
|
||||
CalcValue::Value(result) => match result {
|
||||
Field::StaticString(output) => assert_eq!(output, &data),
|
||||
_ => unreachable!("got {:?}, should have been a string", result),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have received value", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_add_uuid() {
|
||||
let mut add = Addition::new();
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let data = Uuid::new_v4();
|
||||
add.add_field(name.clone(), data.clone());
|
||||
let output = add.get_field(&name);
|
||||
match output {
|
||||
CalcValue::Value(result) => match result {
|
||||
Field::Uuid(result) => assert_eq!(result, &data),
|
||||
_ => unreachable!("got {:?}: should have received uuid", result),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have received value", output),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_get_document() {
|
||||
let mut add = Addition::new();
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let data = Uuid::new_v4();
|
||||
add.add_field(name.clone(), data.clone());
|
||||
let doc = add.get_document();
|
||||
let output = doc.get_field(&name);
|
||||
match output {
|
||||
CalcValue::Value(holder) => match holder {
|
||||
Field::Uuid(result) => assert_eq!(result, &data),
|
||||
_ => unreachable!("should have received uuid"),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have received value", output),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Operation {
|
||||
|
||||
Reference in New Issue
Block a user