Files
reqlite/crates/app/tests/glyphs.rs
T

45 lines
1.7 KiB
Rust

//! Every non-ASCII character in the UI code must be drawable with the
//! bundled fonts (a missing glyph panics in debug builds).
#[test]
fn ui_symbols_exist_in_the_bundled_fonts() {
let mut harness = egui_kittest::Harness::new_ui(|_ui| {});
harness.step();
let ctx = harness.ctx.clone();
let src_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
// `update` builds some labels too (dialog lists, status messages).
let files = std::fs::read_dir(src_dir.join("ui"))
.unwrap()
.map(|e| e.unwrap().path())
.chain([
src_dir.join("action.rs"),
src_dir.join("state.rs"),
src_dir.join("strings.rs"),
]);
let mut missing = Vec::new();
for path in files {
let src = std::fs::read_to_string(&path).unwrap();
for (n, line) in src.lines().enumerate() {
// Only string literals in code matter, not comments.
if line.trim_start().starts_with("//") {
continue;
}
for c in line.chars().filter(|c| !c.is_ascii()) {
for family in [egui::FontFamily::Proportional, egui::FontFamily::Monospace] {
let ok = ctx.fonts_mut(|f| f.has_glyph(&egui::FontId::new(14.0, family.clone()), c));
if !ok {
missing.push(format!(
"{c:?} (U+{:04X}) {family:?} at {}:{}",
c as u32,
path.display(),
n + 1
));
}
}
}
}
}
missing.dedup();
assert!(missing.is_empty(), "missing glyphs:\n{}", missing.join("\n"));
}