Updated reply to include document name.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 0s

This commit is contained in:
2026-02-14 13:45:49 -05:00
parent 1f82c07565
commit 903158b72a
4 changed files with 43 additions and 93 deletions

View File

@@ -176,7 +176,7 @@ mod messages {
fn can_make_reply_message() {
let name = Name::english("testing");
let msg = Message::new(name.clone(), Query::new(name.clone()));
let responce = Reply::new();
let responce = Reply::new(Name::english("something"));
let reply = msg.response(responce);
assert_eq!(reply.get_message_id(), msg.get_message_id());
match &reply.document_id {
@@ -215,7 +215,7 @@ mod messages {
let msg = Message::new(doc_id.clone(), Query::new(doc_id.clone()));
let data = Uuid::new_v4().to_string();
let result1 = msg.response(MTTError::new(NameType::None, ErrorID::DocumentNotFound));
let result2 = msg.response(Reply::new());
let result2 = msg.response(Reply::new(NameType::None));
assert_eq!(result1.get_message_id(), msg.get_message_id());
assert_eq!(result2.get_message_id(), msg.get_message_id());
assert_eq!(result1.document_id, msg.document_id);
@@ -266,88 +266,6 @@ impl Operation {
}
}
/*
#[allow(dead_code)]
#[derive(Clone, Debug)]
pub struct Reply {
data: Vec<Document>,
}
#[allow(dead_code)]
impl Reply {
pub fn new() -> Self {
Self { data: Vec::new() }
}
fn add(&mut self, doc: Document) {
self.data.push(doc);
}
pub fn len(&self) -> usize {
self.data.len()
}
fn iter(&self) -> impl Iterator<Item = &Document> {
self.data.iter()
}
}
#[cfg(test)]
mod replies {
use super::*;
use crate::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 = Document::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 = Document::new();
doc1.add_field(fieldname.clone(), "one");
let mut doc2 = Document::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"),
}
}
}
*/
#[derive(Clone, Debug)]
pub struct Document {
data: HashMap<NameType, CalcValue>,