mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-30 13:08:07 -06:00
tests: match retained font faces and primary-style precedence
This commit is contained in:
@@ -928,13 +928,14 @@ fn fonts_lists_bundled_and_installed_families() {
|
||||
let r = s.execute("text.fonts", json!({"query": "noto ser", "rescan": true})).unwrap();
|
||||
assert_eq!(r["families"][0]["family"], "Noto Serif");
|
||||
// The bundled face is Regular; the OS can also provide Bold, Italic, or other faces.
|
||||
// Compare against the independent directory inventory rather than assuming an empty OS.
|
||||
// Compare against the faces the font database retained after the rescan: a system face
|
||||
// whose family and primary style duplicate a bundled one is skipped.
|
||||
let mut expected_styles = std::collections::BTreeSet::from(["Regular".to_string()]);
|
||||
expected_styles.extend(
|
||||
installed
|
||||
effectcraft_text::fonts::all_faces()
|
||||
.iter()
|
||||
.filter(|face| face.family.eq_ignore_ascii_case("Noto Serif"))
|
||||
.flat_map(|face| std::iter::once(face.style.clone()).chain(face.instances.iter().map(|i| i.style.clone()))),
|
||||
.filter(|face| face.info.family.eq_ignore_ascii_case("Noto Serif"))
|
||||
.flat_map(|face| std::iter::once(face.info.style.clone()).chain(face.info.instances.iter().map(|i| i.style.clone()))),
|
||||
);
|
||||
let styles: Vec<String> = r["families"][0]["styles"].as_array().unwrap().iter().map(|style| style.as_str().unwrap().to_string()).collect();
|
||||
assert_eq!(styles.iter().cloned().collect::<std::collections::BTreeSet<_>>(), expected_styles);
|
||||
|
||||
@@ -104,7 +104,8 @@ fn bundled_families_and_resolution() {
|
||||
let candidates: Vec<_> = faces.iter().filter(|f| f.info.family.eq_ignore_ascii_case(family)).collect();
|
||||
let exact = candidates
|
||||
.iter()
|
||||
.find(|f| f.info.style.eq_ignore_ascii_case("Bold Italic") || f.info.instances.iter().any(|i| i.style.eq_ignore_ascii_case("Bold Italic")));
|
||||
.find(|f| f.info.style.eq_ignore_ascii_case("Bold Italic"))
|
||||
.or_else(|| candidates.iter().find(|f| f.info.instances.iter().any(|i| i.style.eq_ignore_ascii_case("Bold Italic"))));
|
||||
if let Some(exact) = exact {
|
||||
assert_eq!(resolved.face, exact.id, "real style wins for {family}");
|
||||
assert!(!resolved.synth_bold && !resolved.synth_italic);
|
||||
|
||||
Reference in New Issue
Block a user