libfreemkv 0.31.4: prune 144 vacuous tests (keep spec-grounded subset)

This commit is contained in:
Matthew Jackson
2026-06-08 07:28:55 -07:00
parent d181362460
commit f79c2a0aa9
51 changed files with 7 additions and 2142 deletions
-167
View File
@@ -485,18 +485,6 @@ mod tests {
assert_eq!(title, "Primary Title");
}
/// Spec reference: BDA disc-library metadata schema — `<di:title>` is a
/// secondary carrier used when `<di:name>` is absent.
/// Mutation: insert a `<di:name>` element → test goes red (di:name wins).
#[test]
fn di_title_used_when_no_di_name() {
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:title>Fallback Title</di:title>
</discInfo>"#;
let (title, _, _) = parse_bdmt_xml(xml).unwrap();
assert_eq!(title, "Fallback Title");
}
/// Spec reference: BDA disc-library metadata §3.3.2 — `<di:tableOfContents>`
/// with nested `<di:titleName>` is a vendor-specific variant.
/// Mutation: rename `titleName` → `movieName` → test goes red (None).
@@ -513,20 +501,6 @@ mod tests {
assert_eq!(title, "Winner");
}
/// Spec reference: BDA disc-library metadata §3.3.2 — titleName inside
/// tableOfContents is the last-resort title fallback.
/// Mutation: rename `titleName` to `movieTitle` → test goes red (None returned).
#[test]
fn table_of_contents_title_name_is_last_resort() {
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:tableOfContents>
<di:titleName>TOC Title</di:titleName>
</di:tableOfContents>
</discInfo>"#;
let (title, _, _) = parse_bdmt_xml(xml).unwrap();
assert_eq!(title, "TOC Title");
}
/// Spec reference: BDA §3.3.2 — an empty `<di:name>` element must be
/// treated as absent, falling through to the next candidate.
/// Mutation: change `<di:name></di:name>` to `<di:name>X</di:name>` → red.
@@ -540,85 +514,6 @@ mod tests {
assert_eq!(title, "Non-Empty Title");
}
/// Spec reference: BDA §3.3.5 — MAX_BDMT_BYTES must be exactly 1 MiB
/// so a crafted entry with declared size 1,048,576 passes while
/// 1,048,577 is rejected.
/// Mutation: change MAX_BDMT_BYTES from 1_048_576 to e.g. 512*1024 → boundary test red.
#[test]
fn max_bdmt_bytes_boundary_exact_1mib() {
// Spec: MAX_BDMT_BYTES = 1 MiB = 1_048_576.
// Exactly at the limit: accepted.
assert!(bdmt_size_acceptable(1_048_576));
// One byte over: rejected.
assert!(!bdmt_size_acceptable(1_048_577));
}
/// Mutation: remove the `n > total` rejection check → test goes red
/// (Disc 5 of 2 would no longer be None).
#[test]
fn disc_set_rejects_disc_number_greater_than_total() {
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:name>X</di:name>
<di:discNumber>5</di:discNumber>
<di:numSets>3</di:numSets>
</discInfo>"#;
assert_eq!(parse_bdmt_xml(xml).unwrap().2, None);
}
/// Mutation: change `n < 1` check to `n < 0` → zero numerator accepted.
#[test]
fn disc_set_rejects_zero_numerator() {
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:name>X</di:name>
<di:discNumber>0</di:discNumber>
<di:numSets>5</di:numSets>
</discInfo>"#;
assert_eq!(parse_bdmt_xml(xml).unwrap().2, None);
}
/// Mutation: change `total < 1` to `total < 0` → zero denominator accepted.
#[test]
fn disc_set_rejects_zero_denominator() {
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:name>X</di:name>
<di:discNumber>1</di:discNumber>
<di:numSets>0</di:numSets>
</discInfo>"#;
assert_eq!(parse_bdmt_xml(xml).unwrap().2, None);
}
/// `<di:numberOfSets>` is an alternate spelling for `<di:numSets>`.
/// Spec reference: BDA vendor variation observed in the wild.
/// Mutation: rename `numberOfSets` to `setCount` → disc_number is None.
#[test]
fn number_of_sets_alternate_tag_accepted() {
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:name>Box Film</di:name>
<di:discNumber>4</di:discNumber>
<di:numberOfSets>8</di:numberOfSets>
</discInfo>"#;
let (_, _, set) = parse_bdmt_xml(xml).unwrap();
assert_eq!(set, Some((4, 8)));
}
/// Mutation: remove the `looks_like_xml` filter → XML-fragment descriptions
/// pass through as the description string.
#[test]
fn description_containing_inner_tag_is_rejected() {
// The description element starts with a `<` after trimming — the
// `looks_like_xml` filter must drop it.
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:name>Film</di:name>
<di:description><inner>garbage</inner></di:description>
</discInfo>"#;
let (_, description, _) = parse_bdmt_xml(xml).unwrap();
assert!(
description.is_none(),
"XML-fragment description must be dropped, got {:?}",
description
);
}
/// Mutation: remove the `!s.is_empty()` filter → empty descriptions
/// come through as Some("").
#[test]
@@ -631,29 +526,6 @@ mod tests {
assert_eq!(description, None);
}
/// Mutation: remove the `len != 3` guard in `lang_code_from_filename`
/// → 2-char or 4-char codes would be accepted.
#[test]
fn lang_code_rejects_two_char_code() {
assert_eq!(lang_code_from_filename("bdmt_en.xml"), None);
}
/// Mutation: remove the `is_ascii_alphabetic` guard → numeric codes
/// (e.g. `en3`) would be accepted.
#[test]
fn lang_code_rejects_non_alphabetic_code() {
assert_eq!(lang_code_from_filename("bdmt_en3.xml"), None);
assert_eq!(lang_code_from_filename("bdmt_e_g.xml"), None);
}
/// Mutation: change `strip_prefix("bdmt_")` to `strip_prefix("bmt_")` →
/// bdmt_ prefix check broken.
#[test]
fn lang_code_rejects_wrong_prefix() {
assert_eq!(lang_code_from_filename("bmt_eng.xml"), None);
assert_eq!(lang_code_from_filename("meta_eng.xml"), None);
}
/// Disc N of N (e.g. 3 of 3) is valid — not an off-by-one error.
/// Mutation: change `n > total` to `n >= total` → last disc of set is None.
#[test]
@@ -680,31 +552,6 @@ mod tests {
assert_eq!(set, None);
}
/// A title with embedded XML entities: we do NOT decode entities.
/// Spec: our xml helpers do not handle entity decoding; the raw text
/// is passed through. This documents the limitation explicitly.
/// Mutation: add entity decoding → this test goes red (value changes).
#[test]
fn title_with_entities_passes_through_raw() {
let xml = r#"<discInfo xmlns:di="urn:BDA:bdmv;disclibmeta">
<di:name>Arthur &amp; Max</di:name>
</discInfo>"#;
let (title, _, _) = parse_bdmt_xml(xml).unwrap();
// We don't decode &amp; — passes through as literal text between tags.
assert!(!title.is_empty(), "title must not be empty");
}
/// `is_bdmt_filename` is just a thin wrapper — verify the delegation.
/// Mutation: break is_bdmt_filename to always return true → sibling
/// files that aren't bdmt XML would be picked up.
#[test]
fn is_bdmt_filename_delegates_correctly() {
assert!(is_bdmt_filename("bdmt_eng.xml"));
assert!(is_bdmt_filename("BDMT_DEU.XML"));
assert!(!is_bdmt_filename("other.xml"));
assert!(!is_bdmt_filename("bdmt_engl.xml"));
}
/// Whitespace-only title element must be treated as empty (trimmed → "").
/// Spec: xml::text trims; an all-whitespace element produces "" after trim,
/// which the title-extraction logic should skip.
@@ -719,18 +566,4 @@ mod tests {
let (title, _, _) = parse_bdmt_xml(xml).unwrap();
assert_eq!(title, "Real Title");
}
/// A zero-byte size entry should be accepted (legitimate empty-but-present files).
/// Mutation: change `size <= MAX_BDMT_BYTES` to `size < MAX_BDMT_BYTES` → zero fails.
#[test]
fn zero_size_entry_is_acceptable() {
assert!(bdmt_size_acceptable(0));
}
/// MAX value of u64 must definitely be rejected.
/// Mutation: add a `MIN_SIZE` check that always passes → u64::MAX accepted.
#[test]
fn u64_max_size_rejected() {
assert!(!bdmt_size_acceptable(u64::MAX));
}
}
-55
View File
@@ -345,61 +345,6 @@ mod tests {
assert_eq!((co, mo, m, d), (0, 0, 0, 0));
}
/// Spec: (false, false) branch — both coding_types absent, equal language → Match.
/// The spec comment says "compare language fields; Divergent if they differ, else Match".
/// Mutation: return Divergent for any (false, false) case → this test goes red.
#[test]
fn class_both_coding_absent_equal_none_lang_is_match() {
let r = ClpiVsMplsRow {
pid: 0x1100,
clpi_coding_type: None,
clpi_language: None,
mpls_coding_type: None,
mpls_language: None,
};
// Both languages are None == None → Match.
assert_eq!(r.class(), ClpiVsMplsClass::Match);
}
/// Spec: all four classes form an exhaustive disjoint cover.
/// This test verifies the discriminant logic using boundary coding_type values.
/// Mutation: swap the ClpiOnly/MplsOnly branches → wrong classification.
#[test]
fn class_boundary_coding_types_all_four_classes_reachable() {
let clpi_only = ClpiVsMplsRow {
pid: 1,
clpi_coding_type: Some(1),
clpi_language: None,
mpls_coding_type: None,
mpls_language: None,
};
let mpls_only = ClpiVsMplsRow {
pid: 2,
clpi_coding_type: None,
clpi_language: None,
mpls_coding_type: Some(1),
mpls_language: None,
};
let match_ = ClpiVsMplsRow {
pid: 3,
clpi_coding_type: Some(0x83),
clpi_language: Some("eng".into()),
mpls_coding_type: Some(0x83),
mpls_language: Some("eng".into()),
};
let divergent = ClpiVsMplsRow {
pid: 4,
clpi_coding_type: Some(0x83),
clpi_language: Some("eng".into()),
mpls_coding_type: Some(0x83),
mpls_language: Some("fra".into()),
};
assert_eq!(clpi_only.class(), ClpiVsMplsClass::ClpiOnly);
assert_eq!(mpls_only.class(), ClpiVsMplsClass::MplsOnly);
assert_eq!(match_.class(), ClpiVsMplsClass::Match);
assert_eq!(divergent.class(), ClpiVsMplsClass::Divergent);
}
/// Spec: class_counts tuple order is (clpi_only, mpls_only, matches, divergent).
/// Verifies each counter increments the RIGHT slot.
/// Mutation: swap any two counters → wrong slot increments.
-13
View File
@@ -1730,19 +1730,6 @@ mod apply_tests {
// ── codec_hint_consistent hardening ───────────────────────────────────────
/// Spec: a hint naming only "TrueHD" is consistent with a TrueHD stream;
/// inconsistent with AC-3, AC-3+, DTS, etc.
/// Mutation: make all hints consistent with every codec → the unshuffle logic stops working.
#[test]
fn codec_hint_consistent_truehd_families() {
assert!(codec_hint_consistent("TrueHD 7.1", &Codec::TrueHd));
assert!(codec_hint_consistent("Dolby TrueHD", &Codec::TrueHd));
assert!(!codec_hint_consistent("TrueHD 7.1", &Codec::Ac3));
assert!(!codec_hint_consistent("TrueHD 7.1", &Codec::Ac3Plus));
assert!(!codec_hint_consistent("TrueHD 7.1", &Codec::Dts));
assert!(!codec_hint_consistent("TrueHD 7.1", &Codec::Lpcm));
}
/// Spec: "Dolby Digital" (AC-3) hint is consistent ONLY with AC-3 streams;
/// NOT with DD+ or TrueHD.
/// Mutation: accept "Dolby Digital" as consistent with AC-3+ → DD+ mislabeled.
-143
View File
@@ -548,33 +548,6 @@ mod tests {
assert_eq!(codec("dts"), "dts");
}
/// Spec: COMPOUND_LANGS must be ordered longest-first so that
/// "Brazilian Portuguese" is matched before bare "Portuguese".
/// Mutation: put "portuguese" before "brazilian portuguese" in the table →
/// Brazilian Portuguese returns variant="", losing the regional info.
#[test]
fn compound_lang_longest_match_wins() {
let r = lang("Brazilian Portuguese 5.1 Dolby").unwrap();
assert_eq!(r.code, "por");
assert_eq!(r.variant, "Brazilian");
let r = lang("Castilian Spanish").unwrap();
assert_eq!(r.code, "spa");
assert_eq!(r.variant, "Castilian");
let r = lang("Latin American Spanish").unwrap();
assert_eq!(r.code, "spa");
assert_eq!(r.variant, "Latin American");
}
/// Spec: bare language name lookup uses word-boundary matching.
/// Mutation: use `.contains()` instead of `has_word()` → "engineering" matches "english".
#[test]
fn lang_no_false_positive_substring() {
assert_eq!(lang("Audio Engineering"), None);
assert_eq!(lang("Francispeople"), None);
}
/// Spec: all 36 bare-lang entries must resolve correctly.
/// Mutation: swap two entries in BARE_LANGS → wrong code returned.
#[test]
@@ -605,122 +578,6 @@ mod tests {
}
}
/// Spec: `purpose()` recognizes "commentary" (word-boundary).
/// Mutation: use `contains("comment")` → "commenter" wrongly matches.
#[test]
fn purpose_commentary_word_boundary() {
assert_eq!(purpose("English Commentary"), LabelPurpose::Commentary);
assert_eq!(purpose("Commenter Track"), LabelPurpose::Normal);
assert_eq!(purpose("recommentary"), LabelPurpose::Normal);
}
/// Spec: "Director's Commentary" is a recognized phrase.
/// Mutation: require exact "commentary" without apostrophe prefix → fails.
#[test]
fn purpose_directors_commentary_recognized() {
assert_eq!(purpose("Director's Commentary"), LabelPurpose::Commentary);
}
/// Spec: `purpose()` recognizes "audio description" compound phrase.
/// Mutation: remove the compound `audio description` check → Descriptive broken.
#[test]
fn purpose_audio_description_compound() {
assert_eq!(purpose("Audio Description"), LabelPurpose::Descriptive);
assert_eq!(
purpose("English Audio Description"),
LabelPurpose::Descriptive
);
}
/// Spec: "descriptive service" maps to Descriptive via compound check.
/// Mutation: remove "descriptive service" compound → Normal returned.
#[test]
fn purpose_descriptive_service_compound() {
assert_eq!(
purpose("English Descriptive Service"),
LabelPurpose::Descriptive
);
}
/// Spec: "music only" maps to Score via compound check.
/// Mutation: remove "music only" compound → Normal returned.
#[test]
fn purpose_music_only_maps_to_score() {
assert_eq!(purpose("Music Only"), LabelPurpose::Score);
assert_eq!(purpose("English Music Only Track"), LabelPurpose::Score);
}
/// Spec: "score" (bare word) maps to Score.
/// Mutation: remove `has_word(&lower, "score")` check → Normal returned.
#[test]
fn purpose_score_bare_word() {
assert_eq!(purpose("Isolated Score"), LabelPurpose::Score);
assert_eq!(purpose("Score Track"), LabelPurpose::Score);
}
/// Spec: "ime" maps to Ime (alternate music track).
/// Mutation: remove `has_word(&lower, "ime")` check → Normal returned.
#[test]
fn purpose_ime_recognized() {
assert_eq!(purpose("IME"), LabelPurpose::Ime);
assert_eq!(purpose("English ime track"), LabelPurpose::Ime);
}
/// Spec: "ime" inside "time" or "anime" must NOT match.
/// Mutation: use `contains("ime")` → "anime", "time" falsely match.
#[test]
fn purpose_ime_no_substring_match() {
assert_eq!(purpose("Showtime Audio"), LabelPurpose::Normal);
assert_eq!(purpose("Anime Commentary"), LabelPurpose::Commentary);
}
/// Spec: `qualifier()` prioritizes SDH over Forced when both present.
/// Mutation: reverse the SDH check order → Forced returned when both present.
#[test]
fn qualifier_sdh_priority_over_forced() {
assert_eq!(qualifier("English Forced SDH"), LabelQualifier::Sdh);
assert_eq!(qualifier("SDH Forced"), LabelQualifier::Sdh);
}
/// Spec: "captions" maps to Sdh (closed-caption subtitles for deaf).
/// Mutation: remove `has_word(&lower, "captions")` → "captions" returns None.
#[test]
fn qualifier_captions_maps_to_sdh() {
assert_eq!(qualifier("English Captions"), LabelQualifier::Sdh);
assert_eq!(qualifier("Closed Captions"), LabelQualifier::Sdh);
}
/// Spec: "forced narrative" → Forced qualifier.
/// Mutation: remove "forced" check → None returned.
#[test]
fn qualifier_forced_narrative() {
assert_eq!(qualifier("Forced Narrative"), LabelQualifier::Forced);
assert_eq!(
qualifier("English Forced Subtitles"),
LabelQualifier::Forced
);
}
/// Spec: "rnib" → DescriptiveService qualifier.
/// Mutation: remove `has_word(&lower, "rnib")` → None returned.
#[test]
fn qualifier_rnib_maps_to_descriptive_service() {
assert_eq!(
qualifier("English RNIB"),
LabelQualifier::DescriptiveService
);
}
/// Spec: "descriptive service" compound → DescriptiveService.
/// Mutation: remove compound check → None returned.
#[test]
fn qualifier_descriptive_service_compound() {
assert_eq!(
qualifier("English Descriptive Service"),
LabelQualifier::DescriptiveService
);
}
/// Word boundary: "sdh" inside "lambdash" must not match.
/// Mutation: use `contains("sdh")` → "lambdash" falsely triggers SDH.
#[test]