Tests: Show Similar Fonts' limit check tolerates fonts that other tests add

Other tests add and remove composite fonts in the shared font database,
which can change the list between the two text.similarFonts calls. The
limited answer is compared whole with the first families of the full one
when FontDb::generation is the same before and after both calls, and by
the installed families when the fonts changed during each of 20 tries.
This commit is contained in:
dotCooCoo
2026-11-15 16:36:58 -08:00
parent c26c1f3efd
commit 669d98fab1
+22 -2
View File
@@ -51,8 +51,28 @@ fn similar_fonts_lists_every_family_by_likeness() {
// Other tests running at the same time add and remove composite fonts; the installed families are compared.
let installed_only = |list: &[String]| list.iter().filter(|f| db.has_installed_family(f)).cloned().collect::<Vec<_>>();
assert_eq!(installed_only(&sorted), installed_only(&listed), "every family once");
let two = s.execute("text.similarFonts", &json!({"family": "Source Sans 3", "limit": 2})).unwrap();
assert_eq!(names(&two["families"]), order[..2]);
// The two answers are compared whole when the available fonts did not change while both were
// made (the same `FontDb::generation`), and by their installed families when they changed
// during every try.
let mut answers = (vec![], vec![], false);
for _ in 0..20 {
let generation = db.generation();
let all = names(&s.execute("text.similarFonts", &json!({"family": "Source Sans 3"})).unwrap()["families"]);
let two = names(&s.execute("text.similarFonts", &json!({"family": "Source Sans 3", "limit": 2})).unwrap()["families"]);
let unchanged = db.generation() == generation;
answers = (all, two, unchanged);
if unchanged {
break;
}
}
let (all, two, unchanged) = answers;
assert_eq!(two.len(), 2);
if unchanged {
assert_eq!(two, all[..2], "the first families, in order");
} else {
let (two, all) = (installed_only(&two), installed_only(&all));
assert_eq!(two[..], all[..two.len()], "the first installed families, in order");
}
for (params, error) in [
(json!({}), "`family` is required"),
(json!({"family": " "}), "`family` is required"),