Moved reply into action.
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,7 +1,7 @@
|
||||
use super::{Addition, DocDef, Query, Records, UserAction};
|
||||
use super::{Addition, DocDef, Query, Records, Reply, UserAction};
|
||||
use crate::{
|
||||
message::{
|
||||
wrapper::{Delete, Reply, Update},
|
||||
wrapper::{Delete, Update},
|
||||
MessageAction,
|
||||
},
|
||||
mtterror::MTTError,
|
||||
|
||||
79
src/action/reply.rs
Normal file
79
src/action/reply.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use super::{CalcValue, RequestData};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Reply {
|
||||
data: Vec<RequestData>,
|
||||
}
|
||||
|
||||
impl Reply {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Vec::new() }
|
||||
}
|
||||
|
||||
fn add(&mut self, doc: RequestData) {
|
||||
self.data.push(doc);
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &RequestData> {
|
||||
self.data.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod replies {
|
||||
use super::*;
|
||||
use crate::{action::Field, name::Name};
|
||||
|
||||
#[test]
|
||||
fn is_new_empty() {
|
||||
let reply = Reply::new();
|
||||
assert_eq!(reply.len(), 0, "should have no records");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_add_documents() {
|
||||
let mut reply = Reply::new();
|
||||
let doc = RequestData::new();
|
||||
reply.add(doc.clone());
|
||||
assert_eq!(reply.len(), 1);
|
||||
reply.add(doc.clone());
|
||||
assert_eq!(reply.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_retrieve_documents() {
|
||||
let fieldname = Name::english("field");
|
||||
let mut doc1 = RequestData::new();
|
||||
doc1.add_field(fieldname.clone(), "one");
|
||||
let mut doc2 = RequestData::new();
|
||||
doc2.add_field(fieldname.clone(), "two");
|
||||
let mut reply = Reply::new();
|
||||
reply.add(doc1);
|
||||
reply.add(doc2);
|
||||
let mut reply_iter = reply.iter();
|
||||
let result1 = reply_iter.next().unwrap();
|
||||
match result1.get_field(&fieldname) {
|
||||
CalcValue::Value(data) => match data {
|
||||
Field::StaticString(output) => assert_eq!(output, "one"),
|
||||
_ => unreachable!("got {:?}: should have been static string", result1),
|
||||
},
|
||||
_ => unreachable!("got {:?}, should have been value", result1),
|
||||
}
|
||||
let result2 = reply_iter.next().unwrap();
|
||||
match result2.get_field(&fieldname) {
|
||||
CalcValue::Value(data) => match data {
|
||||
Field::StaticString(output) => assert_eq!(output, "two"),
|
||||
_ => unreachable!("got {:?}: should have been static string", result2),
|
||||
},
|
||||
_ => unreachable!("got {:?}, should have been value", result2),
|
||||
}
|
||||
match reply_iter.next() {
|
||||
None => {}
|
||||
Some(_) => unreachable!("should be out of data"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ impl RequestData {
|
||||
self.data.insert(name.into(), field.into());
|
||||
}
|
||||
|
||||
fn get_field<NT>(&self, name: NT) -> &CalcValue
|
||||
pub fn get_field<NT>(&self, name: NT) -> &CalcValue
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user