use super::{Bound, Slot};
use crate::{SlotHandle, SlotName};
struct SearchDocument;
struct TitleTantivy;
struct TitleHnsw;
struct BodyTantivy;
impl Slot for TitleTantivy {
type Of = SearchDocument;
const SLOT: &'static SlotName = SlotName::new("search_document__title__tantivy");
const FIELD: &'static str = "title";
const ENGINE: &'static str = "tantivy";
}
impl Slot for TitleHnsw {
type Of = SearchDocument;
const SLOT: &'static SlotName = SlotName::new("search_document__title__hnsw");
const FIELD: &'static str = "title";
const ENGINE: &'static str = "hnsw";
}
impl Slot for BodyTantivy {
type Of = SearchDocument;
const SLOT: &'static SlotName = SlotName::new("search_document__body__tantivy");
const FIELD: &'static str = "body";
const ENGINE: &'static str = "hnsw";
}
struct AppEngineHnsw;
struct Hnsw;
impl Bound for AppEngineHnsw {
type Engine = Hnsw;
const WORD: &'static str = "hnsw";
}
#[test]
fn a_slot_name_is_unique_in_both_axes() {
assert_ne!(TitleTantivy::SLOT, TitleHnsw::SLOT);
assert_ne!(TitleTantivy::SLOT, BodyTantivy::SLOT);
}
#[test]
fn a_slot_names_the_field_and_the_engine_it_pairs() {
assert_eq!(TitleTantivy::FIELD, "title");
assert_eq!(TitleHnsw::FIELD, "title");
assert_eq!(TitleTantivy::ENGINE, "tantivy");
assert_eq!(TitleHnsw::ENGINE, "hnsw");
}
#[test]
fn two_slots_of_one_engine_are_two_branded_handles() {
let title: SlotHandle<(), TitleTantivy> = SlotHandle::mint(());
let body: SlotHandle<(), BodyTantivy> = SlotHandle::mint(());
assert_eq!(core::mem::size_of_val(&title), core::mem::size_of::<()>());
assert_eq!(title.engine(), body.engine());
}
#[test]
fn a_bound_word_resolves_to_its_concrete_engine() {
fn resolved(engine: <AppEngineHnsw as Bound>::Engine) -> Hnsw {
engine
}
let _: fn(Hnsw) -> Hnsw = resolved;
assert_eq!(AppEngineHnsw::WORD, "hnsw");
}
#[test]
fn a_slots_engine_word_is_the_word_the_table_binds() {
assert_eq!(TitleHnsw::ENGINE, AppEngineHnsw::WORD);
}