mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-03 08:50:02 -06:00
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>
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user