use ingraph_codegen::{index::IndexModel, prelude::NodeKind};
use super::tests::refused;
fn blob(head: proc_macro2::TokenStream) -> syn::Result<IndexModel> {
let (host, arguments) = crate::host::split(&syn::parse_quote! {
#[ingraph(upstream(node = "a::A", payload = "pixels"), fs, #head)]
struct Poster { #[ingraph(repeated)] payload: Vec<u8> }
});
super::super::index::parse(&host, &arguments, NodeKind::Blob)
}
#[test]
fn the_slot_word_reaches_the_model_and_the_default_is_absence() {
let named = blob(quote::quote! { slot = "poster_frames" }).expect("a named slot is legal");
assert_eq!(
named.slot.as_ref().map(syn::LitStr::value).as_deref(),
Some("poster_frames"),
);
let plain = blob(quote::quote! { extension = "png" }).expect("legal");
assert!(plain.slot.is_none());
assert_eq!(
named
.stores
.iter()
.map(|engine| engine.word.to_string())
.collect::<Vec<_>>(),
vec!["fs".to_owned()],
);
}
#[test]
fn a_slot_name_the_store_could_not_hold_is_refused_where_it_was_written() {
for written in ["", "9frames", "poster frames", "poster-frames"] {
let head = {
let name = syn::LitStr::new(written, proc_macro2::Span::call_site());
quote::quote! { slot = #name }
};
let e = blob(head)
.expect_err("a malformed slot name is refused")
.into_iter()
.map(|e| e.to_string())
.collect::<Vec<_>>()
.join("\n");
assert!(e.contains("is not a slot name"), "`{written}`: {e}");
}
}
#[test]
fn one_family_lives_in_one_place() {
let e = blob(quote::quote! { slot = "a", slot = "b" })
.expect_err("a second slot is refused")
.into_iter()
.map(|e| e.to_string())
.collect::<Vec<_>>()
.join("\n");
assert!(e.contains("declared more than once"), "{e}");
assert!(e.contains("ONE place"), "{e}");
}
#[test]
fn the_retrieving_kinds_are_told_the_grain_rather_than_offered_the_word() {
for kind in [NodeKind::Fulltext, NodeKind::Vector] {
let e = refused(
syn::parse_quote! {
#[ingraph(upstream(node = "a::A", body = "text"), dedup(hash), slot = "corpus")]
struct D { #[ingraph(searchable)] body: String }
},
kind,
);
assert!(e.contains("owns one per `(field × engine)` PAIRING"), "{e}");
assert!(
e.contains("__"),
"and the join that keeps two pairings apart: {e}",
);
}
}
#[test]
fn the_three_verdicts_of_the_naming_round_stand_together_on_this_kind() {
assert!(blob(quote::quote! { slot = "poster_frames" }).is_ok());
let renamed = blob(quote::quote! { rename = "Poster" })
.expect_err("this kind mints no type")
.to_string();
assert!(renamed.contains("lands no type in your scope"), "{renamed}");
assert!(
renamed.contains("slot = \"…\""),
"and it points at the word this kind DOES have: {renamed}",
);
let dressed = blob(quote::quote! { graphql(async_graphql) })
.expect_err("this kind mints no wire type")
.to_string();
assert!(
dressed.contains("mints no wire type of its own"),
"{dressed}"
);
}