use ingraph_codegen::{index::IndexModel, prelude::*};
use crate::host;
fn blob() -> IndexModel {
let (host, arguments) = host::split(&syn::parse_quote! {
#[ingraph(upstream(node = "app::Frame", payload = "pixels"), fs, extension = "png")]
struct Poster { #[ingraph(repeated)] payload: Vec<u8> }
});
crate::index::parse(&host, &arguments, NodeKind::Blob).expect("a family on the shipped store")
}
fn record() -> RecordModel {
let (host, options) = host::split(&syn::parse_quote! {
#[ingraph(sqlite,
lineage(fields(media)),
graphql(async_graphql),
locate(bare = "app::Bare", signed(family = "app::Signed", required)),
)]
struct Frame { #[ingraph(id)] at: i64, media: String }
});
crate::parse::parse(&host, &options, NodeKind::Record).expect("two positions, one word apart")
}
fn emitted(tokens: proc_macro2::TokenStream) -> String {
tokens.to_string()
}
#[test]
fn the_shipped_family_answers_an_option_and_renders_without_looking() {
let emission = emitted(blob().emit());
assert!(
emission
.contains("core :: result :: Result < :: core :: option :: Option < Self :: Location >"),
"{emission}"
);
assert!(
!emission.contains("try_exists"),
"the family stats on a caller's behalf: {emission}"
);
assert!(
emission.contains(":: core :: option :: Option :: Some (:: ingraph"),
"{emission}"
);
}
#[test]
fn the_address_render_is_the_whole_body() {
let emission = emitted(blob().emit());
let render = emission
.find("blob_address")
.expect("the address is rendered");
let answer = emission[render..]
.find(":: core :: option :: Option :: Some")
.expect("and handed back");
let between = &emission[render..render + answer];
assert!(!between.contains("if "), "{emission}");
assert!(!between.contains("try_exists"), "{emission}");
}
#[test]
fn a_bare_position_publishes_what_the_family_answered() {
let emission = emitted(record().emit());
assert!(emission.contains("locate_artifact"), "{emission}");
assert!(
emission.contains("Result < :: core :: option :: Option << app :: Bare as"),
"{emission}"
);
assert!(
!emission.contains(":: core :: option :: Option :: Some ,"),
"the emission mints no `Option` of its own any more: {emission}"
);
}
#[test]
fn a_signed_position_takes_the_signed_walk() {
let emission = emitted(record().emit());
assert!(emission.contains("locate_signed_artifact"), "{emission}");
assert!(
emission.contains("Result << app :: Signed as"),
"{emission}"
);
}