use super::tests::{accepted, refused};
fn bound(model: &ingraph_codegen::graph::GraphModel) -> Vec<String> {
model
.engines
.iter()
.map(|binding| {
format!(
"{}={}",
binding.word,
quote::ToTokens::to_token_stream(&binding.engine)
.to_string()
.replace(' ', "")
)
})
.collect()
}
#[test]
fn a_root_binds_a_word_to_a_concrete_engine() {
let model = accepted(quote::quote! {
#[ingraph(engines(hnsw = "app::hnsw::Hnsw"))]
pub struct App {
frames: Keyframes,
}
});
assert_eq!(bound(&model), ["hnsw=app::hnsw::Hnsw"]);
}
#[test]
fn several_words_keep_the_order_they_were_written_in() {
let model = accepted(quote::quote! {
#[ingraph(engines(hnsw = "app::Hnsw", lance = "app::Lance", sonic = "app::Sonic"))]
pub struct App {
frames: Keyframes,
}
});
assert_eq!(
bound(&model),
["hnsw=app::Hnsw", "lance=app::Lance", "sonic=app::Sonic"]
);
}
#[test]
fn a_root_that_binds_nothing_is_the_ordinary_root() {
let model = accepted(quote::quote! {
pub struct App {
frames: Keyframes,
}
});
assert!(model.engines.is_empty());
}
#[test]
fn the_crate_entry_still_reads_beside_it() {
let model = accepted(quote::quote! {
#[ingraph(crate = "shim::ingraph", engines(hnsw = "app::Hnsw"))]
pub struct App {
frames: Keyframes,
}
});
assert_eq!(
quote::ToTokens::to_token_stream(&model.krate)
.to_string()
.replace(' ', ""),
"shim::ingraph"
);
assert_eq!(bound(&model), ["hnsw=app::Hnsw"]);
}
#[test]
fn a_shipped_word_cannot_be_rebound() {
let refusal = refused(quote::quote! {
#[ingraph(engines(tantivy = "app::MyTantivy"))]
pub struct App {
docs: SearchDocument,
}
});
assert!(
refusal.contains("BINDS ITSELF"),
"the refusal says the word is already bound: {refusal}"
);
assert!(
refusal.contains("feature = \"tantivy\""),
"and where it is bound: {refusal}"
);
}
#[test]
fn a_word_is_bound_once() {
let refusal = refused(quote::quote! {
#[ingraph(engines(hnsw = "app::Hnsw", hnsw = "app::Other"))]
pub struct App {
frames: Keyframes,
}
});
assert!(
refusal.contains("bound more than once"),
"the refusal names the repeat: {refusal}"
);
}
#[test]
fn one_root_holds_one_engine_table() {
let refusal = refused(quote::quote! {
#[ingraph(engines(hnsw = "app::Hnsw"), engines(lance = "app::Lance"))]
pub struct App {
frames: Keyframes,
}
});
assert!(
refusal.contains("declared more than once"),
"the refusal names the second block: {refusal}"
);
}
#[test]
fn the_engine_is_quoted() {
let refusal = refused(quote::quote! {
#[ingraph(engines(hnsw = app::Hnsw))]
pub struct App {
frames: Keyframes,
}
});
assert!(
refusal.contains("in a string literal"),
"the refusal states the spelling: {refusal}"
);
}
#[test]
fn the_word_is_one_segment_and_the_path_goes_on_the_right() {
let refusal = refused(quote::quote! {
#[ingraph(engines(app::hnsw = "app::Hnsw"))]
pub struct App {
frames: Keyframes,
}
});
assert!(
refusal.contains("an engine word is ONE word"),
"the refusal states the shape: {refusal}"
);
assert!(
refusal.contains("goes on the right"),
"and where the path belongs: {refusal}"
);
}
#[test]
fn the_unknown_entry_sentence_names_the_engine_table() {
let refusal = refused(quote::quote! {
#[ingraph(backends(hnsw = "app::Hnsw"))]
pub struct App {
frames: Keyframes,
}
});
assert!(
refusal.contains("engines(<word> = \"path::To::Engine\")"),
"the sentence lists what a root takes: {refusal}"
);
}