use ingraph_codegen::{model::GraphqlKind, prelude::NodeKind};
use super::skins::dressed;
fn refusals(inside: proc_macro2::TokenStream) -> String {
dressed(inside)
.expect_err("the block is refused")
.into_iter()
.map(|e| e.to_string())
.collect::<Vec<_>>()
.join("\n")
}
#[test]
fn the_base_is_written_prefix_and_fills_the_base_seat_alone() {
let model = dressed(quote::quote! { prefix = "clips" }).expect("`prefix` is the base's word");
let skin = model
.graphql
.as_ref()
.expect("the declaration named a backend")
.skin(GraphqlKind::AsyncGraphql)
.expect("that backend's block");
assert_eq!(
skin.prefix.as_ref().map(syn::LitStr::value).as_deref(),
Some("clips"),
);
assert!(skin.options.is_none(), "the stem filled a face's seat");
assert!(skin.question.is_none(), "the stem filled a face's seat");
assert!(skin.engine.is_none(), "the stem filled a face's seat");
}
#[test]
fn the_old_word_at_the_base_is_refused_with_the_law_and_the_successor() {
let refused = refusals(quote::quote! { rename = "clips" });
assert!(
refused.contains("names ONE thing verbatim and this position re-stems a FAMILY"),
"the sentence carries the law rather than the substitution alone: {refused}",
);
assert!(
refused.contains("no emitted type is called `clips` at all"),
"and the MEASUREMENT the law rests on: {refused}",
);
assert!(
refused.contains("did you mean `prefix`?"),
"and the near-miss family's own clause, which the edit distance could not produce: {refused}",
);
}
#[test]
fn a_face_still_names_its_one_type_with_a_rename_row() {
let model = dressed(quote::quote! {
prefix = "clips",
options(rename = "ClipKnobs"),
})
.expect("the stem and a face's name are one legal block");
let skin = model
.graphql
.as_ref()
.expect("the declaration named a backend")
.skin(GraphqlKind::AsyncGraphql)
.expect("that backend's block");
assert_eq!(
skin.prefix.as_ref().map(syn::LitStr::value).as_deref(),
Some("clips"),
);
assert_eq!(
skin.options.as_ref().map(syn::LitStr::value).as_deref(),
Some("ClipKnobs"),
);
let refused = refusals(quote::quote! { options(prefix = "ClipKnobs") });
assert!(
refused.contains("it takes `rename = \"…\"` and nothing else"),
"{refused}",
);
}
#[test]
fn the_stem_is_held_to_the_wire_alphabet_under_its_new_word() {
let refused = refusals(quote::quote! { prefix = "9lives" });
assert!(refused.contains("is not a GraphQL name"), "{refused}");
}
#[test]
fn the_stem_is_written_once() {
let refused = refusals(quote::quote! { prefix = "a", prefix = "b" });
assert!(
refused.contains("`prefix` is declared more than once"),
"{refused}",
);
}
#[test]
fn the_vocabulary_the_position_offers_is_the_corrected_one() {
let refused = refusals(quote::quote! { prefiix = "clips" });
assert!(refused.contains("unknown entry"), "{refused}");
assert!(
refused.contains("did you mean `prefix`?"),
"the near-miss engine measures against the corrected vocabulary: {refused}",
);
assert!(
refused.contains("`prefix = \"…\"` re-stems the whole SDL family"),
"and the teaching half says what the word does: {refused}",
);
}
#[test]
fn the_top_level_rename_keeps_its_word_and_both_of_its_forms() {
for form in [
quote::quote! { rename = "ShotSearch" },
quote::quote! { rename(fulltext_options = "MyKnobs") },
] {
let (host, arguments) = crate::host::split(&syn::parse_quote! {
#[ingraph(upstream(node = "a::A", body = "text"), dedup(hash), #form)]
struct D { #[ingraph(searchable)] body: String }
});
super::super::index::parse(&host, &arguments, NodeKind::Fulltext)
.unwrap_or_else(|e| panic!("the bones axis keeps `rename`: {e}"));
}
}