From 669d98fab14b86fe4484c23cfb04da147757c89c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 16:36:58 -0800 Subject: [PATCH] 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. --- crates/engine/src/tests/fontlist.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests/fontlist.rs b/crates/engine/src/tests/fontlist.rs index 4a17bf734a..f7bf95b514 100644 --- a/crates/engine/src/tests/fontlist.rs +++ b/crates/engine/src/tests/fontlist.rs @@ -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::>(); 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"),