beffroi-tools/crates/rundown-converter/tests/supplied_corpus.rs

165 lines
5.5 KiB
Rust

//! User-supplied workbooks: exercise the actual XLSX reader and conversion pipeline.
use rundown_converter::{export, model::*, pipeline, reader};
use std::{path::PathBuf, sync::atomic::AtomicBool};
fn workbook(name: &str) -> Vec<Table> {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../rundowns")
.join(name);
reader::read(&path).unwrap()
}
fn analyze(table: &Table, profile: &Profile) -> Analysis {
pipeline::analyze(table, profile, &AtomicBool::new(false), |_, _| {})
}
fn codes(analysis: &Analysis) -> Vec<&str> {
analysis
.diagnostics
.iter()
.map(|d| d.code.as_str())
.collect()
}
#[test]
fn moebius_french_headers_and_excel_times_reach_schedule_validation() {
for (file, count, last_row, expected_codes) in [
(
"moebius-matin-pleniere-sante-environnement.xlsx",
26,
35,
vec!["INVALID_EVENT"],
),
(
"moebius-apres-midi-sante-mentale.xlsx",
20,
21,
vec!["INVALID_EVENT", "OVERLAP"],
),
] {
let tables = workbook(file);
assert_eq!(tables.len(), 1);
let analysis = analyze(&tables[0], &Profile::default());
let mapping = analysis.mapping.as_ref().unwrap();
assert_eq!(
(
mapping.header_row,
mapping.start,
mapping.title,
mapping.duration
),
(1, 0, 1, Some(2)),
"{file}"
);
assert_eq!(codes(&analysis), expected_codes, "{file}");
assert!(
analysis
.diagnostics
.iter()
.all(|d| d.location == format!("Feuil1!row {last_row}"))
);
let rundown = analysis.rundown.unwrap();
assert_eq!(rundown.entries.len(), count);
let first = &rundown.entries[0];
assert_eq!(first.duration_ms, 15 * 60_000);
assert_eq!(first.end_ms - first.start_ms, first.duration_ms);
assert!(first.explicit_start);
assert!(!first.inferred_duration);
}
}
#[test]
fn competing_pleniere_timers_require_a_column_choice() {
let tables = workbook("pleniere-2.xlsx");
let analysis = analyze(&tables[0], &Profile::default());
assert!(analysis.mapping.is_none());
assert!(analysis.rundown.is_none());
assert_eq!(codes(&analysis), ["AMBIGUOUS_COLUMN"]);
assert!(analysis.diagnostics[0].message.contains("C, D"));
}
#[test]
fn estivales_merged_blocks_preserve_notes_and_missing_final_duration() {
let tables = workbook("estivales-2025-plenieres.xlsx");
assert_eq!(tables.len(), 2);
let profile = Profile {
untimed_as_notes: true,
..Default::default()
};
let opening = tables.iter().find(|t| t.name == "OUVERTURE").unwrap();
assert_eq!(opening.merges.len(), 9);
let analysis = analyze(opening, &profile);
assert_eq!(codes(&analysis), ["MISSING_DURATION"]);
let closing = tables.iter().find(|t| t.name == "CLOTURE").unwrap();
assert_eq!(closing.merges.len(), 2);
let analysis = analyze(closing, &profile);
assert!(
analysis.diagnostics.is_empty(),
"{:?}",
analysis.diagnostics
);
let rundown = analysis.rundown.unwrap();
assert_eq!(rundown.entries.len(), 5);
let output = export::ontime(&rundown).unwrap();
assert_eq!(
output["rundowns"]["default"]["order"]
.as_array()
.unwrap()
.len(),
5
);
let rows: Vec<_> = rundown
.entries
.iter()
.flat_map(|entry| entry.source_rows.iter().map(|source| source.row))
.collect();
assert_eq!(rows, (2..=14).collect::<Vec<_>>());
}
#[test]
fn gifav_parent_ranges_preserve_gaps_and_friday_overlap() {
let tables = workbook("gifav-2026-auditorium.xlsx");
assert_eq!(tables.len(), 2);
let profile = Profile {
columns: [
("start_end".into(), "A".into()),
("title".into(), "D".into()),
]
.into(),
column_usage: [("B".into(), "ignore".into()), ("E".into(), "notes".into())].into(),
..Default::default()
};
for table in &tables {
let unmapped = analyze(table, &Profile::default());
assert_eq!(codes(&unmapped), ["MISSING_COLUMN"]);
let analysis = analyze(table, &profile);
assert!(analysis.mapping.as_ref().unwrap().start_end);
let thursday = table.name == "Jeudi 5nov26";
if thursday {
assert!(analysis.diagnostics.is_empty());
} else {
assert_eq!(table.name, "Vendredi 6nov26_Auditorium");
assert_eq!(codes(&analysis), ["OVERLAP"]);
assert_eq!(
analysis.diagnostics[0].location,
"Vendredi 6nov26_Auditorium!row 16"
);
}
let rundown = analysis.rundown.unwrap();
assert_eq!(rundown.entries.len(), if thursday { 11 } else { 10 });
assert_eq!(rundown.gaps.len(), 3);
assert!(rundown.gaps.iter().all(|gap| !gap.display_timer));
if thursday {
let output = export::ontime(&rundown).unwrap();
let entries = output["rundowns"]["default"]["entries"]
.as_object()
.unwrap();
assert_eq!(entries.len(), 11);
for event in &rundown.entries {
assert_eq!(entries[&event.id]["timeStart"], event.start_ms);
assert_eq!(entries[&event.id]["duration"], event.duration_ms);
}
}
}
}