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:
parent
aae2548da3
commit
9dbaaceb80
@ -1,4 +1,5 @@
|
|||||||
mod action_type;
|
mod action_type;
|
||||||
|
mod addition;
|
||||||
mod calculation;
|
mod calculation;
|
||||||
mod message;
|
mod message;
|
||||||
mod query;
|
mod query;
|
||||||
@ -10,6 +11,7 @@ pub use crate::document::{
|
|||||||
field::{Field, FieldType},
|
field::{Field, FieldType},
|
||||||
};
|
};
|
||||||
pub use action_type::Action;
|
pub use action_type::Action;
|
||||||
|
pub use addition::Addition;
|
||||||
pub use calculation::{CalcValue, Calculation, Operand};
|
pub use calculation::{CalcValue, Calculation, Operand};
|
||||||
pub use message::MsgAction;
|
pub use message::MsgAction;
|
||||||
pub use query::Query;
|
pub use query::Query;
|
||||||
|
|||||||
94
src/action/addition.rs
Normal file
94
src/action/addition.rs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
use super::{CalcValue, Field, RequestData};
|
||||||
|
use crate::name::NameType;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Addition {
|
||||||
|
data: RequestData,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Addition {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
data: RequestData::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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ntype: NameType = name.clone().into();
|
||||||
|
let data = Uuid::new_v4().to_string();
|
||||||
|
add.add_field(name.clone(), data.clone());
|
||||||
|
assert_eq!(add.iter().count(), 1);
|
||||||
|
for (field_name, value) in add.iter() {
|
||||||
|
assert_eq!(field_name, &ntype);
|
||||||
|
match value {
|
||||||
|
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", value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_add_uuid() {
|
||||||
|
let mut add = Addition::new();
|
||||||
|
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||||
|
let ntype: NameType = name.clone().into();
|
||||||
|
let data = Uuid::new_v4();
|
||||||
|
add.add_field(name.clone(), data.clone());
|
||||||
|
assert_eq!(add.iter().count(), 1);
|
||||||
|
for (field_name, value) in add.iter() {
|
||||||
|
assert_eq!(field_name, &ntype);
|
||||||
|
match value {
|
||||||
|
CalcValue::Value(result) => match result {
|
||||||
|
Field::Uuid(output) => assert_eq!(output, &data),
|
||||||
|
_ => unreachable!("got {:?}, should have been a string", result),
|
||||||
|
},
|
||||||
|
_ => unreachable!("got {:?}: should have received value", value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#[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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
use super::{DocDef, Query, UserAction};
|
use super::{Addition, DocDef, Query, UserAction};
|
||||||
use crate::{
|
use crate::{
|
||||||
message::wrapper::{Addition, Delete, Records, Reply, Update},
|
message::wrapper::{Delete, Records, Reply, Update},
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
name::NameType,
|
name::NameType,
|
||||||
queue::data_director::Register,
|
queue::data_director::Register,
|
||||||
@ -27,6 +27,7 @@ pub enum MsgAction {
|
|||||||
impl MsgAction {
|
impl MsgAction {
|
||||||
fn doc_name(&self) -> NameType {
|
fn doc_name(&self) -> NameType {
|
||||||
match self {
|
match self {
|
||||||
|
Self::Addition(data) => NameType::None,
|
||||||
Self::Query(data) => data.doc_name(),
|
Self::Query(data) => data.doc_name(),
|
||||||
_ => NameType::None,
|
_ => NameType::None,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ pub struct RequestData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RequestData {
|
impl RequestData {
|
||||||
fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: HashMap::new(),
|
data: HashMap::new(),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -811,9 +811,9 @@ impl DocumentFile {
|
|||||||
mod document_files {
|
mod document_files {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Operand,
|
action::{Addition, Operand},
|
||||||
document::field::FieldType,
|
document::field::FieldType,
|
||||||
message::wrapper::{Addition, Delete},
|
message::wrapper::Delete,
|
||||||
name::{Name, Names},
|
name::{Name, Names},
|
||||||
support_tests::TIMEOUT,
|
support_tests::TIMEOUT,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -85,13 +85,13 @@ impl Session {
|
|||||||
mod sessions {
|
mod sessions {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
action::{MsgAction, Query},
|
action::{Addition, MsgAction, Query},
|
||||||
document::{
|
document::{
|
||||||
clock::{clock_test_support::gen_clock_message, Clock},
|
clock::{clock_test_support::gen_clock_message, Clock},
|
||||||
create::CreateDoc,
|
create::CreateDoc,
|
||||||
field::Field,
|
field::Field,
|
||||||
},
|
},
|
||||||
message::wrapper::{Addition, Records},
|
message::wrapper::Records,
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
name::{Name, NameType, Names},
|
name::{Name, NameType, Names},
|
||||||
queue::data_director::{Include, Path, RegMsg, Register},
|
queue::data_director::{Include, Path, RegMsg, Register},
|
||||||
|
|||||||
@ -6,10 +6,11 @@ mod name;
|
|||||||
mod queue;
|
mod queue;
|
||||||
|
|
||||||
use action::{
|
use action::{
|
||||||
Action, CalcValue, Calculation, DocDef, Field, FieldType, MsgAction, Operand, Query, UserAction,
|
Action, Addition, CalcValue, Calculation, DocDef, Field, FieldType, MsgAction, Operand, Query,
|
||||||
|
UserAction,
|
||||||
};
|
};
|
||||||
use document::{clock::Clock, create::CreateDoc, session::Session};
|
use document::{clock::Clock, create::CreateDoc, session::Session};
|
||||||
use message::wrapper::{Addition, Message};
|
use message::wrapper::Message;
|
||||||
use queue::{
|
use queue::{
|
||||||
data_director::{Include, Path, RegMsg, Register},
|
data_director::{Include, Path, RegMsg, Register},
|
||||||
router::Queue,
|
router::Queue,
|
||||||
|
|||||||
@ -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)]
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Operation {
|
pub struct Operation {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user