use ingraph_codegen::catalog::ResourceSource;
use super::tests::{accepted, refused};
#[test]
fn the_goodbye_composes_with_every_source_spelling() {
let model = accepted(quote::quote! {
pub struct App {
videos: media::Video,
#[ingraph(resource(teardown))]
egemma: models::Egemma,
#[ingraph(resource(factory, teardown))]
pool: Pool,
#[ingraph(resource(factory = "boot::cache", teardown))]
cache: Cache,
}
});
assert_eq!(model.resources.len(), 3);
assert_eq!(model.resources[0].source, ResourceSource::Section);
assert_eq!(model.resources[1].source, ResourceSource::Prepare);
assert!(matches!(
model.resources[2].source,
ResourceSource::Initializer(_)
));
assert!(
model.resources.iter().all(|field| field.teardown),
"the axis is orthogonal to the source: every one of them said it"
);
}
#[test]
fn the_goodbye_reads_the_same_written_first() {
let model = accepted(quote::quote! {
pub struct App {
videos: media::Video,
#[ingraph(resource(teardown, factory = "boot::cache"))]
cache: Cache,
}
});
assert!(matches!(
model.resources[0].source,
ResourceSource::Initializer(_)
));
assert!(model.resources[0].teardown);
}
#[test]
fn a_resource_without_the_word_carries_no_goodbye() {
let model = accepted(quote::quote! {
pub struct App {
videos: media::Video,
#[ingraph(resource)]
egemma: models::Egemma,
#[ingraph(resource(factory))]
pool: Pool,
}
});
assert!(model.resources.iter().all(|field| !field.teardown));
}
#[test]
fn the_goodbye_takes_no_value() {
let refusal = refused(quote::quote! {
pub struct App {
videos: media::Video,
#[ingraph(resource(teardown = "shut_down"))]
egemma: models::Egemma,
}
});
assert!(refusal.contains("`teardown` is a bare word"), "{refusal}");
}
#[test]
fn the_goodbye_is_refused_where_it_is_written_twice() {
let refusal = refused(quote::quote! {
pub struct App {
videos: media::Video,
#[ingraph(resource(teardown, teardown))]
egemma: models::Egemma,
}
});
assert!(
refusal.contains("`teardown` is declared more than once on one resource"),
"{refusal}"
);
}
#[test]
fn a_teardown_outside_the_resource_word_is_an_orphan_attribute() {
let refusal = refused(quote::quote! {
pub struct App {
#[ingraph(teardown)]
videos: media::Video,
}
});
assert!(
refusal.contains("unknown entry in `#[ingraph(…)]` on a graph root's field"),
"{refusal}"
);
assert!(
refusal.contains("a `teardown` composed with any of them"),
"and the sentence names the spellings that exist: {refusal}"
);
}