From f8ffab72e2a723baeec3e2816221929cddfd2208 Mon Sep 17 00:00:00 2001 From: Ian Holloway <72767437+IanHollow@users.noreply.github.com> Date: Sun, 18 Oct 2026 06:38:06 -0700 Subject: [PATCH] Tests: keep font-cache misses independent of optional Thai fonts (#1981) Assisted-by: GPT-6 Signed-off-by: IanHollow <72767437+IanHollow@users.noreply.github.com> --- crates/fonts/src/tests_sysfonts.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/fonts/src/tests_sysfonts.rs b/crates/fonts/src/tests_sysfonts.rs index 83013e7b7c..19b36be188 100644 --- a/crates/fonts/src/tests_sysfonts.rs +++ b/crates/fonts/src/tests_sysfonts.rs @@ -162,21 +162,26 @@ fn fallback_lookups_are_remembered_until_fonts_load() { let db = FontDb::with_font_dirs(vec![dir]); db.set_system_fallback(false); let latin = db.face(FALLBACK_FAMILY, "Regular"); - let thai = 'ก'; - assert!(db.fallback_for(thai, latin.id()).is_none(), "no bundled Thai font"); + // A cache-miss fixture must stay absent even when Thai Craft fonts are embedded. + // The coverage-index regression below also uses this supplementary private-use range. + let missing = '\u{F0001}'; + assert!(db.fallback_for(missing, latin.id()).is_none(), "no bundled font covers the cache-miss fixture"); + if crate::CRAFT_FONTS.iter().any(|font| font.scripts.contains(&"Thai")) { + assert!(db.fallback_for('ก', latin.id()).is_some(), "the embedded Thai face supplies its glyph"); + } let a = db.fallback_for('A', latin.id()).unwrap(); assert_eq!(db.fallback_for('A', latin.id()).unwrap().id(), a.id(), "the same answer from the cache"); { let cache = db.fallbacks.read().unwrap(); assert_eq!(cache.faces, db.read_faces().len()); - assert!(cache.map.contains_key(&(thai, latin.id())) && cache.map.contains_key(&('A', latin.id()))); + assert!(cache.map.contains_key(&(missing, latin.id())) && cache.map.contains_key(&('A', latin.id()))); } // Loading fonts (here, the installed family) makes the remembered answers stale. assert_eq!(db.face(FAMILY, "Regular").family, FAMILY); assert_eq!(db.fallback_for('A', latin.id()).unwrap().id(), a.id()); let cache = db.fallbacks.read().unwrap(); assert_eq!(cache.faces, db.read_faces().len()); - assert!(!cache.map.contains_key(&(thai, latin.id())), "entries from before the fonts loaded are dropped"); + assert!(!cache.map.contains_key(&(missing, latin.id())), "entries from before the fonts loaded are dropped"); } #[test] @@ -282,8 +287,12 @@ fn fallback_cache_is_dropped_when_a_face_loads_by_its_legacy_family_name() { let db = FontDb::with_font_dirs(vec![dir]); db.set_system_fallback(false); let latin = db.face(FALLBACK_FAMILY, "Regular"); - let thai = 'ก'; - assert!(db.fallback_for(thai, latin.id()).is_none()); + // Keep the negative cache entry independent of the optional Thai font input. + let missing = '\u{F0001}'; + assert!(db.fallback_for(missing, latin.id()).is_none()); + if crate::CRAFT_FONTS.iter().any(|font| font.scripts.contains(&"Thai")) { + assert!(db.fallback_for('ก', latin.id()).is_some(), "the embedded Thai face supplies its glyph"); + } let before = db.read_faces().len(); let semibold = format!("{FAMILY} Semibold"); let f = db.face(&semibold, "Regular"); @@ -292,7 +301,7 @@ fn fallback_cache_is_dropped_when_a_face_loads_by_its_legacy_family_name() { assert!(db.fallback_for('A', f.id()).is_some_and(|g| g.id() != f.id())); let cache = db.fallbacks.read().unwrap(); assert_eq!(cache.faces, db.read_faces().len()); - assert!(!cache.map.contains_key(&(thai, latin.id())), "answers from before the load are dropped"); + assert!(!cache.map.contains_key(&(missing, latin.id())), "answers from before the load are dropped"); } #[test]