use ingraph_codegen::{index::IndexModel, prelude::*};
fn parse(input: &syn::DeriveInput, kind: NodeKind) -> syn::Result<IndexModel> {
let (host, arguments) = crate::host::split(input);
super::parse(&host, &arguments, kind)
}
fn fulltext(entry: proc_macro2::TokenStream) -> syn::DeriveInput {
syn::parse_quote! {
#[ingraph(#entry, upstream(node = "asr::Segment", body = "text"), dedup(hash))]
pub struct Transcript {
#[ingraph(searchable, lexical(resource = "crate::Ft"))]
body: String,
}
}
}
fn refusals(input: &syn::DeriveInput, kind: NodeKind) -> String {
parse(input, kind)
.expect_err("the declaration is refused")
.into_iter()
.map(|refusal| refusal.to_string())
.collect::<Vec<_>>()
.join("\n")
}
#[test]
fn the_bare_word_is_the_launch_seat_and_its_absence_is_the_hand_road() {
let wearing = parse(&fulltext(quote::quote!(subscribe)), NodeKind::Fulltext)
.expect("a full-text declaration may launch");
assert!(wearing.subscribe, "the word did not reach the model");
let bare = parse(
&syn::parse_quote! {
#[ingraph(upstream(node = "asr::Segment", body = "text"), dedup(hash))]
pub struct Transcript {
#[ingraph(searchable, lexical(resource = "crate::Ft"))]
body: String,
}
},
NodeKind::Fulltext,
)
.expect("a declaration with no word is the road that shipped");
assert!(
!bare.subscribe,
"a declaration that wrote nothing was read as launching",
);
}
#[test]
fn a_valued_word_is_refused_with_the_entry_that_already_names_the_edge() {
let refused = refusals(
&fulltext(quote::quote!(subscribe = "asr::Segment")),
NodeKind::Fulltext,
);
assert!(refused.contains("BARE"), "{refused}");
assert!(refused.contains("upstream(…)"), "{refused}");
assert!(refused.contains("LAUNCHES"), "{refused}");
}
#[test]
fn a_block_is_refused_with_the_per_edge_words_it_would_have_carried() {
let refused = refusals(
&fulltext(quote::quote!(subscribe(channel = bounded(8)))),
NodeKind::Fulltext,
);
assert!(refused.contains("no block"), "{refused}");
assert!(refused.contains("channel"), "{refused}");
assert!(refused.contains("changes(<db>)"), "{refused}");
}
#[test]
fn the_word_written_twice_is_refused_as_a_presence() {
let refused = refusals(
&fulltext(quote::quote!(subscribe, subscribe)),
NodeKind::Fulltext,
);
assert!(refused.contains("more than once"), "{refused}");
assert!(refused.contains("PRESENCE"), "{refused}");
}
#[test]
fn the_word_on_a_kind_without_the_road_names_the_deferral() {
let vector = refusals(
&syn::parse_quote! {
#[ingraph(subscribe, upstream(node = "media::Keyframe", clip = "clip"), dedup(hash))]
pub struct Shots {
#[ingraph(embedding, knn, lance(resource = "crate::Lance"))]
clip: Embedding<f32, 4, Clip>,
}
},
NodeKind::Vector,
);
assert!(vector.contains("LAUNCHABLE NODE"), "{vector}");
assert!(vector.contains("deferred"), "{vector}");
assert!(vector.contains("FulltextLane"), "{vector}");
let blob = refusals(
&syn::parse_quote! {
#[ingraph(subscribe, upstream(node = "media::Shot", frame = "frame"), fs)]
pub struct Thumbs {
frame: String,
}
},
NodeKind::Blob,
);
assert!(blob.contains("LAUNCHABLE NODE"), "{blob}");
assert!(blob.contains("deferred"), "{blob}");
}
#[test]
fn the_unknown_entry_roster_offers_the_word_only_where_it_is_taken() {
let fulltext = refusals(&fulltext(quote::quote!(subscribed)), NodeKind::Fulltext);
assert!(fulltext.contains("`subscribe`"), "{fulltext}");
let vector = refusals(
&syn::parse_quote! {
#[ingraph(subscribed, upstream(node = "media::Keyframe", clip = "clip"), dedup(hash))]
pub struct Shots {
#[ingraph(embedding, knn, lance(resource = "crate::Lance"))]
clip: Embedding<f32, 4, Clip>,
}
},
NodeKind::Vector,
);
assert!(
!vector.contains("`subscribe`"),
"a vector declaration was offered a word its next compile refuses: {vector}",
);
}