use crate::conversions::Converter;
use crate::testing::Error::UnknownTestCase;
use crate::testing::{TestCase, TestCaseIndex};
pub trait TestDefinition: Converter {
fn list_indexes(&self) -> Vec<TestCaseIndex<Self>>;
fn generate_index_code(&self, index: &TestCaseIndex<Self>) -> Self::TargetType;
fn list_test_cases(&self) -> Vec<TestCase<Self>> {
self.list_indexes()
.into_iter()
.flat_map(|index| index.test_cases)
.collect()
}
fn require_test_case(&self, path: &str) -> Result<TestCase<Self>, crate::Error> {
let case = self
.list_test_cases()
.into_iter()
.find(|case| case.schema.as_os_str() == path)
.ok_or_else(|| UnknownTestCase {
path: path.to_string(),
})?;
Ok(case)
}
}