use super::window;
use crate::keymap::{CenterTab, InspectorTab};
use crate::paint_probe::seen_of;
const KNOWN: [(&str, &str); 0] = [];
const WRAPPED: f32 = 40.0;
fn silent_cuts(
w: f32,
h: f32,
trail: bool,
tab: CenterTab,
inspector: InspectorTab,
) -> Vec<String> {
seen_of(&window(w, h, trail, tab, inspector))
.into_iter()
.filter(|seen| seen.shown.width() < seen.laid.width() - 1.0)
.map(|seen| {
format!(
"{:?} laid {:.0} pt, {:.0} pt shown — at {w}x{h} \
(trail {trail}, {tab:?}, {inspector:?})",
seen.text,
seen.laid.width(),
seen.shown.width()
)
})
.filter(|cut| !KNOWN.iter().any(|(needle, _)| cut.contains(needle)))
.collect()
}
fn assert_all_filed(report: &[String]) {
let excused: Vec<String> = KNOWN
.iter()
.map(|(needle, ball)| format!(" {needle:?} — {ball}"))
.collect();
assert!(
report.is_empty(),
"runs cut with no ellipsis, on no filed ball:\n{}\n\nalready filed:\n{}",
report.join("\n"),
if excused.is_empty() {
" (nothing — the list is empty and must stay that way)".to_owned()
} else {
excused.join("\n")
}
);
}
#[test]
fn nothing_is_cut_without_an_ellipsis_at_any_window_size() {
let mut report = Vec::new();
for (w, h) in super::SIZES {
for trail in [false, true] {
for tab in [
CenterTab::Conversation,
CenterTab::Config,
CenterTab::Login,
CenterTab::Search,
] {
report.extend(silent_cuts(w, h, trail, tab, InspectorTab::Transcript));
}
}
}
assert_all_filed(&report);
}
#[test]
fn nothing_is_cut_without_an_ellipsis_on_any_inspector_tab() {
let mut report = Vec::new();
for (w, h) in super::SIZES {
for inspector in InspectorTab::all() {
report.extend(silent_cuts(w, h, false, CenterTab::Conversation, inspector));
}
}
assert_all_filed(&report);
}
#[test]
fn the_inspector_strip_shows_all_of_its_peers_or_none_of_them() {
let want: Vec<&str> = InspectorTab::all().iter().map(|t| t.label()).collect();
let mut ever = false;
for (w, h) in super::SIZES {
let out = window(
w,
h,
false,
CenterTab::Conversation,
InspectorTab::Transcript,
);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(w, h));
let painted = seen_of(&out);
let Some(head) = painted.iter().find(|seen| seen.text == "Transcript") else {
continue;
};
ever = true;
let band = head.laid.top() - 1.0..=head.laid.bottom() + WRAPPED;
for label in &want {
let seat = painted
.iter()
.find(|seen| &seen.text == label && band.contains(&seen.laid.top()))
.unwrap_or_else(|| {
panic!(
"the strip is up at {w}x{h} but `{label}` is not on it: {:?}",
painted
.iter()
.filter(|s| band.contains(&s.laid.top()))
.map(|s| &s.text)
.collect::<Vec<_>>()
)
});
assert!(
seat.shown.width() >= seat.laid.width() - 1.0,
"the `{label}` tab is cut at {w}x{h}: {} pt of {} pt shown",
seat.shown.width(),
seat.laid.width()
);
assert!(
screen.contains_rect(seat.laid),
"the `{label}` tab is laid off the window at {w}x{h}: {:?}",
seat.laid
);
}
}
assert!(
ever,
"no window size painted the inspector strip at all — the property above \
would have held vacuously"
);
}
#[test]
fn the_walk_reports_a_run_its_seat_really_does_slice() {
let ctx = egui::Context::default();
let out = ctx.run(crate::paint_probe::screen_sized(120.0, 200.0), |ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label("a run far wider than the hundred points it was given");
});
});
});
let cut: Vec<_> = seen_of(&out)
.into_iter()
.filter(|seen| seen.shown.width() < seen.laid.width() - 1.0)
.collect();
assert!(
cut.iter().any(|seen| seen.text.starts_with("a run far")
&& !seen.text.ends_with('…')
&& seen.shown.width() < 130.0),
"a run sliced by its seat, with no ellipsis to say so, must be reported: {:?}",
cut.iter().map(|s| &s.text).collect::<Vec<_>>()
);
}
mod floor;