use super::{
ElectionBackend, FieldNumbers, IndexBackend, IndexGraphql, IndexModel, IndexRename, Numbers,
answers::{fanned, plain},
};
use crate::{model::GraphqlKind, prefix::EmissionPrefix};
fn ident(name: &str) -> syn::Ident {
syn::Ident::new(name, proc_macro2::Span::call_site())
}
fn word(spelled: &str) -> syn::LitStr {
syn::LitStr::new(spelled, proc_macro2::Span::call_site())
}
fn tight(model: &IndexModel) -> String {
model.emit().to_string().split_whitespace().collect()
}
fn dressed(model: IndexModel, skin: ElectionBackend) -> IndexModel {
IndexModel {
prefix: EmissionPrefix::default(),
field_numbers: vec![FieldNumbers {
field: ident("clip"),
numbers: Numbers::default(),
skins: vec![skin],
}],
..model
}
}
fn sighting(spelled: &str) -> ElectionBackend {
let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
skin.sighting = Some(word(spelled));
skin
}
fn fused_key_match(spelled: &str) -> ElectionBackend {
let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
skin.fused_key_match = Some(word(spelled));
skin
}
#[test]
fn the_sighting_seat_moves_the_union_and_never_its_arms() {
let emitted = tight(&dressed(fanned(), sighting("ClipAgreement")));
assert!(
emitted.contains(r#""ClipAgreement""#),
"the seat did not reach the published name: {emitted}",
);
assert!(
!emitted.contains(r#""ShotsClipSighting""#),
"the derived union name survived the rename: {emitted}",
);
assert!(
emitted.contains("enumShotsClipSighting{"),
"the schema word moved the RUST declaration: {emitted}",
);
for arm in ["ShotsClipDeepSighting", "ShotsClipShallowSighting"] {
assert!(
emitted.contains(&format!(r#""{arm}""#)),
"the union's word moved `{arm}` with it: {emitted}",
);
}
}
#[test]
fn the_fused_key_match_seat_moves_the_row_and_leaves_the_union() {
let emitted = tight(&dressed(fanned(), fused_key_match("ClipLeader")));
assert!(
emitted.contains(r#""ClipLeader""#),
"the seat did not reach the published name: {emitted}",
);
assert!(
!emitted.contains(r#""ShotsClipFusedKeyMatch""#),
"the derived row name survived the rename: {emitted}",
);
assert!(
emitted.contains("structShotsClipFusedKeyMatch{"),
"the schema word moved the RUST declaration: {emitted}",
);
assert!(
emitted.contains(r#""ShotsClipSighting""#),
"the row's word moved the union with it: {emitted}",
);
}
#[test]
fn the_two_answer_seats_fill_independently() {
let mut skin = sighting("ClipAgreement");
skin.fused_key_match = Some(word("ClipLeader"));
let emitted = tight(&dressed(fanned(), skin));
assert!(emitted.contains(r#""ClipAgreement""#), "{emitted}");
assert!(emitted.contains(r#""ClipLeader""#), "{emitted}");
assert!(!emitted.contains(r#""ShotsClipSighting""#), "{emitted}");
assert!(
!emitted.contains(r#""ShotsClipFusedKeyMatch""#),
"{emitted}"
);
}
#[test]
fn a_renamed_answer_still_carries_the_frameworks_own_rows() {
let mut skin = sighting("ClipAgreement");
skin.fused_key_match = Some(word("ClipLeader"));
let emitted = tight(&dressed(fanned(), skin));
for row in ["node", "score", "evidence", "ordinal", "contribution"] {
assert!(
emitted.contains(&format!(r#"#[graphql(name="{row}")]"#)),
"the floor row `{row}` is not published: {emitted}",
);
}
assert!(
!emitted.contains(r#"#[graphql(name="key")]"#),
"the retired address spelling reached a fused answer: {emitted}",
);
}
#[test]
fn an_answer_seat_wins_over_the_skin_base_which_takes_the_other_half() {
let mut head = IndexBackend::of(GraphqlKind::AsyncGraphql);
head.prefix = Some(word("Reels"));
let model = IndexModel {
prefix: EmissionPrefix::default(),
graphql: Some(IndexGraphql {
backends: vec![head],
}),
..dressed(fanned(), sighting("ClipAgreement"))
};
let emitted = tight(&model);
assert!(
emitted.contains(r#""ClipAgreement""#),
"the MEMBER lost to the base: {emitted}",
);
assert!(
emitted.contains(r#""ReelsClipFusedKeyMatch""#),
"the BASE did not reach the half the member left it: {emitted}",
);
assert!(
!emitted.contains(r#""ShotsClipFusedKeyMatch""#),
"a face kept the DEFAULT although a base was written: {emitted}",
);
}
#[test]
fn an_answer_seat_and_the_bones_rename_move_two_different_things() {
let model = IndexModel {
prefix: EmissionPrefix::default(),
rename: Some(IndexRename::Base(ident("ShotSearch"))),
..dressed(fanned(), sighting("ClipAgreement"))
};
let emitted = tight(&model);
assert!(
emitted.contains("enumShotSearchClipSighting{"),
"the BONES rename did not move the Rust declaration: {emitted}",
);
assert!(
emitted.contains(r#""ClipAgreement""#),
"the SKIN seat did not survive the bones rename: {emitted}",
);
}
#[test]
fn the_answer_seats_are_unspent_on_a_road_that_publishes_no_fused_answer() {
let mut skin = sighting("ClipAgreement");
skin.fused_key_match = Some(word("ClipLeader"));
let dressed_up = tight(&dressed(plain(), skin));
let bare = tight(&dressed(
plain(),
ElectionBackend::of(GraphqlKind::AsyncGraphql),
));
assert_eq!(dressed_up, bare, "an unspent word reached the expansion");
for absent in ["ClipAgreement", "ClipLeader"] {
assert!(
!dressed_up.contains(absent),
"`{absent}` landed on a road with no fused answer: {dressed_up}",
);
}
}