diff --git a/src/message.rs b/src/message.rs index fb348b8..15217c9 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2411,22 +2411,32 @@ mod additions { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq)] enum OnType { Query, Update, } #[derive(Clone, Debug)] -struct On; +struct On { + on_type: OnType, + oids: HashSet, +} impl On { - fn new(on_type: OnType) -> Self { - Self {} + fn new(on_type: OnType, oids: HashSet) -> Self { + Self { + on_type: on_type, + oids: oids, + } } fn get_type(&self) -> &OnType { - &OnType::Query + &self.on_type + } + + fn get_oids(&self) -> &HashSet { + &self.oids } } @@ -2435,14 +2445,17 @@ mod ons { use super::*; #[test] - #[ignore] fn can_create_on_action() { - let value = OnType::Update; - let on = On::new(value.clone()); - let on_type = on.get_type(); - match on_type { - OnType::Update => {}, - _ => unreachable!("got {:?}, should have been update", on_type), + let count = 5; + let values = [OnType::Query, OnType::Update]; + for on_type in values.iter() { + let mut oids: HashSet = HashSet::new(); + while oids.len() < count { + oids.insert(Oid::new()); + } + let result = On::new(on_type.clone(), oids.clone()); + assert_eq!(result.get_type(), on_type); + assert_eq!(result.get_oids(), &oids); } } } @@ -2965,13 +2978,11 @@ impl Calculation { } let mut base = self.get_type(); match self.operation { - Operand::Add => { - match base { - FieldType::DateTime => base = FieldType::Duration, - _ => {}, - } - } - _ => {}, + Operand::Add => match base { + FieldType::DateTime => base = FieldType::Duration, + _ => {} + }, + _ => {} } let ftype = holder.get_type(); if base == ftype { @@ -4338,12 +4349,6 @@ impl DocumentFile { } records.into() - - - - - - /* for (field_id, value) in addition.iter() { let id = match self.docdef.get_field_id(field_id) { @@ -4504,8 +4509,6 @@ impl DocumentFile { } output.into() - - /* let mut changes: HashMap = HashMap::new(); for (key, value) in update.get_values().iter() { @@ -5197,7 +5200,7 @@ mod document_files { let action = result.get_action(); match action { MsgAction::Error(data) => match data { - MTTError::FieldInvalidType => {}, + MTTError::FieldInvalidType => {} _ => unreachable!("got {:?}: should been invalid field type", data), }, _ => unreachable!("got {:?}: should have been a error", action), @@ -5330,7 +5333,8 @@ mod document_files { doc.populate([id.into(), old.into()].to_vec()); let mut update = Update::new(); let mut calc = Calculation::new(Operand::Equal); - calc.add_value(CalcValue::Existing(FieldType::Uuid)).unwrap(); + calc.add_value(CalcValue::Existing(FieldType::Uuid)) + .unwrap(); calc.add_value(id.clone()).unwrap(); update.get_query_mut().add(Name::english("field0"), calc); update @@ -5371,7 +5375,8 @@ mod document_files { let mut update = Update::new(); let mut calc = Calculation::new(Operand::Equal); calc.add_value(picked.clone()).unwrap(); - calc.add_value(CalcValue::Existing(FieldType::Integer)).unwrap(); + calc.add_value(CalcValue::Existing(FieldType::Integer)) + .unwrap(); update.get_query_mut().add(Name::english("field0"), calc); update .get_values_mut() @@ -5426,7 +5431,8 @@ mod document_files { let mut update = Update::new(); let mut calc = Calculation::new(Operand::Equal); calc.add_value(picked.clone()).unwrap(); - calc.add_value(CalcValue::Existing(FieldType::Integer)).unwrap(); + calc.add_value(CalcValue::Existing(FieldType::Integer)) + .unwrap(); update.get_query_mut().add(Name::english("field0"), calc); update .get_values_mut() @@ -5658,7 +5664,8 @@ mod document_files { let mut update = Update::new(); let mut calc = Calculation::new(Operand::Equal); calc.add_value(data).unwrap(); - calc.add_value(CalcValue::Existing(FieldType::StaticString)).unwrap(); + calc.add_value(CalcValue::Existing(FieldType::StaticString)) + .unwrap(); update.get_query_mut().add(&f1name, calc); update.get_values_mut().add_field(&f0name, holder.clone()); doc.send(update).unwrap();