use super::{
IndexModel,
answers::{fanned, plain},
};
use crate::prefix::EmissionPrefix;
fn tight(model: &IndexModel) -> String {
model.emit().to_string().split_whitespace().collect()
}
fn inside(model: &IndexModel, gate: &str) -> String {
fn walk(stream: proc_macro2::TokenStream, gate: &str, into: &mut String) {
let mut named = false;
for tree in stream {
match tree {
proc_macro2::TokenTree::Ident(ident) => named = ident == gate,
proc_macro2::TokenTree::Group(group) => {
if named {
into.push_str(
&group
.stream()
.to_string()
.split_whitespace()
.collect::<String>(),
);
named = false;
} else {
walk(group.stream(), gate, into);
}
}
_ => {}
}
}
}
let mut held = String::new();
walk(model.emit(), gate, &mut held);
held
}
fn document() -> IndexModel {
IndexModel {
prefix: EmissionPrefix::default(),
kind: crate::model::NodeKind::Fulltext,
embeddings: Vec::new(),
searchable: vec![syn::Ident::new("body", proc_macro2::Span::call_site())],
..plain()
}
}
#[test]
fn the_hydrated_pair_drops_the_tier_noun() {
let emitted = tight(&plain());
for name in [
r#"#[graphql(name="shotsByClipKeys")]"#,
r#"#[graphql(name="shotsByClip")]"#,
r#"#[graphql(name="shotsSimilarByClipKeys")]"#,
r#"#[graphql(name="shotsSimilarByClip")]"#,
] {
assert!(emitted.contains(name), "{name} is missing: {emitted}");
}
}
#[test]
fn the_hydrated_legs_ride_the_family_gate() {
let open = inside(&plain(), "if_sqlx");
assert!(open.contains(r#"#[graphql(name="shotsByClip")]"#), "{open}");
assert!(
open.contains(r#"#[graphql(name="shotsSimilarByClip")]"#),
"{open}"
);
assert!(
open.contains(
"type__INGRAPH_ANSWER_DB__=<Keyframeas::ingraph::__private::transform::Hydrates>::Db;"
),
"{open}",
);
assert!(open.contains("type__INGRAPH_ANSWER_ROW__="), "{open}");
assert!(open.contains("type__INGRAPH_ANSWER_ENTITY__="), "{open}");
}
#[test]
fn the_shut_half_is_the_unit_without_the_store() {
let shut = inside(&plain(), "if_no_sqlx");
assert!(
shut.contains(r#"#[graphql(name="shotsByClipKeys")]"#),
"{shut}"
);
assert!(
shut.contains(r#"#[graphql(name="shotsSimilarByClipKeys")]"#),
"{shut}"
);
assert!(
!shut.contains(r#"#[graphql(name="shotsByClip")]"#),
"a hydrated field reached the family-less half: {shut}",
);
for named in [
"SqlDoor",
"SqlPooledGather",
"Hydrates",
"__INGRAPH_ANSWER_DB__",
] {
assert!(
!shut.contains(named),
"`{named}` reached the family-less half: {shut}",
);
}
}
#[test]
fn the_door_is_keyed_on_the_upstream_projection() {
let emitted = tight(&plain());
assert!(
emitted.contains(
"::ingraph::__private::graphql::SqlDoor<__INGRAPH_ANSWER_DB__>>(__async_graphql_ctx)?"
),
"{emitted}",
);
assert!(
emitted.contains(
"::ingraph::__private::retrieve::SqlPooledGather::<__INGRAPH_ANSWER_ROW__,\
__INGRAPH_ANSWER_DB__>::new"
),
"{emitted}",
);
assert!(
emitted.contains(
"type__INGRAPH_ANSWER_ROW__=<Keyframeas::ingraph::__private::transform::Record<\
__INGRAPH_ANSWER_DB__>>::Row;"
),
"{emitted}",
);
}
#[test]
fn a_fanned_election_mounts_no_hydrated_leg() {
let emitted = tight(&fanned());
assert!(!emitted.contains("Hydrates"), "{emitted}");
assert!(!emitted.contains("__INGRAPH_ANSWER_DB__"), "{emitted}");
assert!(!emitted.contains("SqlPooledGather"), "{emitted}");
assert!(!emitted.contains("if_no_sqlx"), "{emitted}");
}
#[test]
fn a_full_text_declaration_mints_no_gate_pair() {
let emitted = tight(&document());
assert!(!emitted.contains("if_no_sqlx"), "{emitted}");
assert!(!emitted.contains("Hydrates"), "{emitted}");
}
#[test]
fn the_hydrated_answer_is_the_frameworks_own_entity_hit() {
let emitted = tight(&plain());
assert!(
emitted.contains("::ingraph::__private::graphql::Match<__INGRAPH_ANSWER_ENTITY__,"),
"{emitted}",
);
let file: syn::File = syn::parse2(plain().emit()).expect("the emission parses");
let landed: Vec<String> = file
.items
.into_iter()
.filter_map(|item| match item {
syn::Item::Struct(declared) => Some(declared.ident.to_string()),
syn::Item::Enum(declared) => Some(declared.ident.to_string()),
_ => None,
})
.collect();
assert!(
!landed.iter().any(|name| name.contains("Entity")),
"the hydrated tier minted a shape of its own: {landed:?}",
);
}
#[test]
fn the_hydrated_tier_adds_nothing_to_the_roster() {
for name in plain()
.emitted_types()
.iter()
.map(|declared| declared.name.to_string())
{
assert!(
!name.contains("Entity") && !name.contains("Hydrat"),
"the hydrated tier put a name in the declaring scope: {name}",
);
}
}