use hunch::Pipeline;
#[test]
fn issue_94_fallback_title_single_file() {
let pipeline = Pipeline::new();
let result = pipeline.run_with_context_and_fallback(
"Paw Patrol/SP/Special.720p.mkv",
&Vec::<&str>::new(),
Some("Paw Patrol"),
);
assert_eq!(
result.title(),
Some("Paw Patrol"),
"single file should inherit parent title via fallback"
);
}
#[test]
fn issue_94_fallback_title_few_dissimilar_files() {
let pipeline = Pipeline::new();
let result = pipeline.run_with_context_and_fallback(
"ShowName/Extras/Making.Of.720p.mkv",
&["ShowName/Extras/Gag.Reel.720p.mkv"],
Some("ShowName"),
);
let title = result.title().unwrap_or("");
assert!(
title.contains("ShowName"),
"title should include the parent show name, got: {title:?}"
);
}
#[test]
fn issue_94_invariance_wins_over_fallback() {
let pipeline = Pipeline::new();
let siblings = vec![
"Show/Season 2/Show.S02E01.720p.mkv",
"Show/Season 2/Show.S02E02.720p.mkv",
"Show/Season 2/Show.S02E03.720p.mkv",
];
let result = pipeline.run_with_context_and_fallback(
"Show/Season 2/Show.S02E04.720p.mkv",
&siblings,
Some("Wrong Show Name"),
);
assert_ne!(
result.title(),
Some("Wrong Show Name"),
"invariance should win over fallback when siblings produce a title"
);
}
#[test]
fn issue_94_no_fallback_no_crash() {
let pipeline = Pipeline::new();
let result = pipeline.run_with_context_and_fallback(
"Some.Movie.2024.720p.mkv",
&Vec::<&str>::new(),
None,
);
assert_eq!(result.title(), Some("Some Movie"));
}
#[test]
fn issue_94_dir_name_invariance_yields_to_fallback() {
let pipeline = Pipeline::new();
let siblings = vec![
"夏目友人帐/特典映像/[DBD-Raws][Natsume.Yuujinchou.Shichi][NC.Ver][1080P].mkv",
"夏目友人帐/特典映像/[DBD-Raws][Natsume.Yuujinchou.Shichi][TalkShow][1080P].mkv",
];
let result = pipeline.run_with_context_and_fallback(
"夏目友人帐/特典映像/[DBD-Raws][Natsume.Yuujinchou.Shichi][劇伴コンサート][1080P].mkv",
&siblings,
Some("夏目友人帐"),
);
let title = result.title().unwrap_or("");
assert_ne!(
title, "特典映像",
"invariance should not use the sub-directory name as the title"
);
}
#[test]
fn issue_94_dir_name_invariance_extras() {
let pipeline = Pipeline::new();
let siblings = vec![
"ShowName/Extras/Behind.The.Scenes.720p.mkv",
"ShowName/Extras/Visual.Effects.720p.mkv",
];
let result = pipeline.run_with_context_and_fallback(
"ShowName/Extras/Interview.720p.mkv",
&siblings,
Some("ShowName"),
);
let title = result.title().unwrap_or("");
assert_ne!(
title, "Extras",
"directory name 'Extras' should not be the title when fallback is available"
);
assert!(
title.contains("ShowName"),
"title should include the parent show name, got: {title:?}"
);
}