Confirmed fields can be calculated.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
parent
a153e23d38
commit
0c2af3bc96
@ -1604,6 +1604,7 @@ mod operands {
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
enum CalcValue {
|
enum CalcValue {
|
||||||
|
Calculate(Calculation),
|
||||||
FType(FieldType),
|
FType(FieldType),
|
||||||
Value(Field),
|
Value(Field),
|
||||||
}
|
}
|
||||||
@ -1613,10 +1614,17 @@ impl CalcValue {
|
|||||||
match self {
|
match self {
|
||||||
Self::FType(ftype) => ftype.get_default(),
|
Self::FType(ftype) => ftype.get_default(),
|
||||||
Self::Value(field) => field.clone(),
|
Self::Value(field) => field.clone(),
|
||||||
|
Self::Calculate(calc) => calc.calculate(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Calculation> for CalcValue {
|
||||||
|
fn from(value: Calculation) -> Self {
|
||||||
|
Self::Calculate(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Field> for CalcValue {
|
impl From<Field> for CalcValue {
|
||||||
fn from(value: Field) -> Self {
|
fn from(value: Field) -> Self {
|
||||||
Self::Value(value)
|
Self::Value(value)
|
||||||
@ -1687,10 +1695,11 @@ mod calcvalues {
|
|||||||
let value = Uuid::new_v4();
|
let value = Uuid::new_v4();
|
||||||
let expected: Field = value.into();
|
let expected: Field = value.into();
|
||||||
let result: CalcValue = value.into();
|
let result: CalcValue = value.into();
|
||||||
match result {
|
match result.clone() {
|
||||||
CalcValue::FType(_) => unreachable!("got {:?}, should have gotten a field", result),
|
|
||||||
CalcValue::Value(data) => assert_eq!(data, expected),
|
CalcValue::Value(data) => assert_eq!(data, expected),
|
||||||
|
_ => unreachable!("got {:?}, should have gotten a field", result),
|
||||||
}
|
}
|
||||||
|
assert_eq!(result.get(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1698,10 +1707,11 @@ mod calcvalues {
|
|||||||
let value = "something";
|
let value = "something";
|
||||||
let expected: Field = value.into();
|
let expected: Field = value.into();
|
||||||
let result: CalcValue = value.into();
|
let result: CalcValue = value.into();
|
||||||
match result {
|
match result.clone() {
|
||||||
CalcValue::FType(_) => unreachable!("got {:?}, should have gotten a field", result),
|
|
||||||
CalcValue::Value(data) => assert_eq!(data, expected),
|
CalcValue::Value(data) => assert_eq!(data, expected),
|
||||||
|
_ => unreachable!("got {:?}, should have gotten a field", result),
|
||||||
}
|
}
|
||||||
|
assert_eq!(result.get(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1709,10 +1719,11 @@ mod calcvalues {
|
|||||||
let value = "data".to_string();
|
let value = "data".to_string();
|
||||||
let expected: Field = value.clone().into();
|
let expected: Field = value.clone().into();
|
||||||
let result: CalcValue = value.into();
|
let result: CalcValue = value.into();
|
||||||
match result {
|
match result.clone() {
|
||||||
CalcValue::FType(_) => unreachable!("got {:?}, should have gotten a field", result),
|
|
||||||
CalcValue::Value(data) => assert_eq!(data, expected),
|
CalcValue::Value(data) => assert_eq!(data, expected),
|
||||||
|
_ => unreachable!("got {:?}, should have gotten a field", result),
|
||||||
}
|
}
|
||||||
|
assert_eq!(result.get(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1720,10 +1731,11 @@ mod calcvalues {
|
|||||||
let value = true;
|
let value = true;
|
||||||
let expected: Field = value.clone().into();
|
let expected: Field = value.clone().into();
|
||||||
let result: CalcValue = value.into();
|
let result: CalcValue = value.into();
|
||||||
match result {
|
match result.clone() {
|
||||||
CalcValue::FType(_) => unreachable!("got {:?}, should have gotten a field", result),
|
|
||||||
CalcValue::Value(data) => assert_eq!(data, expected),
|
CalcValue::Value(data) => assert_eq!(data, expected),
|
||||||
|
_ => unreachable!("got {:?}, should have gotten a field", result),
|
||||||
}
|
}
|
||||||
|
assert_eq!(result.get(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1731,10 +1743,11 @@ mod calcvalues {
|
|||||||
let value = Utc::now();
|
let value = Utc::now();
|
||||||
let expected: Field = value.clone().into();
|
let expected: Field = value.clone().into();
|
||||||
let result: CalcValue = value.into();
|
let result: CalcValue = value.into();
|
||||||
match result {
|
match result.clone() {
|
||||||
CalcValue::FType(_) => unreachable!("got {:?}, should have gotten a field", result),
|
|
||||||
CalcValue::Value(data) => assert_eq!(data, expected),
|
CalcValue::Value(data) => assert_eq!(data, expected),
|
||||||
|
_ => unreachable!("got {:?}, should have gotten a field", result),
|
||||||
}
|
}
|
||||||
|
assert_eq!(result.get(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1742,10 +1755,11 @@ mod calcvalues {
|
|||||||
let value = Duration::from_secs(5);
|
let value = Duration::from_secs(5);
|
||||||
let expected: Field = value.clone().into();
|
let expected: Field = value.clone().into();
|
||||||
let result: CalcValue = value.into();
|
let result: CalcValue = value.into();
|
||||||
match result {
|
match result.clone() {
|
||||||
CalcValue::FType(_) => unreachable!("got {:?}, should have gotten a field", result),
|
|
||||||
CalcValue::Value(data) => assert_eq!(data, expected),
|
CalcValue::Value(data) => assert_eq!(data, expected),
|
||||||
|
_ => unreachable!("got {:?}, should have gotten a field", result),
|
||||||
}
|
}
|
||||||
|
assert_eq!(result.get(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1753,10 +1767,30 @@ mod calcvalues {
|
|||||||
let value: i128 = 5;
|
let value: i128 = 5;
|
||||||
let expected: Field = value.clone().into();
|
let expected: Field = value.clone().into();
|
||||||
let result: CalcValue = value.into();
|
let result: CalcValue = value.into();
|
||||||
match result {
|
match result.clone() {
|
||||||
CalcValue::FType(_) => unreachable!("got {:?}, should have gotten a field", result),
|
|
||||||
CalcValue::Value(data) => assert_eq!(data, expected),
|
CalcValue::Value(data) => assert_eq!(data, expected),
|
||||||
|
_ => unreachable!("got {:?}, should have gotten a field", result),
|
||||||
}
|
}
|
||||||
|
assert_eq!(result.get(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_calculation() {
|
||||||
|
let duration = Duration::from_secs(300);
|
||||||
|
let start = Utc::now() + duration;
|
||||||
|
let mut calc = Calculation::new(Operand::Add);
|
||||||
|
calc.add_value(FieldType::DateTime);
|
||||||
|
calc.add_value(duration.clone());
|
||||||
|
let result: CalcValue = calc.into();
|
||||||
|
let data = match result.get() {
|
||||||
|
Field::DateTime(data) => data,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
let stop = Utc::now() + duration;
|
||||||
|
assert!(
|
||||||
|
data > start && data < stop,
|
||||||
|
"should be about 5 minutes ahead"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3813,6 +3847,35 @@ mod document_files {
|
|||||||
_ => unreachable!("got {:?}: should have gotten reply", action),
|
_ => unreachable!("got {:?}: should have gotten reply", action),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_calculate_field_values() {
|
||||||
|
let mut doc = TestDocument::new([FieldType::DateTime].to_vec());
|
||||||
|
doc.start();
|
||||||
|
let duration = Duration::from_secs(300);
|
||||||
|
let mut calc = Calculation::new(Operand::Add);
|
||||||
|
calc.add_value(FieldType::DateTime).unwrap();
|
||||||
|
calc.add_value(duration.clone()).unwrap();
|
||||||
|
let mut addition = Addition::new();
|
||||||
|
addition.add_field("field0".to_string(), calc);
|
||||||
|
let start = Utc::now() + duration;
|
||||||
|
doc.send(addition).unwrap();
|
||||||
|
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
||||||
|
let stop = Utc::now() + duration;
|
||||||
|
let action = result.get_action();
|
||||||
|
match action {
|
||||||
|
MsgAction::Reply(data) => {
|
||||||
|
assert_eq!(data.len(), 1);
|
||||||
|
for doc in data.iter() {
|
||||||
|
match doc.get_field("field0").unwrap() {
|
||||||
|
Field::DateTime(datetime) => assert!(datetime > start && datetime < stop),
|
||||||
|
_ => unreachable!("did not get uuid"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => unreachable!("got {:?}: should have gotten reply", action),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user