2026-02-25 10:16:50 -05:00
|
|
|
mod support;
|
|
|
|
|
|
|
|
|
|
use morethantext::{
|
|
|
|
|
action::{Addition, DocDef, Field, FieldType, Query},
|
2026-02-25 13:44:43 -05:00
|
|
|
ErrorID, MTTError, MoreThanText, Name,
|
2026-02-25 10:16:50 -05:00
|
|
|
};
|
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
use support::random_name;
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn can_new_documents_be_added() {
|
|
|
|
|
let count = 5;
|
|
|
|
|
let mut mtt = MoreThanText::new();
|
|
|
|
|
let doc_name = random_name();
|
|
|
|
|
let field_name = random_name();
|
|
|
|
|
let mut data: HashSet<Field> = HashSet::new();
|
|
|
|
|
for i in 0..count {
|
|
|
|
|
data.insert(i.into());
|
|
|
|
|
}
|
|
|
|
|
let mut docdef = DocDef::new(doc_name.clone());
|
|
|
|
|
docdef.add_field(field_name.clone(), FieldType::Integer);
|
|
|
|
|
mtt.create_document(docdef);
|
|
|
|
|
for item in data.iter() {
|
|
|
|
|
let mut add = Addition::new(doc_name.clone());
|
|
|
|
|
add.add_field(field_name.clone(), item.clone());
|
|
|
|
|
mtt.records(add).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let qry = Query::new(doc_name.clone());
|
|
|
|
|
let recs = mtt.records(qry).unwrap();
|
|
|
|
|
assert_eq!(recs.len(), data.len());
|
|
|
|
|
for rec in recs.iter() {
|
|
|
|
|
let result = rec.get(&field_name).unwrap();
|
|
|
|
|
assert!(
|
|
|
|
|
data.contains(&result),
|
|
|
|
|
"did not find {:?} in {:?}",
|
|
|
|
|
result,
|
|
|
|
|
data
|
|
|
|
|
);
|
|
|
|
|
data.remove(&result);
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(data.len(), 0, "{:?} did not appear in query", data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-02-25 13:44:43 -05:00
|
|
|
fn does_it_error_on_a_bad_document_name() {
|
2026-02-25 10:16:50 -05:00
|
|
|
let mut mtt = MoreThanText::new();
|
|
|
|
|
let doc_name = Name::english("empty");
|
2026-02-25 13:44:43 -05:00
|
|
|
let mut expected = MTTError::new(ErrorID::NameNotFound(doc_name.clone().into()));
|
|
|
|
|
expected.add_parent(ErrorID::Document(doc_name.clone().into()));
|
|
|
|
|
let add = Addition::new(doc_name.clone());
|
|
|
|
|
let result = mtt.records(add).unwrap_err();
|
|
|
|
|
assert_eq!(result.to_string(), expected.to_string());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2026-02-25 10:16:50 -05:00
|
|
|
let result = mtt
|
|
|
|
|
.records(add)
|
|
|
|
|
.unwrap_err()
|
|
|
|
|
.get_error_ids()
|
|
|
|
|
.back()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.clone();
|
|
|
|
|
match result {
|
2026-02-25 13:44:43 -05:00
|
|
|
ErrorID::NameNotFound(_) => {}
|
2026-02-25 10:16:50 -05:00
|
|
|
_ => unreachable!(
|
|
|
|
|
"got {:?}: should have been document field not found.",
|
|
|
|
|
result
|
|
|
|
|
),
|
|
|
|
|
}
|
2026-02-25 13:44:43 -05:00
|
|
|
*/
|
2026-02-25 10:16:50 -05:00
|
|
|
}
|