use super::fixture::world_empty;
use crate::cli_outbound::Cli;
use crate::paint_probe::{Seen, seen_of};
const ONE_AXIS: f32 = 2.0;
fn masthead(w: f32, h: f32) -> Vec<Seen> {
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();
}
seen_of(&frame())
}
fn stack(painted: &[Seen], w: f32, h: f32) -> [Seen; 3] {
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<_>>()
)
})
.clone()
};
[
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 ")
}),
]
}
#[test]
fn the_empty_worlds_masthead_stacks_three_whole_runs_in_order() {
for (w, h) in super::SIZES {
let painted = masthead(w, h);
let stack = stack(&painted, w, h);
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()
);
}
}
}
#[test]
fn the_masthead_is_centred_on_one_axis_and_the_prediction_is_set_apart() {
for (w, h) in super::SIZES {
let painted = masthead(w, h);
let [word, tagline, prediction] = stack(&painted, w, h);
let lockup = word.laid.center().x - crate::theme::WORDMARK_LEAD / 2.0;
for seen in [&tagline, &prediction] {
assert!(
(lockup - seen.laid.center().x).abs() <= ONE_AXIS,
"the masthead splits across two axes at {w}x{h}: the wordmark lockup \
centres at x {lockup} while `{}` centres at x {}",
seen.text,
seen.laid.center().x
);
}
let apart = prediction.laid.top() - tagline.laid.bottom();
assert!(
apart >= super::super::bootstrap::SAID_APART,
"`{}` runs straight on from the tagline at {w}x{h}: {apart} pt between them",
prediction.text
);
}
}