Added the ability to populate test documents.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-02-28 01:38:49 -05:00
parent 8d0b149b31
commit 03134aa9fd
2 changed files with 61 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
mod support;
use morethantext::{FieldType, Name};
use morethantext::{Field, FieldType, MoreThanText, Name, Query};
use support::TestDocument;
#[test]
@@ -29,7 +29,7 @@ fn can_fields_be_created() {
let ftypes = [FieldType::Uuid, FieldType::Integer];
for ftype in ftypes.iter() {
let mut input = Vec::new();
for i in 0..count {
for _ in 0..count {
input.push(ftype.clone());
}
let test_doc = TestDocument::new(input);
@@ -54,3 +54,45 @@ fn can_field_types_be_varied() {
.unwrap();
}
}
#[test]
fn can_record_be_added_to_document() {
let count = 5;
let mut mtt = MoreThanText::new();
let mut fields: Vec<FieldType> = Vec::new();
let mut input: Vec<String> = Vec::new();
for i in 0..count {
fields.push(FieldType::StaticString);
input.push(i.to_string());
}
let test_doc = TestDocument::new(fields);
mtt.create_document(test_doc.get_docdef());
test_doc.populate(&mut mtt, input);
let query = Query::new(test_doc.get_doc_name());
let results = mtt.records(query).unwrap();
assert_eq!(results.len(), 1);
for rec in results.iter() {
for i in 0..count {
let field = rec.get(test_doc.get_field_name(i)).unwrap();
assert_eq!(field, i.to_string().into());
}
}
}
#[test]
fn can_document_be_populated_with_multiple_records() {
let count = 5;
let mut mtt = MoreThanText::new();
let test_doc = TestDocument::new(vec![FieldType::Integer]);
mtt.create_document(test_doc.get_docdef());
let mut data: Vec<Vec<i128>> = Vec::new();
for i in 0..count {
let item: i128 = i.try_into().unwrap();
let holder: Vec<i128> = vec![item];
data.push(holder);
}
test_doc.populate_multiple(&mut mtt, data);
let query = Query::new(test_doc.get_doc_name());
let results = mtt.records(query).unwrap();
assert_eq!(results.len(), count);
}