Tests: compare OPEN_EXTS with the readable formats as one map

The gate's test-lint step failed on open_exts_cover_every_readable_format:
the filter assertions this branch changes sit in the same test as two
loops that only check presence for every entry of FORMATS and OPEN_EXTS
(the census rule). The test now builds the extension-to-format map from
the readable formats and from readable_format() over OPEN_EXTS and
compares the two, so a missing, extra, duplicated or misrouted extension
fails with the whole difference. It also checks that no extension is
claimed by two readable formats, plus an alias, a mixed-case name with a
leading dot, and that .txt is not a graphic format.
This commit is contained in:
dotCooCoo
2026-12-04 16:54:29 -08:00
parent a9230fd7c3
commit c12e48284d
+10 -8
View File
@@ -448,14 +448,16 @@ fn templates_open_untitled() {
#[test]
fn open_exts_cover_every_readable_format() {
for f in FORMATS.iter().filter(|f| f.read) {
for e in read_extensions(f) {
assert!(OPEN_EXTS.contains(e), "OPEN_EXTS lacks .{e} ({})", f.label);
}
}
for e in OPEN_EXTS {
assert!(readable_format(e).is_some(), ".{e} in OPEN_EXTS is no readable format");
}
let owner: std::collections::BTreeMap<&str, &str> =
FORMATS.iter().filter(|f| f.read).flat_map(|f| read_extensions(f).iter().map(move |e| (*e, f.id))).collect();
let declared: usize = FORMATS.iter().filter(|f| f.read).map(|f| read_extensions(f).len()).sum();
assert_eq!(owner.len(), declared, "no extension is claimed by two readable formats");
let looked_up: std::collections::BTreeMap<&str, &str> = OPEN_EXTS.iter().filter_map(|e| Some((*e, readable_format(e)?.id))).collect();
assert_eq!(looked_up.len(), OPEN_EXTS.len(), "every OPEN_EXTS entry is listed once and looks up a readable format");
assert_eq!(looked_up, owner, "OPEN_EXTS is exactly the readable formats' extensions, each looking up its own format");
assert_eq!(readable_format("dib").map(|f| f.id), Some("bmp"), "an alias opens as its format");
assert_eq!(readable_format(".SVG").map(|f| f.id), Some("svg"), "any case, leading dot allowed");
assert!(readable_format("txt").is_none(), "text documents open through their own reader, not a graphic format");
let filters: Vec<_> = open_filters().collect();
assert_eq!(filters[0], ("All readable files", &[OPEN_EXTS, TEXT_DOCUMENT_EXTS].concat()[..]));
assert_eq!(