Moved Query into separate actions.
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:
@@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
action::Query,
|
||||
document::field::{Field, FieldType},
|
||||
message::action::MsgAction,
|
||||
mtterror::MTTError,
|
||||
@@ -1008,84 +1009,6 @@ impl From<HashSet<Oid>> for QueryType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Query {
|
||||
data: HashMap<NameType, Calculation>,
|
||||
}
|
||||
|
||||
impl Query {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add<NT>(&mut self, name: NT, operation: Calculation)
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
self.data.insert(name.into(), operation);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get<NT>(&self, name: NT) -> Option<Calculation>
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
match self.data.get(&name.into()) {
|
||||
Some(calc) => Some(calc.clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn field_ids(&self) -> HashSet<&NameType> {
|
||||
self.data.keys().collect()
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&NameType, &Calculation)> {
|
||||
self.data.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod queries {
|
||||
use super::*;
|
||||
use crate::name::Name;
|
||||
|
||||
#[test]
|
||||
fn holds_calculation_to_run_query() {
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let data = Uuid::new_v4();
|
||||
let mut bad_data = data.clone();
|
||||
while bad_data == data {
|
||||
bad_data = Uuid::new_v4();
|
||||
}
|
||||
let mut query = Query::new();
|
||||
let mut calc = Calculation::new(Operand::Equal);
|
||||
calc.add_value(data.clone()).unwrap();
|
||||
query.add(name.clone(), calc);
|
||||
match query.get(&name) {
|
||||
Some(op) => {
|
||||
let expected: Field = true.into();
|
||||
let mut holder = op.clone();
|
||||
holder.add_value(data).unwrap();
|
||||
assert_eq!(holder.calculate(&Field::None), expected);
|
||||
}
|
||||
None => unreachable!("should have returned a calculation"),
|
||||
}
|
||||
match query.get(&name) {
|
||||
Some(op) => {
|
||||
let expected: Field = false.into();
|
||||
let mut holder = op.clone();
|
||||
holder.add_value(bad_data).unwrap();
|
||||
assert_eq!(holder.calculate(&Field::None), expected);
|
||||
}
|
||||
None => unreachable!("should have returned a calculation"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Reply {
|
||||
|
||||
Reference in New Issue
Block a user