mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 20:43:18 -05:00
Tests: the Stylistic Sets submenu test reads the sets from the face
The test reads the expected ss01 to ss20 sets from the text's face, compares them with the panel's entries and with the submenu's toggle rows in order, and checks that the submenu is left out when the face offers no sets. Before, a face whose sets the panel dropped returned early and skipped every submenu assertion.
This commit is contained in:
1 parent
1dbbf87436
commit
7407da03c8
1 file changed
+30
@@ -857,6 +857,36 @@ mod tests {
|
||||
let sets = set_entries(&app, &st);
|
||||
// With the bundled fonts, the text's face offers sets. Without them, an installed face may.
|
||||
assert!(!cfg!(feature = "bundled-fonts") || !sets.is_empty(), "the bundled face of the text offers stylistic sets");
|
||||
// The submenu lists the `ss01` to `ss20` sets that the text's face offers, read here from
|
||||
// the face itself, so the test returns early only when the face offers none.
|
||||
let db = FontDb::global();
|
||||
let available = db.has_family(&db.canonical(&st.font_family, &st.font_style).0);
|
||||
let face_sets = if available { db.style_face(&st).map(|face| face.stylistic_sets()).unwrap_or_default() } else { Vec::new() };
|
||||
let expected: Vec<String> = face_sets.iter().filter(|set| (1..=20).contains(&set.number)).map(|set| format!("ss{:02}", set.number)).collect();
|
||||
let listed: Vec<String> = sets.iter().map(|(_, flag, _)| flag.tag().unwrap_or_default().to_string()).collect();
|
||||
assert_eq!(listed, expected, "the submenu lists the stylistic sets of the text's face");
|
||||
let rows = menu_rows(&app);
|
||||
if expected.is_empty() {
|
||||
assert!(!rows.iter().any(|row| matches!(row, PanelRow::Submenu(..))), "the submenu is left out when the face offers no sets");
|
||||
} else {
|
||||
let submenu = rows.iter().find_map(|row| match row {
|
||||
PanelRow::Submenu(_, sub) if (1..=20).any(|number| has_row(sub, &toggle_ref(&format!("ss{number:02}")))) => Some(sub),
|
||||
_ => None,
|
||||
});
|
||||
let actual: Vec<&str> = submenu
|
||||
.expect("the menu has a Stylistic Sets submenu")
|
||||
.iter()
|
||||
.filter_map(|row| match row {
|
||||
PanelRow::Command(c) if c.id == TOGGLE => Some(c.params["tag"].as_str().expect("a toggle has a tag")),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(actual, expected, "the submenu toggle tags match the face's sets in order");
|
||||
}
|
||||
for tag in &expected {
|
||||
let r = toggle_ref(tag);
|
||||
assert!(rows.iter().any(|row| matches!(row, PanelRow::Submenu(_, sub) if has_row(sub, &r))), "the submenu has a row for {tag}");
|
||||
}
|
||||
let Some((first, flag, _)) = sets.first() else { return };
|
||||
let (label, tag) = (set_label(first), flag.tag().unwrap());
|
||||
set(&mut app, OtFeatures { small_caps: true, ..Default::default() });
|
||||
|
||||
Reference in new issue
Block a user