Moved missing fields add test to lib.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-02-27 12:22:57 -05:00
parent 632332298d
commit 8d0b149b31
4 changed files with 117 additions and 14 deletions

56
tests/support_test.rs Normal file
View File

@@ -0,0 +1,56 @@
mod support;
use morethantext::{FieldType, Name};
use support::TestDocument;
#[test]
fn are_document_names_unique() {
let test_doc1 = TestDocument::new(Vec::new());
let test_doc2 = TestDocument::new(Vec::new());
assert_ne!(test_doc1.get_doc_name(), test_doc2.get_doc_name());
}
#[test]
fn does_test_doc_create_docdef() {
let test_doc = TestDocument::new(Vec::new());
let expected = vec![test_doc.get_doc_name().clone()];
let docdef = test_doc.get_docdef();
assert_eq!(docdef.get_document_names(), &expected);
}
#[test]
fn can_fields_be_created() {
let count = 5;
let mut expected_fields = Vec::new();
for i in 0..count {
let name = Name::english(format!("field{}", i).as_str());
expected_fields.push(name);
}
let ftypes = [FieldType::Uuid, FieldType::Integer];
for ftype in ftypes.iter() {
let mut input = Vec::new();
for i in 0..count {
input.push(ftype.clone());
}
let test_doc = TestDocument::new(input);
for i in 0..count {
assert_eq!(test_doc.get_field_name(i), expected_fields[i]);
}
let docdef = test_doc.get_docdef();
for name in expected_fields.iter() {
docdef.validate(name, &ftype.get_default()).unwrap();
}
}
}
#[test]
fn can_field_types_be_varied() {
let field_types = vec![FieldType::Uuid, FieldType::Integer];
let test_doc = TestDocument::new(field_types.clone());
let docdef = test_doc.get_docdef();
for i in 0..field_types.len() {
docdef
.validate(test_doc.get_field_name(i), &field_types[i].get_default())
.unwrap();
}
}