use crate::{
catalog::{ResourceField, ResourceSource},
graph::GraphModel,
};
use super::tests::{app, compact, rendered};
fn resourced() -> GraphModel {
GraphModel {
interfaces: Vec::new(),
resources: vec![
ResourceField {
mount: syn::parse_quote!(egemma),
ty: syn::parse_quote!(models::Egemma),
source: ResourceSource::Section,
teardown: false,
},
ResourceField {
mount: syn::parse_quote!(index),
ty: syn::parse_quote!(Index),
source: ResourceSource::Initializer(syn::parse_quote!(boot::index)),
teardown: true,
},
],
..app()
}
}
#[test]
fn the_teardown_word_names_the_enrolling_door_and_nothing_else_moves() {
let model = resourced();
let emitted = compact(&model);
assert!(
emitted.contains("Creation::declared_resource::<models::Egemma,"),
"the silent resource keeps the door it had: {}",
rendered(&model)
);
assert!(
emitted.contains("Creation::declared_resource_saying_goodbye::<Index,"),
"and the worded one is enrolled: {}",
rendered(&model)
);
assert!(
!emitted.contains("Creation::declared_resource::<Index,"),
"one door per resource, never both: {}",
rendered(&model)
);
}
#[test]
fn a_root_with_no_worded_resource_names_the_enrolling_door_nowhere() {
let model = GraphModel {
interfaces: Vec::new(),
resources: vec![ResourceField {
mount: syn::parse_quote!(egemma),
ty: syn::parse_quote!(models::Egemma),
source: ResourceSource::Section,
teardown: false,
}],
..app()
};
assert!(
!compact(&model).contains("declared_resource_saying_goodbye"),
"{}",
rendered(&model)
);
}
#[test]
fn the_node_bag_is_declared_empty_and_assigned_slot_by_slot() {
let model = app();
let emitted = compact(&model);
assert!(
emitted.contains("letmut__ingraph_nodes=AppNodes{videos:::core::option::Option::None,"),
"{}",
rendered(&model)
);
assert!(
emitted.contains("__ingraph_nodes.videos=::ingraph::__private::drive::Creation::node::"),
"{}",
rendered(&model)
);
}
#[test]
fn each_phase_hands_its_refusal_to_its_own_walks_unwind() {
let model = app();
let emitted = compact(&model);
assert!(
emitted.contains("let__ingraph_created=async{"),
"the create phase is one block: {}",
rendered(&model)
);
assert!(
emitted.contains("Creation::unwind(__ingraph_creation,{"),
"whose refusal reaches the create walk's unwind: {}",
rendered(&model)
);
assert!(
emitted.contains("let__ingraph_connected=(||->::core::result::Result<(),"),
"the wiring phase is the other: {}",
rendered(&model)
);
assert!(
emitted.contains("Wiring::unwind(__ingraph_wiring,{"),
"whose refusal reaches the wiring walk's: {}",
rendered(&model)
);
}
#[test]
fn the_per_mount_holders_are_declared_ahead_of_the_wiring_walk() {
let model = app();
let emitted = compact(&model);
for mount in ["videos", "scenes", "search"] {
assert!(
emitted.contains(&format!(
"letmut__ingraph_body_{mount}=::core::option::Option::None;\
letmut__ingraph_feed_{mount}=::core::option::Option::None;"
)),
"{}",
rendered(&model)
);
}
let holders = emitted
.find("letmut__ingraph_body_videos")
.expect("the holders are emitted");
let walk = emitted
.find("let__ingraph_connected")
.expect("the wiring phase is emitted");
assert!(holders < walk, "{}", rendered(&model));
}
#[test]
fn the_wiring_ledger_stages_through_the_mount_cell_and_falls_back_to_the_bag() {
let model = app();
let emitted = compact(&model);
assert!(
emitted.contains(
"as::ingraph::__private::drive::Mount<media::Video,>>::stage(&mut__ingraph_staged,\"videos\",\
__ingraph_body);"
),
"{}",
rendered(&model)
);
assert!(
emitted.contains(
"::core::option::Option::None=>{iflet::core::option::Option::Some(__ingraph_value)=\
AppNodes::take_videos(&mut__ingraph_nodes,)"
),
"and the mount the wiring never reached falls back to the bag: {}",
rendered(&model)
);
}