use super::fixture::world_empty;
use crate::cli_outbound::Cli;
use crate::paint_probe::seen_of;
#[test]
fn the_empty_worlds_masthead_stacks_three_whole_runs_in_order() {
for (w, h) in super::SIZES {
let (lernie, bl, bz) = (Cli::new("lernie"), Cli::new("bl"), Cli::new("bz"));
let mut world = world_empty();
let ctx = egui::Context::default();
let mut frame = || {
ctx.run(crate::paint_probe::screen_sized(w, h), |ctx| {
super::super::render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
})
};
for _ in 0..3 {
let _ = frame();
}
let painted = seen_of(&frame());
let line = |what: &str, hit: &dyn Fn(&str) -> bool| {
painted
.iter()
.find(|seen| hit(&seen.text))
.unwrap_or_else(|| {
panic!(
"{what} is not on the empty world's masthead at {w}x{h}: {:?}",
painted.iter().map(|s| &s.text).collect::<Vec<_>>()
)
})
};
let stack = [
line("the wordmark", &|text: &str| text == "yog"),
line("the tagline", &|text: &str| text == crate::theme::TAGLINE),
line("the name prediction", &|text: &str| {
text.starts_with("will be named ")
}),
];
for seen in stack {
assert!(
seen.shown.width() >= seen.laid.width() - 1.0,
"the masthead's `{}` is cut at {w}x{h}: {} pt of {} pt shown",
seen.text,
seen.shown.width(),
seen.laid.width()
);
}
for pair in stack.windows(2) {
assert!(
pair[1].laid.top() >= pair[0].laid.bottom() - 1.0,
"the masthead is out of order at {w}x{h}: `{}` at y {} is not below \
`{}` ending at y {}",
pair[1].text,
pair[1].laid.top(),
pair[0].text,
pair[0].laid.bottom()
);
}
}
}