use ingraph_codegen::{index::IndexModel, prelude::*};
fn parse(input: &syn::DeriveInput) -> syn::Result<IndexModel> {
let (host, arguments) = crate::host::split(input);
super::parse(&host, &arguments, NodeKind::Vector)
}
fn declaration(entry: proc_macro2::TokenStream) -> syn::DeriveInput {
syn::parse_quote! {
#[ingraph(upstream(node = "media::Keyframe", clip = "clip"), dedup(hash))]
pub struct Shots {
#[ingraph(embedding, knn(#entry), toy)]
clip: Embedding<f32, 4, Clip>,
}
}
}
fn refusals(entry: proc_macro2::TokenStream) -> String {
parse(&declaration(entry))
.expect_err("the declaration is refused")
.into_iter()
.map(|e| e.to_string())
.collect::<Vec<_>>()
.join("\n")
}
#[test]
fn the_road_reaches_the_election_as_the_type_its_author_wrote() {
let model = parse(&declaration(
quote::quote! { searchable(tower = "media::ClipText") },
))
.expect("an election naming its tower road is legal");
let road = model.embeddings[0]
.tower_road
.as_ref()
.expect("the road did not reach its seat");
assert_eq!(
quote::quote!(#road).to_string().replace(' ', ""),
"media::ClipText",
);
}
#[test]
fn an_election_with_no_road_word_carries_none() {
let model = parse(&syn::parse_quote! {
#[ingraph(upstream(node = "media::Keyframe", clip = "clip"), dedup(hash))]
pub struct Shots {
#[ingraph(embedding, knn, toy)]
clip: Embedding<f32, 4, Clip>,
}
})
.expect("an election with a bare marker is legal");
assert!(
model.embeddings[0].tower_road.is_none(),
"a road appeared on an election that wrote no word",
);
}
#[test]
fn the_bare_word_is_told_what_the_two_positions_differ_by() {
for entry in [quote::quote! { searchable }, quote::quote! { searchable() }] {
let refused = refusals(entry.clone());
assert!(
refused.contains("names the TOWER"),
"`{entry}` was not refused as a shape: {refused}",
);
assert!(
refused.contains("It is BARE on a full-text election"),
"the sentence does not say why the other position takes nothing: {refused}",
);
assert!(
refused.contains("knn(searchable(tower = \"path::to::Tower\"))"),
"the sentence does not spell the form: {refused}",
);
}
}
#[test]
fn an_unquoted_tower_is_refused_under_the_crossing_law() {
let refused = refusals(quote::quote! { searchable(tower = media::ClipText) });
assert!(
refused.contains("names the tower that walks a question"),
"{refused}",
);
assert!(
refused.contains("QUOTED"),
"the sentence does not name the law: {refused}",
);
}
#[test]
fn a_second_road_names_the_declaration_that_holds_two() {
let refused = refusals(quote::quote! {
searchable(tower = "media::ClipText", tower = "media::ClipImage")
});
assert!(
refused.contains("`tower` is declared more than once"),
"{refused}",
);
assert!(
refused.contains("`#[ingraph::search]` recipe"),
"the sentence does not say where a second road goes: {refused}",
);
}
#[test]
fn an_unknown_entry_inside_the_block_draws_the_boundary() {
let refused = refusals(quote::quote! { searchable(weight = 1.0) });
assert!(
refused.contains("unknown entry in `searchable(…)`"),
"{refused}"
);
assert!(
refused.contains("Every other knob a search has is the RECIPE's"),
"the sentence does not draw the boundary: {refused}",
);
}
#[test]
fn the_unknown_entry_sentence_offers_both_of_the_blocks_words() {
let refused = refusals(quote::quote! { searchably(tower = "media::ClipText") });
assert!(refused.contains("unknown entry in `knn(…)`"), "{refused}");
assert!(refused.contains("`searchable(tower = \"…\")`"), "{refused}");
assert!(refused.contains("`semantics(<kind> = \"…\")`"), "{refused}");
assert!(
refused.contains("did you mean `searchable`"),
"the near miss is not offered: {refused}",
);
}
#[test]
fn the_retired_road_word_names_the_word_that_replaced_it() {
let refused = refusals(quote::quote! { ask = "ClipTextTower" });
assert!(refused.contains("`ask` has retired"), "{refused}");
assert!(
refused.contains("knn(searchable(tower = \"path::to::Tower\"))"),
"the retirement does not name the short road: {refused}",
);
}