2201 lines
72 KiB
Rust
2201 lines
72 KiB
Rust
use rundown_converter::{detect, export, model::*, pipeline, reader, time};
|
||
use std::{collections::BTreeMap, io::Write, sync::atomic::AtomicBool};
|
||
|
||
fn table(rows: &[&[&str]]) -> Table {
|
||
Table {
|
||
name: "Show".into(),
|
||
rows: rows
|
||
.iter()
|
||
.map(|r| {
|
||
r.iter()
|
||
.map(|v| Cell {
|
||
text: (*v).into(),
|
||
..Cell::default()
|
||
})
|
||
.collect()
|
||
})
|
||
.collect(),
|
||
merges: vec![],
|
||
}
|
||
}
|
||
fn analyze(t: &Table, p: &Profile) -> Analysis {
|
||
pipeline::analyze(t, p, &AtomicBool::new(false), |_, _| {})
|
||
}
|
||
fn simple() -> Table {
|
||
table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["11:45", "15 min", "Morning"],
|
||
&["13:30", "20 min", "Afternoon"],
|
||
])
|
||
}
|
||
#[test]
|
||
fn independent_anchors_and_implicit_lunch_gap() {
|
||
let a = analyze(&simple(), &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert!(r.entries.iter().all(|entry| !entry.inferred_duration));
|
||
assert!(r.entries.iter().all(|entry| entry.inferred_end));
|
||
assert_eq!(r.gaps.len(), 1);
|
||
assert_eq!(r.gaps[0].start_ms, Some(43_200_000));
|
||
assert_eq!(r.gaps[0].end_ms, Some(48_600_000));
|
||
assert!(!r.gaps[0].display_timer);
|
||
let json = export::ontime(&r).unwrap();
|
||
let entries = json["rundowns"]["default"]["entries"].as_object().unwrap();
|
||
assert_eq!(entries.len(), 2);
|
||
assert!(
|
||
entries
|
||
.values()
|
||
.all(|e| e["linkStart"] == false && e["endAction"] == "none")
|
||
);
|
||
assert!(entries.values().any(|e| e["timeStart"] == 48_600_000));
|
||
}
|
||
|
||
#[test]
|
||
fn ir_records_inferred_start_end_and_duration_provenance() {
|
||
let t = table(&[
|
||
&["Start", "End", "Duration", "Title"],
|
||
&["09:00", "", "10 min", "Opening"],
|
||
&["", "09:30", "", "Continuation"],
|
||
]);
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let entries = a.rundown.unwrap().entries;
|
||
assert!(entries[0].explicit_start);
|
||
assert!(entries[0].inferred_end);
|
||
assert!(!entries[0].inferred_duration);
|
||
assert!(!entries[1].explicit_start);
|
||
assert!(!entries[1].inferred_end);
|
||
assert!(entries[1].inferred_duration);
|
||
}
|
||
|
||
#[test]
|
||
fn combined_start_end_column_is_inferred_and_enforced_across_rows() {
|
||
let t = table(&[
|
||
&["Horaires", "Title"],
|
||
&["08h00 - 08h30", "Welcome"],
|
||
&["08h30-09h15", "Keynote"],
|
||
]);
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let mapping = a.mapping.unwrap();
|
||
assert!(mapping.start_end);
|
||
assert_eq!(mapping.start, 0);
|
||
let entries = a.rundown.unwrap().entries;
|
||
assert_eq!(entries[0].start_ms, 8 * 3_600_000);
|
||
assert_eq!(entries[0].end_ms, 8 * 3_600_000 + 30 * 60_000);
|
||
assert_eq!(entries[0].duration_ms, 30 * 60_000);
|
||
|
||
let malformed = table(&[
|
||
&["Window", "Title"],
|
||
&["08:00 - 08:30", "Welcome"],
|
||
&["08:30", "Keynote"],
|
||
]);
|
||
let profile = Profile {
|
||
header_row: Some(1),
|
||
columns: BTreeMap::from([
|
||
("start_end".into(), "A".into()),
|
||
("title".into(), "B".into()),
|
||
]),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&malformed, &profile);
|
||
assert!(
|
||
a.diagnostics
|
||
.iter()
|
||
.any(|d| { d.code == "INCONSISTENT_COLUMN_MEANING" && d.location.ends_with("A3") })
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn start_role_extracts_only_start_from_a_mixed_clock_range() {
|
||
let t = table(&[
|
||
&["Horaires", "Durée", "Title"],
|
||
&["08h45 - 09h10", "20 min + 5 min QR", "Welcome"],
|
||
]);
|
||
let profile = Profile {
|
||
header_row: Some(1),
|
||
columns: BTreeMap::from([
|
||
("start".into(), "A".into()),
|
||
("duration".into(), "B".into()),
|
||
("title".into(), "C".into()),
|
||
]),
|
||
duration_mode: Some("maximum".into()),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let event = &a.rundown.unwrap().entries[0];
|
||
assert_eq!(event.start_ms, (8 * 60 + 45) * 60_000);
|
||
assert_eq!(event.duration_ms, 20 * 60_000);
|
||
assert_eq!(event.end_ms, (9 * 60 + 5) * 60_000);
|
||
}
|
||
|
||
#[test]
|
||
fn duration_policies_extract_values_from_mixed_text() {
|
||
let cell = Cell {
|
||
text: "08h45 - 09h10\n20 min + 5 min QR".into(),
|
||
..Cell::default()
|
||
};
|
||
let selected = |mode| time::select_durations(&cell, None, Some(mode), Some("\\n")).unwrap();
|
||
assert_eq!(selected("minimum").events, [5 * 60_000]);
|
||
assert_eq!(selected("maximum").events, [20 * 60_000]);
|
||
assert_eq!(selected("sum").events, [25 * 60_000]);
|
||
assert_eq!(selected("margin").events, [20 * 60_000]);
|
||
assert_eq!(selected("margin").margin, 5 * 60_000);
|
||
|
||
let split = Cell {
|
||
text: "08:00 - 08:15\n10 min + 5 min|20 min".into(),
|
||
..Cell::default()
|
||
};
|
||
assert_eq!(
|
||
time::select_durations(&split, None, Some("split"), Some("|"))
|
||
.unwrap()
|
||
.events,
|
||
[15 * 60_000, 20 * 60_000]
|
||
);
|
||
|
||
let summary_and_detail = Cell {
|
||
text: "30 mn\n25 min + 5 min questions".into(),
|
||
..Cell::default()
|
||
};
|
||
assert_eq!(
|
||
time::select_durations(&summary_and_detail, None, Some("sum"), Some("\\n"))
|
||
.unwrap()
|
||
.events,
|
||
[30 * 60_000]
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn start_only_merged_anchor_allows_sequential_child_durations() {
|
||
let mut t = table(&[
|
||
&["Horaires", "Durée", "Title"],
|
||
&["08h45 - 10h00", "20 min + 5 min", "First"],
|
||
&["", "20 min + 5 min", "Second"],
|
||
&["", "20 min + 5 min", "Third"],
|
||
]);
|
||
t.merges.push(Merge {
|
||
first_row: 1,
|
||
last_row: 3,
|
||
first_col: 0,
|
||
last_col: 0,
|
||
});
|
||
let profile = Profile {
|
||
header_row: Some(1),
|
||
columns: BTreeMap::from([
|
||
("start".into(), "A".into()),
|
||
("duration".into(), "B".into()),
|
||
("title".into(), "C".into()),
|
||
]),
|
||
duration_mode: Some("margin".into()),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let rundown = a.rundown.unwrap();
|
||
assert_eq!(rundown.entries.len(), 3);
|
||
assert_eq!(rundown.entries[0].start_ms, (8 * 60 + 45) * 60_000);
|
||
assert_eq!(rundown.entries[1].start_ms, (9 * 60 + 10) * 60_000);
|
||
assert_eq!(rundown.entries[2].start_ms, (9 * 60 + 35) * 60_000);
|
||
assert_eq!(
|
||
rundown
|
||
.gaps
|
||
.iter()
|
||
.filter(|gap| gap.title == "Duration margin")
|
||
.count(),
|
||
3
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn duration_margin_becomes_an_explicit_untimed_gap() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["08:00", "20 min + 5 min", "Welcome"],
|
||
]);
|
||
let profile = Profile {
|
||
duration_mode: Some("margin".into()),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let rundown = a.rundown.unwrap();
|
||
assert_eq!(rundown.entries[0].duration_ms, 20 * 60_000);
|
||
let margin = rundown
|
||
.gaps
|
||
.iter()
|
||
.find(|gap| gap.title == "Duration margin")
|
||
.expect("duration margin gap");
|
||
assert_eq!(margin.start_ms, Some((8 * 60 + 20) * 60_000));
|
||
assert_eq!(margin.end_ms, Some((8 * 60 + 25) * 60_000));
|
||
}
|
||
|
||
#[test]
|
||
fn split_duration_creates_sequential_virtual_entries() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["08:00", "10 min\n5 min", "Welcome"],
|
||
]);
|
||
let profile = Profile {
|
||
duration_mode: Some("split".into()),
|
||
duration_separator: Some("\\n".into()),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let entries = a.rundown.unwrap().entries;
|
||
assert_eq!(entries.len(), 2);
|
||
assert_eq!(entries[0].duration_ms, 10 * 60_000);
|
||
assert_eq!(entries[1].duration_ms, 5 * 60_000);
|
||
assert_eq!(entries[0].end_ms, entries[1].start_ms);
|
||
assert_ne!(entries[0].id, entries[1].id);
|
||
assert_eq!(entries[0].title, "Welcome (1/2)");
|
||
assert_eq!(entries[1].title, "Welcome (2/2)");
|
||
}
|
||
|
||
#[test]
|
||
fn combined_start_end_mapping_rejects_separate_start_or_end_roles() {
|
||
let t = table(&[
|
||
&["Window", "Finish", "Title"],
|
||
&["08:00 - 08:30", "08:30", "Welcome"],
|
||
]);
|
||
for columns in [
|
||
BTreeMap::from([
|
||
("start".into(), "A".into()),
|
||
("start_end".into(), "A".into()),
|
||
("title".into(), "C".into()),
|
||
]),
|
||
BTreeMap::from([
|
||
("start_end".into(), "A".into()),
|
||
("end".into(), "B".into()),
|
||
("title".into(), "C".into()),
|
||
]),
|
||
] {
|
||
let a = analyze(
|
||
&t,
|
||
&Profile {
|
||
header_row: Some(1),
|
||
columns,
|
||
..Profile::default()
|
||
},
|
||
);
|
||
assert!(
|
||
a.diagnostics.iter().any(|d| d.code == "INVALID_MAPPING"),
|
||
"{:?}",
|
||
a.diagnostics
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn combined_ranges_do_not_hide_another_possible_start_column() {
|
||
let t = table(&[
|
||
&["Window", "Anchor", "Title"],
|
||
&["08:00 - 08:30", "08:00", "Welcome"],
|
||
&["08:30 - 09:15", "08:30", "Keynote"],
|
||
]);
|
||
let a = analyze(
|
||
&t,
|
||
&Profile {
|
||
header_row: Some(1),
|
||
columns: BTreeMap::from([("title".into(), "C".into())]),
|
||
..Profile::default()
|
||
},
|
||
);
|
||
assert!(
|
||
a.diagnostics.iter().any(|d| {
|
||
d.code == "AMBIGUOUS_COLUMN" && d.message.contains("start or start–end")
|
||
})
|
||
);
|
||
}
|
||
#[test]
|
||
fn named_untimed_break_occupies_time_without_timer() {
|
||
let t = table(&[
|
||
&["Heure", "Durée", "Déroulement"],
|
||
&["11h45", "15 min", "Talk"],
|
||
&["", "", "Déjeuner"],
|
||
&["13h30", "30 min", "Restart"],
|
||
]);
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 2);
|
||
assert_eq!(r.gaps.len(), 1);
|
||
assert_eq!(r.gaps[0].source_rows[0].row, 3);
|
||
}
|
||
#[test]
|
||
fn start_only_rows_do_not_invent_breaks_or_durations() {
|
||
let t = table(&[
|
||
&["Start", "Title"],
|
||
&["11:45", "Talk"],
|
||
&["13:30", "Restart"],
|
||
]);
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.iter().any(|d| d.code == "MISSING_DURATION"));
|
||
assert_eq!(a.completed_stage, 2);
|
||
}
|
||
#[test]
|
||
fn all_cells_must_fit_and_duplicate_timer_columns_are_errors() {
|
||
let mut t = simple();
|
||
t.rows[2][0].text = "after lunch".into();
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(
|
||
a.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INCONSISTENT_COLUMN_MEANING" && d.location.contains("A3"))
|
||
);
|
||
let t = table(&[
|
||
&["Heure", "Timer", "Timer", "Title"],
|
||
&["09h00", "20 min", "2 min", "A"],
|
||
]);
|
||
assert!(
|
||
analyze(&t, &Profile::default())
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "AMBIGUOUS_COLUMN")
|
||
);
|
||
let p = Profile {
|
||
columns: BTreeMap::from([("duration".into(), "B".into())]),
|
||
..Profile::default()
|
||
};
|
||
assert!(analyze(&t, &p).diagnostics.is_empty());
|
||
}
|
||
#[test]
|
||
fn duration_units_inferred_from_other_rows_and_not_per_cell() {
|
||
let t = table(&[
|
||
&["Start", "End", "Duration", "Title"],
|
||
&["09:00", "09:30", "00:30", "A"],
|
||
&["09:30", "10:30", "1h", "B"],
|
||
]);
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
assert_eq!(a.mapping.unwrap().duration_unit.as_deref(), Some("hh:mm"));
|
||
let t = table(&[&["Start", "Duration", "Title"], &["09:00", "15", "A"]]);
|
||
assert!(!analyze(&t, &Profile::default()).diagnostics.is_empty());
|
||
let p = Profile {
|
||
duration_unit: Some("minutes".into()),
|
||
..Profile::default()
|
||
};
|
||
assert!(analyze(&t, &p).diagnostics.is_empty());
|
||
}
|
||
#[test]
|
||
fn infer_roles_from_data_without_keyword_headers() {
|
||
let t = table(&[
|
||
&["When?", "Length?", "Title"],
|
||
&["09h00", "10 min", "A"],
|
||
&["10h00", "20 min", "B"],
|
||
]);
|
||
let p = Profile {
|
||
header_row: Some(1),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &p);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
assert_eq!(a.mapping.unwrap().duration, Some(1));
|
||
}
|
||
#[test]
|
||
fn independent_validation_rejects_conflicts_backward_and_negative_times() {
|
||
for (rows, code) in [
|
||
(
|
||
vec![
|
||
vec!["Start", "End", "Duration", "Title"],
|
||
vec!["09:00", "09:10", "20 min", "A"],
|
||
],
|
||
"CONFLICTING_TIMES",
|
||
),
|
||
(
|
||
vec![
|
||
vec!["Start", "Duration", "Title"],
|
||
vec!["10:00", "10 min", "A"],
|
||
vec!["09:00", "10 min", "B"],
|
||
],
|
||
"BACKWARD_TIME",
|
||
),
|
||
(
|
||
vec![vec!["Start", "End", "Title"], vec!["23:00", "01:00", "A"]],
|
||
"NEGATIVE_DURATION",
|
||
),
|
||
(
|
||
vec![
|
||
vec!["Start", "Duration", "Title"],
|
||
vec!["10:00", "-2 min", "A"],
|
||
],
|
||
"NEGATIVE_DURATION",
|
||
),
|
||
] {
|
||
let refs: Vec<&[&str]> = rows.iter().map(Vec::as_slice).collect();
|
||
let a = analyze(&table(&refs), &Profile::default());
|
||
assert!(
|
||
a.diagnostics.iter().any(|d| d.code == code),
|
||
"{code}: {:?}",
|
||
a.diagnostics
|
||
);
|
||
}
|
||
}
|
||
#[test]
|
||
fn merged_shared_duration_is_one_timer_with_all_source_rows() {
|
||
let mut t = table(&[
|
||
&["Heure", "Durée", "Title"],
|
||
&["09h00-09h20", "20 min", "First speaker"],
|
||
&["", "", "Second speaker"],
|
||
&["09h20", "5 min", "Next"],
|
||
]);
|
||
t.merges = vec![
|
||
Merge {
|
||
first_row: 1,
|
||
last_row: 2,
|
||
first_col: 0,
|
||
last_col: 0,
|
||
},
|
||
Merge {
|
||
first_row: 1,
|
||
last_row: 2,
|
||
first_col: 1,
|
||
last_col: 1,
|
||
},
|
||
];
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 2);
|
||
assert_eq!(r.entries[0].source_rows.len(), 2);
|
||
}
|
||
#[test]
|
||
fn merged_window_with_individual_durations_leaves_slack() {
|
||
let mut t = table(&[
|
||
&["Heure", "Durée", "Title"],
|
||
&["09h00-09h10", "3 min", "A"],
|
||
&["", "3 min", "B"],
|
||
&["", "3 min", "C"],
|
||
&["09h10-09h15", "5 min", "Next"],
|
||
]);
|
||
t.merges = vec![Merge {
|
||
first_row: 1,
|
||
last_row: 3,
|
||
first_col: 0,
|
||
last_col: 0,
|
||
}];
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 4);
|
||
assert_eq!(r.entries[1].start_ms, 32_580_000);
|
||
assert_eq!(r.gaps.len(), 1);
|
||
assert_eq!(
|
||
r.gaps[0].end_ms.unwrap() - r.gaps[0].start_ms.unwrap(),
|
||
60_000
|
||
);
|
||
t.rows[3][1].text = "5 min".into();
|
||
assert!(
|
||
analyze(&t, &Profile::default())
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "GROUP_OVERFLOW")
|
||
);
|
||
}
|
||
#[test]
|
||
fn notes_and_markers_require_explicit_choices() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "10 min", "A"],
|
||
&["", "", "Stage movement"],
|
||
&["09:10", "", "Thanks"],
|
||
]);
|
||
let unresolved = analyze(&t, &Profile::default());
|
||
let error = unresolved
|
||
.diagnostics
|
||
.iter()
|
||
.find(|d| d.code == "UNTIMED_ROW")
|
||
.unwrap();
|
||
assert!(
|
||
error
|
||
.message
|
||
.contains("Row preview:\nC (Title): Stage movement")
|
||
);
|
||
assert!(!error.message.contains("Thanks"));
|
||
let p = Profile {
|
||
untimed_as_notes: true,
|
||
row_kinds: BTreeMap::from([(4, "marker".into())]),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &p);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries[0].source_rows.len(), 2);
|
||
assert_eq!(r.entries[1].kind, "marker");
|
||
assert_eq!(
|
||
export::ontime(&r).unwrap()["rundowns"]["default"]["order"]
|
||
.as_array()
|
||
.unwrap()
|
||
.len(),
|
||
1
|
||
);
|
||
}
|
||
#[test]
|
||
fn explicit_corrections_preserve_originals() {
|
||
let t = table(&[
|
||
&["Start", "End", "Duration", "Title"],
|
||
&["09:00", "10:00", "TBC", "A"],
|
||
]);
|
||
let p = Profile {
|
||
titles: BTreeMap::from([(2, "Corrected title".into())]),
|
||
starts: BTreeMap::from([(2, "09:15".into())]),
|
||
ends: BTreeMap::from([(2, "09:20".into())]),
|
||
durations: BTreeMap::from([(2, "5 min".into())]),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &p);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries[0].start_ms, 33_300_000);
|
||
assert_eq!(r.entries[0].end_ms, 33_600_000);
|
||
assert_eq!(r.entries[0].duration_ms, 300_000);
|
||
assert_eq!(r.entries[0].title, "Corrected title");
|
||
assert_eq!(r.entries[0].source_rows[0].cells["A"].text, "09:00");
|
||
assert_eq!(r.entries[0].source_rows[0].cells["B"].text, "10:00");
|
||
assert_eq!(r.entries[0].source_rows[0].cells["C"].text, "TBC");
|
||
assert_eq!(r.entries[0].source_rows[0].cells["D"].text, "A");
|
||
|
||
for (profile, code) in [
|
||
(
|
||
Profile {
|
||
starts: BTreeMap::from([(2, "morning".into())]),
|
||
durations: BTreeMap::from([(2, "5 min".into())]),
|
||
..Profile::default()
|
||
},
|
||
"INVALID_START_OVERRIDE",
|
||
),
|
||
(
|
||
Profile {
|
||
ends: BTreeMap::from([(2, "later".into())]),
|
||
durations: BTreeMap::from([(2, "5 min".into())]),
|
||
..Profile::default()
|
||
},
|
||
"INVALID_END_OVERRIDE",
|
||
),
|
||
] {
|
||
assert!(
|
||
analyze(&t, &profile)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == code)
|
||
);
|
||
}
|
||
|
||
let overlap = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "1 h", "Opening"],
|
||
&["09:30", "30 min", "Next"],
|
||
]);
|
||
assert!(
|
||
analyze(&overlap, &Profile::default())
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "OVERLAP")
|
||
);
|
||
let corrected = analyze(
|
||
&overlap,
|
||
&Profile {
|
||
starts: BTreeMap::from([(3, "10:00".into())]),
|
||
..Profile::default()
|
||
},
|
||
);
|
||
assert!(
|
||
corrected.diagnostics.is_empty(),
|
||
"{:?}",
|
||
corrected.diagnostics
|
||
);
|
||
assert_eq!(corrected.rundown.unwrap().entries[1].start_ms, 36_000_000);
|
||
|
||
let missing_title = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "5 min", "Opening"],
|
||
&["09:05", "5 min", ""],
|
||
]);
|
||
assert!(
|
||
analyze(&missing_title, &Profile::default())
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "MISSING_TITLE")
|
||
);
|
||
let titled = analyze(
|
||
&missing_title,
|
||
&Profile {
|
||
titles: BTreeMap::from([(3, "Closing".into())]),
|
||
..Profile::default()
|
||
},
|
||
);
|
||
assert!(titled.diagnostics.is_empty(), "{:?}", titled.diagnostics);
|
||
assert_eq!(titled.rundown.unwrap().entries[1].title, "Closing");
|
||
}
|
||
#[test]
|
||
fn atomic_publication_preserves_source_and_existing_output() {
|
||
let dir = tempfile::tempdir().unwrap();
|
||
let input = dir.path().join("source.csv");
|
||
std::fs::write(&input, "source").unwrap();
|
||
let output = dir.path().join("out.json");
|
||
let a = analyze(&simple(), &Profile::default());
|
||
let cancel = AtomicBool::new(false);
|
||
export::write(&a, &input, &output, false, false, &cancel).unwrap();
|
||
let old = std::fs::read(&output).unwrap();
|
||
assert!(export::write(&a, &input, &output, true, false, &cancel).is_err());
|
||
assert_eq!(std::fs::read(&output).unwrap(), old);
|
||
assert!(export::write(&a, &input, &input, false, true, &cancel).is_err());
|
||
assert_eq!(std::fs::read_to_string(&input).unwrap(), "source");
|
||
assert!(export::write(&a, &input, &output, true, true, &AtomicBool::new(true)).is_err());
|
||
assert_eq!(std::fs::read(&output).unwrap(), old);
|
||
export::write(&a, &input, &output, true, true, &cancel).unwrap();
|
||
assert_eq!(
|
||
serde_json::from_slice::<serde_json::Value>(&std::fs::read(output).unwrap()).unwrap()["schema_version"],
|
||
1
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn xlsx_export_has_ontime_columns_notes_metadata_and_clock_strings() {
|
||
let source = table(&[
|
||
&["Start", "Duration", "Title", "Notes", "Video"],
|
||
&["09:00", "5 min", "Opening", "Ready & <go>", "Slides"],
|
||
&["09:10", "2 min", "Closing", "", "Camera"],
|
||
]);
|
||
let profile = Profile {
|
||
column_usage: BTreeMap::from([
|
||
("D".into(), "notes".into()),
|
||
("E".into(), "metadata".into()),
|
||
]),
|
||
..Profile::default()
|
||
};
|
||
let analysis = analyze(&source, &profile);
|
||
assert!(
|
||
analysis.diagnostics.is_empty(),
|
||
"{:?}",
|
||
analysis.diagnostics
|
||
);
|
||
let bytes = export::xlsx(analysis.rundown.as_ref().unwrap()).unwrap();
|
||
assert!(bytes.starts_with(b"PK"));
|
||
|
||
let dir = tempfile::tempdir().unwrap();
|
||
let path = dir.path().join("ontime.xlsx");
|
||
std::fs::write(&path, bytes).unwrap();
|
||
let tables = reader::read(&path).unwrap();
|
||
assert_eq!(tables.len(), 1);
|
||
assert_eq!(tables[0].name, "Ontime");
|
||
assert_eq!(
|
||
tables[0].rows[0]
|
||
.iter()
|
||
.map(|cell| cell.text.as_str())
|
||
.collect::<Vec<_>>(),
|
||
[
|
||
"Time Start",
|
||
"Time End",
|
||
"Duration",
|
||
"Cue",
|
||
"Title",
|
||
"Notes",
|
||
"Timer Type",
|
||
"Link Start",
|
||
"Colour",
|
||
"ID",
|
||
"Flag",
|
||
"Count to end",
|
||
"End Action",
|
||
"Warning Time",
|
||
"Danger Time",
|
||
"Skip",
|
||
"Video",
|
||
]
|
||
);
|
||
assert_eq!(tables[0].rows[1][0].text, "09:00:00");
|
||
assert_eq!(tables[0].rows[1][1].text, "09:05:00");
|
||
assert_eq!(tables[0].rows[1][2].text, "00:05:00");
|
||
assert_eq!(tables[0].rows[1][5].text, "Ready & <go>");
|
||
assert_eq!(tables[0].rows[1][6].text, "count-down");
|
||
assert_eq!(tables[0].rows[1][16].text, "Slides");
|
||
assert_eq!(tables[0].rows[2][0].text, "09:10:00");
|
||
|
||
// Keep XLSX playback settings identical to JSON, including unlinked starts
|
||
// on both sides of an intentional gap and duration-scaled warning thresholds.
|
||
let json = export::ontime(analysis.rundown.as_ref().unwrap()).unwrap();
|
||
let events = &json["rundowns"]["default"]["entries"];
|
||
for row in &tables[0].rows[1..] {
|
||
let event = &events[&row[9].text];
|
||
assert_eq!(row[7].text, "FALSE");
|
||
for (column, key) in [
|
||
(7, "linkStart"),
|
||
(10, "flag"),
|
||
(11, "countToEnd"),
|
||
(15, "skip"),
|
||
] {
|
||
assert_eq!(row[column].text == "TRUE", event[key].as_bool().unwrap());
|
||
}
|
||
for (column, key) in [
|
||
(5, "note"),
|
||
(6, "timerType"),
|
||
(8, "colour"),
|
||
(12, "endAction"),
|
||
] {
|
||
assert_eq!(row[column].text, event[key].as_str().unwrap());
|
||
}
|
||
for (column, key) in [(13, "timeWarning"), (14, "timeDanger")] {
|
||
assert_eq!(
|
||
row[column].text,
|
||
rundown_converter::time::display(event[key].as_i64().unwrap())
|
||
);
|
||
}
|
||
}
|
||
|
||
// Metadata must not shadow Ontime's standard timing fields.
|
||
let mut rundown = analysis.rundown.unwrap();
|
||
rundown
|
||
.mapping
|
||
.column_labels
|
||
.insert("E".into(), "Time Start".into());
|
||
std::fs::write(&path, export::xlsx(&rundown).unwrap()).unwrap();
|
||
let tables = reader::read(&path).unwrap();
|
||
assert_eq!(tables[0].rows[0][0].text, "Time Start");
|
||
assert_eq!(tables[0].rows[0][16].text, "Time Start (E)");
|
||
}
|
||
#[test]
|
||
fn invalid_or_cancelled_analysis_never_exports() {
|
||
let a = pipeline::analyze(
|
||
&simple(),
|
||
&Profile::default(),
|
||
&AtomicBool::new(true),
|
||
|_, _| panic!("cancel first"),
|
||
);
|
||
assert_eq!(a.diagnostics[0].code, "CANCELLED");
|
||
let dir = tempfile::tempdir().unwrap();
|
||
let p = dir.path().join("out.json");
|
||
assert!(export::write(&a, &p, &p, false, false, &AtomicBool::new(false)).is_err());
|
||
assert!(!p.exists());
|
||
let mut r = analyze(&simple(), &Profile::default()).rundown.unwrap();
|
||
r.entries[0].duration_ms = -1;
|
||
assert!(export::ontime(&r).is_err());
|
||
}
|
||
#[test]
|
||
fn clock_units_and_column_roundtrips() {
|
||
for (s, expected) in [
|
||
("9h", 32_400_000),
|
||
("9H30", 34_200_000),
|
||
("2:30 PM", 52_200_000),
|
||
("12:00 AM", 0),
|
||
("09:30:01", 34_201_000),
|
||
] {
|
||
assert_eq!(
|
||
time::clock(&Cell {
|
||
text: s.into(),
|
||
..Cell::default()
|
||
}),
|
||
Some(expected)
|
||
);
|
||
}
|
||
for s in ["24:00", "13:00 PM", "09:90", "9", "tomorrow"] {
|
||
assert!(
|
||
time::clock(&Cell {
|
||
text: s.into(),
|
||
..Cell::default()
|
||
})
|
||
.is_none()
|
||
);
|
||
}
|
||
assert_eq!(
|
||
time::duration(
|
||
&Cell {
|
||
text: "1h10".into(),
|
||
..Cell::default()
|
||
},
|
||
None
|
||
),
|
||
Some(4_200_000)
|
||
);
|
||
assert_eq!(
|
||
time::duration(
|
||
&Cell {
|
||
text: "1,5 min".into(),
|
||
..Cell::default()
|
||
},
|
||
None
|
||
),
|
||
Some(90_000)
|
||
);
|
||
for i in [0, 25, 26, 701, 16383] {
|
||
assert_eq!(column_index(&column_name(i)), Some(i));
|
||
}
|
||
assert_eq!(column_index("A1"), None);
|
||
}
|
||
#[test]
|
||
fn csv_bom_quotes_semicolon_and_unsupported_pdf() {
|
||
let dir = tempfile::tempdir().unwrap();
|
||
let path = dir.path().join("show.csv");
|
||
std::fs::write(
|
||
&path,
|
||
"\u{feff}Start;Duration;Title\n09:00;2 min;\"A; B\"\n",
|
||
)
|
||
.unwrap();
|
||
let t = reader::read(&path).unwrap();
|
||
assert_eq!(t[0].rows[1][2].text, "A; B");
|
||
assert!(analyze(&t[0], &Profile::default()).diagnostics.is_empty());
|
||
let pdf = dir.path().join("show.pdf");
|
||
std::fs::write(&pdf, "%PDF").unwrap();
|
||
assert!(
|
||
reader::read(&pdf)
|
||
.unwrap_err()
|
||
.to_string()
|
||
.contains("PDF_REQUIRES_REVIEW")
|
||
);
|
||
}
|
||
fn workbook(path: &std::path::Path) {
|
||
let mut z = zip::ZipWriter::new(std::fs::File::create(path).unwrap());
|
||
let parts = [
|
||
(
|
||
"xl/workbook.xml",
|
||
r#"<workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="Demo" r:id="rId1"/></sheets></workbook>"#,
|
||
),
|
||
(
|
||
"xl/_rels/workbook.xml.rels",
|
||
r#"<Relationships><Relationship Id="rId1" Target="worksheets/sheet1.xml"/></Relationships>"#,
|
||
),
|
||
(
|
||
"xl/styles.xml",
|
||
r#"<styleSheet><cellXfs><xf numFmtId="0"/><xf numFmtId="20"/></cellXfs></styleSheet>"#,
|
||
),
|
||
(
|
||
"xl/sharedStrings.xml",
|
||
r#"<sst><si><t>Start</t></si><si><t>Duration</t></si><si><t>Title</t></si></sst>"#,
|
||
),
|
||
(
|
||
"xl/worksheets/sheet1.xml",
|
||
r#"<worksheet><sheetData><row r="1"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c><c r="C1" t="s"><v>2</v></c></row><row r="2"><c r="A2" s="1"><v>0.5</v></c><c r="B2" s="1"><v>0.006944444444444444</v></c><c r="C2" t="inlineStr"><is><t>Talk</t></is></c></row><row r="3"><c r="C3" t="inlineStr"><is><t>Continuation</t></is></c></row></sheetData><mergeCells><mergeCell ref="A2:A3"/><mergeCell ref="B2:B3"/></mergeCells></worksheet>"#,
|
||
),
|
||
];
|
||
for (name, text) in parts {
|
||
z.start_file(name, zip::write::SimpleFileOptions::default())
|
||
.unwrap();
|
||
z.write_all(text.as_bytes()).unwrap();
|
||
}
|
||
z.finish().unwrap();
|
||
}
|
||
#[test]
|
||
fn xlsx_typed_times_and_merges_without_private_fixtures() {
|
||
let dir = tempfile::tempdir().unwrap();
|
||
let path = dir.path().join("show.xlsx");
|
||
workbook(&path);
|
||
let tables = reader::read(&path).unwrap();
|
||
assert_eq!(tables[0].merges.len(), 2);
|
||
let a = analyze(&tables[0], &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries[0].duration_ms, 600_000);
|
||
assert_eq!(r.entries[0].source_rows.len(), 2);
|
||
}
|
||
#[test]
|
||
fn profile_and_empty_sheet_errors_are_actionable() {
|
||
assert!(detect::infer(&table(&[]), &Profile::default()).is_err());
|
||
for profile in [
|
||
Profile {
|
||
header_row: Some(0),
|
||
..Profile::default()
|
||
},
|
||
Profile {
|
||
columns: BTreeMap::from([("start".into(), "ZZ".into())]),
|
||
..Profile::default()
|
||
},
|
||
Profile {
|
||
duration_unit: Some("guess".into()),
|
||
..Profile::default()
|
||
},
|
||
] {
|
||
assert!(!analyze(&simple(), &profile).diagnostics.is_empty());
|
||
}
|
||
}
|
||
#[test]
|
||
fn formula_without_cached_value_is_not_silently_skipped() {
|
||
let mut t = simple();
|
||
t.rows[1][0].text.clear();
|
||
t.rows[1][0].formula = Some("A3".into());
|
||
assert!(
|
||
analyze(&t, &Profile::default())
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "FORMULA_WITHOUT_VALUE")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn full_width_merged_lunch_is_a_gap_not_a_discarded_heading() {
|
||
let mut t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["11:00", "60 min", "Morning"],
|
||
&["Lunch", "", ""],
|
||
&["13:30", "10 min", "Restart"],
|
||
]);
|
||
t.merges.push(Merge {
|
||
first_row: 2,
|
||
last_row: 2,
|
||
first_col: 0,
|
||
last_col: 2,
|
||
});
|
||
let map = detect::infer(&t, &Profile::default()).unwrap();
|
||
let gaps = pipeline::identify_gaps(&t, &map, &Profile::default());
|
||
assert_eq!(gaps.len(), 1);
|
||
assert_eq!(gaps[0].title, "Lunch");
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
assert_eq!(a.rundown.unwrap().gaps[0].end_ms, Some(48_600_000));
|
||
}
|
||
#[test]
|
||
fn stage_two_identifies_an_unnamed_gap_before_constructing_events() {
|
||
let t = simple();
|
||
let map = detect::infer(&t, &Profile::default()).unwrap();
|
||
let gaps = pipeline::identify_gaps(&t, &map, &Profile::default());
|
||
assert_eq!(gaps.len(), 1);
|
||
assert_eq!(gaps[0].start_ms, Some(43_200_000));
|
||
}
|
||
#[test]
|
||
fn negative_subhour_duration_does_not_lose_its_sign() {
|
||
assert_eq!(
|
||
time::duration(
|
||
&Cell {
|
||
text: "-00:30".into(),
|
||
..Cell::default()
|
||
},
|
||
Some("hh:mm")
|
||
),
|
||
Some(-1_800_000)
|
||
);
|
||
assert_eq!(
|
||
time::duration(
|
||
&Cell {
|
||
text: "-1h30".into(),
|
||
..Cell::default()
|
||
},
|
||
None
|
||
),
|
||
Some(-5_400_000)
|
||
);
|
||
assert!(
|
||
time::duration(
|
||
&Cell {
|
||
text: "1h-30m".into(),
|
||
..Cell::default()
|
||
},
|
||
None
|
||
)
|
||
.is_none()
|
||
);
|
||
}
|
||
#[test]
|
||
fn stale_profiles_and_invalid_row_classifications_fail_early() {
|
||
let t = simple();
|
||
for p in [
|
||
Profile {
|
||
expected_headers: BTreeMap::from([("A".into(), "Something else".into())]),
|
||
..Profile::default()
|
||
},
|
||
Profile {
|
||
row_kinds: BTreeMap::from([(2, "guessed".into())]),
|
||
..Profile::default()
|
||
},
|
||
] {
|
||
assert_eq!(analyze(&t, &p).completed_stage, 0);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn explicit_event_is_not_downgraded_by_general_note_policy() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "10 min", "A"],
|
||
&["", "", "Needs a timer"],
|
||
]);
|
||
let p = Profile {
|
||
untimed_as_notes: true,
|
||
row_kinds: BTreeMap::from([(3, "event".into())]),
|
||
..Profile::default()
|
||
};
|
||
assert!(
|
||
analyze(&t, &p)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "MISSING_DURATION")
|
||
);
|
||
}
|
||
#[test]
|
||
fn explicit_duration_can_replace_a_missing_formula_result() {
|
||
let mut t = simple();
|
||
t.rows[1][1].text.clear();
|
||
t.rows[1][1].formula = Some("B3".into());
|
||
let p = Profile {
|
||
durations: BTreeMap::from([(2, "15 min".into())]),
|
||
..Profile::default()
|
||
};
|
||
assert!(analyze(&t, &p).diagnostics.is_empty());
|
||
}
|
||
|
||
#[test]
|
||
fn notes_metadata_and_ignored_columns_have_distinct_ontime_destinations() {
|
||
let t = table(&[
|
||
&[
|
||
"Start", "Timer", "Timer", "Title", "Speaker", "Private", "Notes",
|
||
],
|
||
&[
|
||
"09:00",
|
||
"5 min",
|
||
"Operator reference",
|
||
"Opening",
|
||
"Alice",
|
||
"SECRET ONE",
|
||
"Microphone 1",
|
||
],
|
||
&[
|
||
"",
|
||
"",
|
||
"",
|
||
"Stage direction",
|
||
"Bob",
|
||
"SECRET TWO",
|
||
"Move lectern",
|
||
],
|
||
&["", "", "", "", "", "SECRET ONLY ROW", ""],
|
||
&[
|
||
"09:05",
|
||
"5 min",
|
||
"Backup reference",
|
||
"Closing",
|
||
"Carol",
|
||
"SECRET THREE",
|
||
"Microphone 2",
|
||
],
|
||
]);
|
||
let p = Profile {
|
||
column_usage: BTreeMap::from([
|
||
("C".into(), "metadata".into()),
|
||
("E".into(), "metadata".into()),
|
||
("f".into(), "ignore".into()),
|
||
("G".into(), "notes".into()),
|
||
]),
|
||
row_kinds: BTreeMap::from([(3, "note".into())]),
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &p);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.mapping.duration, Some(1));
|
||
assert_eq!(r.mapping.column_usage["F"], "ignore");
|
||
assert_eq!(r.entries.len(), 2);
|
||
assert_eq!(r.entries[0].source_rows[0].cells["F"].text, "SECRET ONE");
|
||
assert_eq!(r.entries[0].source_rows[1].cells["F"].text, "SECRET TWO");
|
||
let json = export::ontime(&r).unwrap();
|
||
let note = json["rundowns"]["default"]["entries"][&r.entries[0].id]["note"]
|
||
.as_str()
|
||
.unwrap();
|
||
for text in ["Microphone 1", "Move lectern"] {
|
||
assert!(note.contains(text), "Missing note {text}");
|
||
}
|
||
for text in ["Operator reference", "Alice", "Bob"] {
|
||
assert!(!note.contains(text), "Metadata leaked into notes: {text}");
|
||
}
|
||
assert!(!note.contains("derived from"));
|
||
let custom = &json["rundowns"]["default"]["entries"][&r.entries[0].id]["custom"];
|
||
assert_eq!(custom["timer"], "Operator reference");
|
||
assert_eq!(custom["speaker"], "Alice\nBob");
|
||
assert_eq!(json["customFields"]["timer"]["label"], "Timer");
|
||
assert_eq!(json["customFields"]["speaker"]["type"], "text");
|
||
assert!(!json.to_string().contains("SECRET"));
|
||
let restored: Rundown = serde_json::from_str(&serde_json::to_string(&r).unwrap()).unwrap();
|
||
assert!(
|
||
!export::ontime(&restored)
|
||
.unwrap()
|
||
.to_string()
|
||
.contains("SECRET")
|
||
);
|
||
let restored_profile: Profile =
|
||
serde_json::from_str(&serde_json::to_string(&p).unwrap()).unwrap();
|
||
assert_eq!(restored_profile.usage(5), Some("ignore"));
|
||
}
|
||
|
||
#[test]
|
||
fn unknown_columns_default_to_ignore_and_production_headers_become_custom_fields() {
|
||
let t = table(&[
|
||
&[
|
||
"Start",
|
||
"Duration",
|
||
"Title",
|
||
"Vidéo",
|
||
"Light",
|
||
"Lumière",
|
||
"Lumiere",
|
||
"Son",
|
||
"Sound",
|
||
"PowerPoint",
|
||
"Slides",
|
||
"Notes",
|
||
"Speaker",
|
||
],
|
||
&[
|
||
"09:00", "5 min", "Opening", "Roll VT", "Preset A", "Blue", "Wash", "Mic 1", "Walk-in",
|
||
"Deck A", "1–3", "Stand by", "Alice",
|
||
],
|
||
&["", "", "", "", "", "", "", "", "", "", "", "", "Ghost"],
|
||
&[
|
||
"09:05",
|
||
"5 min",
|
||
"Closing",
|
||
"Logo",
|
||
"Preset B",
|
||
"Blackout",
|
||
"Spot",
|
||
"Mic 2",
|
||
"Sting",
|
||
"Deck B",
|
||
"4–6",
|
||
"Clear stage",
|
||
"Bob",
|
||
],
|
||
]);
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
for column in ["D", "E", "F", "G", "H", "I", "J", "K"] {
|
||
assert_eq!(r.mapping.column_usage[column], "metadata", "{column}");
|
||
}
|
||
assert_eq!(r.mapping.column_usage["L"], "notes");
|
||
assert_eq!(r.mapping.column_usage["M"], "ignore");
|
||
let json = export::ontime(&r).unwrap();
|
||
let event = &json["rundowns"]["default"]["entries"][&r.entries[0].id];
|
||
assert_eq!(event["note"], "Stand by");
|
||
assert_eq!(event["custom"]["video"], "Roll VT");
|
||
assert_eq!(json["customFields"]["video"]["label"], "Vidéo");
|
||
assert!(!json.to_string().contains("Alice"));
|
||
assert!(!json.to_string().contains("Ghost"));
|
||
assert!(!event["note"].as_str().unwrap().contains("derived from"));
|
||
}
|
||
|
||
#[test]
|
||
fn column_usage_excludes_data_candidates_and_rejects_conflicting_profiles() {
|
||
let t = table(&[
|
||
&["Start", "End", "Reference", "Title"],
|
||
&["09:00", "09:05", "1 min", "Opening"],
|
||
&["09:05", "09:10", "2 min", "Closing"],
|
||
]);
|
||
for usage in ["notes", "metadata", "ignore"] {
|
||
let p = Profile {
|
||
column_usage: BTreeMap::from([("C".into(), usage.into())]),
|
||
..Default::default()
|
||
};
|
||
let a = analyze(&t, &p);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
assert_eq!(a.mapping.unwrap().duration, None);
|
||
assert_eq!(a.rundown.unwrap().entries[0].duration_ms, 300_000);
|
||
}
|
||
for usages in [
|
||
vec![("Z", "ignore")],
|
||
vec![("C", "unknown")],
|
||
vec![("C", "ignore"), ("c", "metadata")],
|
||
] {
|
||
let p = Profile {
|
||
column_usage: usages
|
||
.into_iter()
|
||
.map(|(k, v)| (k.into(), v.into()))
|
||
.collect(),
|
||
..Default::default()
|
||
};
|
||
assert!(
|
||
analyze(&t, &p)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INVALID_COLUMN_USAGE")
|
||
);
|
||
}
|
||
let p = Profile {
|
||
columns: BTreeMap::from([("start".into(), "A".into())]),
|
||
column_usage: BTreeMap::from([("A".into(), "ignore".into())]),
|
||
..Default::default()
|
||
};
|
||
assert!(
|
||
analyze(&t, &p)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INVALID_MAPPING")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn gap_choices_adjust_adjacent_timers_and_can_be_reversed() {
|
||
for named in [false, true] {
|
||
let t = if named {
|
||
table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["11:45", "15 min", "Morning"],
|
||
&["", "", "Lunch break"],
|
||
&["13:30", "20 min", "Afternoon"],
|
||
])
|
||
} else {
|
||
simple()
|
||
};
|
||
let baseline = analyze(&t, &Profile::default()).rundown.unwrap();
|
||
let key = baseline.gaps[0].key();
|
||
for action in ["keep", "extend_previous", "add_to_next"] {
|
||
let mut profile = Profile::default();
|
||
profile.gap_resolutions.insert(key.clone(), action.into());
|
||
// Profiles saved by either interface preserve the choice.
|
||
let profile: Profile =
|
||
serde_json::from_str(&serde_json::to_string(&profile).unwrap()).unwrap();
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 2);
|
||
assert_eq!(r.gaps.len(), usize::from(action == "keep"));
|
||
assert_eq!(r.resolved_gaps.len(), usize::from(action != "keep"));
|
||
assert_eq!(r.entries[0].start_ms, baseline.entries[0].start_ms);
|
||
assert_eq!(r.entries[1].end_ms, baseline.entries[1].end_ms);
|
||
if action == "extend_previous" {
|
||
assert_eq!(r.entries[0].end_ms, baseline.entries[1].start_ms);
|
||
assert_eq!(r.entries[1].start_ms, baseline.entries[1].start_ms);
|
||
} else if action == "add_to_next" {
|
||
assert_eq!(r.entries[1].start_ms, baseline.entries[0].end_ms);
|
||
assert_eq!(r.entries[0].end_ms, baseline.entries[0].end_ms);
|
||
assert!(!r.entries[1].explicit_start);
|
||
}
|
||
let exported = export::ontime(&r).unwrap();
|
||
for e in &r.entries {
|
||
let timer = &exported["rundowns"]["default"]["entries"][&e.id];
|
||
assert_eq!(timer["duration"], e.end_ms - e.start_ms);
|
||
assert_eq!(timer["timeStart"], e.start_ms);
|
||
}
|
||
assert_eq!(
|
||
serde_json::to_value(&r).unwrap(),
|
||
serde_json::to_value(analyze(&t, &profile).rundown.unwrap()).unwrap()
|
||
);
|
||
}
|
||
let restored = analyze(&t, &Profile::default()).rundown.unwrap();
|
||
assert_eq!(
|
||
serde_json::to_value(restored).unwrap(),
|
||
serde_json::to_value(baseline).unwrap()
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn invalid_or_unavailable_gap_choices_block_export() {
|
||
let t = simple();
|
||
let baseline = analyze(&t, &Profile::default()).rundown.unwrap();
|
||
let mut profile = Profile::default();
|
||
profile
|
||
.gap_resolutions
|
||
.insert(baseline.gaps[0].key(), "unknown".into());
|
||
assert!(
|
||
analyze(&t, &profile)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INVALID_GAP_RESOLUTION")
|
||
);
|
||
profile.gap_resolutions = [("stale".into(), "extend_previous".into())]
|
||
.into_iter()
|
||
.collect();
|
||
assert!(
|
||
analyze(&t, &profile)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INVALID_GAP_RESOLUTION")
|
||
);
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "30 min", "Lunch break"],
|
||
&["09:30", "20 min", "Opening"],
|
||
]);
|
||
profile = Profile::default();
|
||
profile.row_kinds.insert(2, "gap".into());
|
||
let baseline = analyze(&t, &profile).rundown.unwrap();
|
||
profile.gap_resolutions = [(baseline.gaps[0].key(), "extend_previous".into())]
|
||
.into_iter()
|
||
.collect();
|
||
let a = analyze(&t, &profile);
|
||
assert!(
|
||
a.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "GAP_RESOLUTION_UNAVAILABLE")
|
||
);
|
||
assert_eq!(a.rundown.unwrap().gaps.len(), 1);
|
||
}
|
||
|
||
#[test]
|
||
fn excel_scientific_notation_durations_reach_export_as_milliseconds() {
|
||
let mut t = simple();
|
||
t.rows[1][1] = Cell {
|
||
text: "6.9444444444444441E-3".into(),
|
||
numeric: true,
|
||
time_style: true,
|
||
..Default::default()
|
||
};
|
||
let a = analyze(&t, &Profile::default());
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries[0].duration_ms, 600_000);
|
||
let json = export::ontime(&r).unwrap();
|
||
assert_eq!(
|
||
json["rundowns"]["default"]["entries"][&r.entries[0].id]["duration"],
|
||
600_000
|
||
);
|
||
t.rows[1][1].text = "-6.9444444444444441E-3".into();
|
||
assert_eq!(time::duration(&t.rows[1][1], None), Some(-600_000));
|
||
assert!(!analyze(&t, &Profile::default()).diagnostics.is_empty());
|
||
}
|
||
|
||
#[test]
|
||
fn warning_policy_excludes_rows_rechecks_and_can_be_disabled() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "5 min", "Opening"],
|
||
&["", "", "Stage direction"],
|
||
&["09:10", "5 min", "Closing"],
|
||
]);
|
||
let profile = Profile {
|
||
ignore_warnings: true,
|
||
..Default::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
assert_eq!(a.completed_stage, 4);
|
||
assert_eq!(a.automatically_ignored_rows, [3]);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 2);
|
||
assert_eq!(r.gaps.len(), 1);
|
||
assert!(export::ontime(&r).is_ok());
|
||
assert!(profile.row_kinds.is_empty());
|
||
assert_eq!(
|
||
analyze(&t, &Profile::default()).diagnostics[0].code,
|
||
"UNTIMED_ROW"
|
||
);
|
||
let both = Profile {
|
||
untimed_as_notes: true,
|
||
..profile.clone()
|
||
};
|
||
let a = analyze(&t, &both);
|
||
assert!(a.diagnostics.is_empty());
|
||
assert!(a.automatically_ignored_rows.is_empty());
|
||
assert_eq!(a.rundown.unwrap().entries[0].source_rows.len(), 2);
|
||
let mut overlap = t.clone();
|
||
overlap.rows[3][0].text = "09:03".into();
|
||
let a = analyze(&overlap, &profile);
|
||
assert_eq!(a.automatically_ignored_rows, [3]);
|
||
assert!(a.diagnostics.iter().any(|d| d.code == "OVERLAP"));
|
||
assert!(export::ontime(&a.rundown.unwrap()).is_err());
|
||
let mut ambiguity = t.clone();
|
||
ambiguity.rows[0][2].text = "Timer".into();
|
||
let a = analyze(&ambiguity, &profile);
|
||
assert!(a.mapping.is_none());
|
||
assert!(a.automatically_ignored_rows.is_empty());
|
||
let explicit = Profile {
|
||
row_kinds: [(3, "event".into())].into_iter().collect(),
|
||
..profile
|
||
};
|
||
let a = analyze(&t, &explicit);
|
||
assert!(!a.diagnostics.is_empty());
|
||
assert!(a.automatically_ignored_rows.is_empty());
|
||
}
|
||
|
||
#[test]
|
||
fn split_combines_with_each_duration_policy_and_keeps_each_margin() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["08:00", "20 min + 5 min\n10 min + 2 min", "Talks"],
|
||
]);
|
||
for (mode, durations, margins) in [
|
||
("minimum", [5, 2], [0, 0]),
|
||
("maximum", [20, 10], [0, 0]),
|
||
("sum", [25, 12], [0, 0]),
|
||
("margin", [20, 10], [5, 2]),
|
||
] {
|
||
let profile = Profile {
|
||
duration_mode: Some(mode.into()),
|
||
duration_split: true,
|
||
..Profile::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{mode}: {:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 2);
|
||
assert_eq!(r.entries[0].duration_ms, durations[0] * 60_000);
|
||
assert_eq!(r.entries[1].duration_ms, durations[1] * 60_000);
|
||
assert_eq!(
|
||
r.entries[1].start_ms,
|
||
r.entries[0].end_ms + margins[0] * 60_000
|
||
);
|
||
if mode == "margin" {
|
||
assert_eq!(r.gaps.len(), 2);
|
||
for (gap, minutes) in r.gaps.iter().zip(margins) {
|
||
assert_eq!(
|
||
gap.end_ms.unwrap() - gap.start_ms.unwrap(),
|
||
minutes * 60_000
|
||
);
|
||
}
|
||
}
|
||
assert!(export::ontime(&r).is_ok());
|
||
}
|
||
let mut invalid = t;
|
||
invalid.rows[1][1].text = "20 min\nunreadable duration".into();
|
||
let a = analyze(
|
||
&invalid,
|
||
&Profile {
|
||
duration_mode: Some("maximum".into()),
|
||
duration_split: true,
|
||
..Profile::default()
|
||
},
|
||
);
|
||
assert!(
|
||
a.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INCONSISTENT_COLUMN_MEANING")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn secondary_title_policies_preserve_distinct_export_destinations() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title", "Presentation"],
|
||
&["09:00", "5 min", "Session", "Talk"],
|
||
&["09:05", "5 min", "Closing", ""],
|
||
]);
|
||
for mode in ["either", "merge", "notes", "metadata"] {
|
||
let profile = Profile {
|
||
columns: BTreeMap::from([("secondary_title".into(), "D".into())]),
|
||
secondary_title_mode: Some(mode.into()),
|
||
..Default::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{mode}: {:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(
|
||
r.entries[0].title,
|
||
if mode == "merge" {
|
||
"Session — Talk"
|
||
} else {
|
||
"Session"
|
||
}
|
||
);
|
||
assert_eq!(r.entries[1].title, "Closing");
|
||
let json = export::ontime(&r).unwrap();
|
||
let event = &json["rundowns"]["default"]["entries"][&r.entries[0].id];
|
||
assert_eq!(event["note"], if mode == "notes" { "Talk" } else { "" });
|
||
if mode == "metadata" {
|
||
assert_eq!(event["custom"]["presentation"], "Talk");
|
||
} else {
|
||
assert!(event["custom"].as_object().unwrap().is_empty());
|
||
}
|
||
assert_eq!(
|
||
r.mapping.column_usage.get("D").map(String::as_str),
|
||
match mode {
|
||
"notes" => Some("notes"),
|
||
"metadata" => Some("metadata"),
|
||
_ => None,
|
||
}
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn secondary_title_merge_previous_carries_only_primary_titles() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title", "Subtitle"],
|
||
&["09:00", "5 min", "", "Before first title"],
|
||
&["09:05", "5 min", "Session A", "Talk 1"],
|
||
&["09:10", "5 min", "", "Talk 2"],
|
||
&["", "", "Ignored title", ""],
|
||
&["09:15", "5 min", "", "Talk 3"],
|
||
&["09:20", "5 min", "Session B", "Talk 4"],
|
||
&["09:25", "5 min", "", "Talk 5"],
|
||
]);
|
||
let profile = Profile {
|
||
columns: BTreeMap::from([("secondary_title".into(), "D".into())]),
|
||
secondary_title_mode: Some("merge_previous".into()),
|
||
row_kinds: BTreeMap::from([(5, "ignore".into())]),
|
||
titles: BTreeMap::from([(4, "Corrected row title".into())]),
|
||
..Profile::default()
|
||
};
|
||
let profile = serde_json::from_str(&serde_json::to_string(&profile).unwrap()).unwrap();
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let rundown = a.rundown.unwrap();
|
||
assert_eq!(
|
||
rundown
|
||
.entries
|
||
.iter()
|
||
.map(|e| e.title.as_str())
|
||
.collect::<Vec<_>>(),
|
||
[
|
||
"Before first title",
|
||
"Session A - Talk 1",
|
||
"Corrected row title",
|
||
"Session A - Talk 3",
|
||
"Session B - Talk 4",
|
||
"Session B - Talk 5",
|
||
]
|
||
);
|
||
let json = export::ontime(&rundown).unwrap();
|
||
for entry in &rundown.entries {
|
||
assert_eq!(
|
||
json["rundowns"]["default"]["entries"][&entry.id]["title"],
|
||
entry.title
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn secondary_title_fallback_respects_empty_cells_and_explicit_corrections() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title", "Title"],
|
||
&["09:00", "5 min", "", "Fallback"],
|
||
&["09:05", "5 min", "Main", "Secondary"],
|
||
]);
|
||
let mut profile = Profile {
|
||
columns: BTreeMap::from([("secondary_title".into(), "D".into())]),
|
||
..Default::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries[0].title, "Fallback");
|
||
assert_eq!(r.entries[1].title, "Main");
|
||
profile.titles.insert(2, "Corrected".into());
|
||
profile.secondary_title_mode = Some("merge".into());
|
||
let a = analyze(&t, &profile);
|
||
assert_eq!(a.rundown.unwrap().entries[0].title, "Corrected");
|
||
profile.secondary_title_mode = Some("invalid".into());
|
||
assert!(
|
||
analyze(&t, &profile)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INVALID_SECONDARY_TITLE_MODE")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn split_window_bounds_the_total_and_preserves_slack() {
|
||
let t = table(&[
|
||
&["Start–end", "Duration", "Title"],
|
||
&["10:00-10:30", "10 min + 5 min\n10 min + 5 min", "Talks"],
|
||
&["10:30-10:40", "10 min", "Next"],
|
||
]);
|
||
let profile = Profile {
|
||
header_row: Some(1),
|
||
columns: BTreeMap::from([
|
||
("start_end".into(), "A".into()),
|
||
("duration".into(), "B".into()),
|
||
("title".into(), "C".into()),
|
||
]),
|
||
duration_split: true,
|
||
duration_mode: Some("maximum".into()),
|
||
..Default::default()
|
||
};
|
||
for mode in ["maximum", "sum", "margin"] {
|
||
let p = Profile {
|
||
duration_mode: Some(mode.into()),
|
||
..profile.clone()
|
||
};
|
||
let a = analyze(&t, &p);
|
||
assert!(a.diagnostics.is_empty(), "{mode}: {:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 3);
|
||
assert_eq!(r.entries[2].start_ms, (10 * 60 + 30) * 60_000);
|
||
if mode == "maximum" {
|
||
assert!(
|
||
r.gaps
|
||
.iter()
|
||
.any(|g| g.start_ms == Some((10 * 60 + 20) * 60_000)
|
||
&& g.end_ms == Some((10 * 60 + 30) * 60_000))
|
||
);
|
||
}
|
||
assert!(export::ontime(&r).is_ok());
|
||
}
|
||
let mut overflow = t;
|
||
overflow.rows[1][1].text = "20 min\n20 min".into();
|
||
let a = analyze(&overflow, &profile);
|
||
assert!(
|
||
a.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "CONFLICTING_TIMES" && d.message.contains("sum of split"))
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn margin_toggle_combines_with_minimum_maximum_sum_and_split() {
|
||
for split in [false, true] {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&[
|
||
"09:00",
|
||
if split {
|
||
"20 min + 5 min\n20 min + 5 min"
|
||
} else {
|
||
"20 min + 5 min"
|
||
},
|
||
"Talks",
|
||
],
|
||
]);
|
||
for (mode, duration, margin) in [("minimum", 5, 2), ("maximum", 20, 2), ("sum", 25, 2)] {
|
||
let profile = Profile {
|
||
duration_mode: Some(mode.into()),
|
||
duration_add_margin: true,
|
||
duration_margin: Some("2 min".into()),
|
||
duration_split: split,
|
||
..Default::default()
|
||
};
|
||
let a = analyze(&t, &profile);
|
||
assert!(
|
||
a.diagnostics.is_empty(),
|
||
"{mode}/{split}: {:?}",
|
||
a.diagnostics
|
||
);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), if split { 2 } else { 1 });
|
||
assert!(r.entries.iter().all(|e| e.duration_ms == duration * 60_000));
|
||
assert_eq!(r.gaps.len(), if margin == 0 { 0 } else { r.entries.len() });
|
||
assert!(
|
||
r.gaps
|
||
.iter()
|
||
.all(|g| g.end_ms.unwrap() - g.start_ms.unwrap() == margin * 60_000)
|
||
);
|
||
if split {
|
||
assert_eq!(
|
||
r.entries[1].start_ms,
|
||
9 * 3_600_000 + (duration + margin) * 60_000
|
||
);
|
||
}
|
||
assert!(export::ontime(&r).is_ok());
|
||
}
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn splitting_precedes_every_operation_and_export_keeps_independent_results() {
|
||
for (separator, text) in [
|
||
("\\n", "20 min + 5 min\n10 min + 2 min\n3 min"),
|
||
("|", "20 min + 5 min|10 min + 2 min|3 min"),
|
||
(
|
||
"\\n\\n",
|
||
"09:00-09:25\n20 min + 5 min\n\n09:25-09:37\n10 min + 2 min\n\n3 min",
|
||
),
|
||
] {
|
||
let t = table(&[&["Start", "Duration", "Title"], &["09:00", text, "Talks"]]);
|
||
for (mode, minutes) in [
|
||
("sum", [25, 12, 3]),
|
||
("minimum", [5, 2, 3]),
|
||
("maximum", [20, 10, 3]),
|
||
] {
|
||
for margin in [false, true] {
|
||
let p = Profile {
|
||
duration_mode: Some(mode.into()),
|
||
duration_split: true,
|
||
duration_separator: Some(separator.into()),
|
||
duration_add_margin: margin,
|
||
duration_margin: Some("2 min".into()),
|
||
..Default::default()
|
||
};
|
||
let a = analyze(&t, &p);
|
||
assert!(
|
||
a.diagnostics.is_empty(),
|
||
"{mode}/{separator}: {:?}",
|
||
a.diagnostics
|
||
);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 3);
|
||
let json = export::ontime(&r).unwrap();
|
||
for (entry, minutes) in r.entries.iter().zip(minutes) {
|
||
assert_eq!(entry.duration_ms, minutes * 60_000);
|
||
assert_eq!(
|
||
json["rundowns"]["default"]["entries"][&entry.id]["duration"],
|
||
minutes * 60_000
|
||
);
|
||
}
|
||
if margin {
|
||
assert_eq!(
|
||
r.entries[1].start_ms,
|
||
9 * 3_600_000 + (minutes[0] + 2) * 60_000
|
||
);
|
||
assert_eq!(
|
||
r.entries[2].start_ms,
|
||
9 * 3_600_000 + (minutes[0] + minutes[1] + 4) * 60_000
|
||
);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn fixed_margin_requires_a_value_and_applies_to_overrides_and_derived_durations() {
|
||
let t = table(&[&["Start", "End", "Title"], &["09:00", "09:10", "Talk"]]);
|
||
for value in [None, Some(""), Some("2"), Some("-2 min"), Some("0 min")] {
|
||
let p = Profile {
|
||
duration_add_margin: true,
|
||
duration_margin: value.map(str::to_string),
|
||
..Default::default()
|
||
};
|
||
assert!(
|
||
analyze(&t, &p)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INVALID_MARGIN")
|
||
);
|
||
}
|
||
for corrected in [false, true] {
|
||
let mut p = Profile {
|
||
duration_add_margin: true,
|
||
duration_margin: Some("30 s".into()),
|
||
..Default::default()
|
||
};
|
||
if corrected {
|
||
p.durations.insert(2, "10 min".into());
|
||
}
|
||
let a = analyze(&t, &p);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries[0].duration_ms, 600_000);
|
||
assert_eq!(r.gaps.len(), 1);
|
||
assert_eq!(r.gaps[0].start_ms, Some(r.entries[0].end_ms));
|
||
assert_eq!(r.gaps[0].end_ms, Some(r.entries[0].end_ms + 30_000));
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn upper_median_duration_handles_odd_even_duplicates_and_single_values() {
|
||
for (text, expected) in [
|
||
("20 min + 5 min + 10 min", 600_000),
|
||
("20 min + 5 min", 1_200_000),
|
||
("40 min + 5 min + 20 min + 10 min", 1_200_000),
|
||
("20 min + 5 min + 5 min", 300_000),
|
||
("3 min", 180_000),
|
||
] {
|
||
let cell = Cell {
|
||
text: text.into(),
|
||
..Default::default()
|
||
};
|
||
assert_eq!(
|
||
time::select_durations(&cell, None, Some("median"), None)
|
||
.unwrap()
|
||
.events,
|
||
[expected]
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn upper_median_is_applied_per_split_entry_with_independent_fixed_margins() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "20 min + 5 min + 10 min\n20 min + 5 min", "Talks"],
|
||
]);
|
||
let profile = Profile {
|
||
duration_mode: Some("median".into()),
|
||
duration_split: true,
|
||
duration_add_margin: true,
|
||
duration_margin: Some("30 s".into()),
|
||
..Default::default()
|
||
};
|
||
let profile: Profile = serde_json::from_str(&serde_json::to_string(&profile).unwrap()).unwrap();
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(
|
||
r.entries.iter().map(|e| e.duration_ms).collect::<Vec<_>>(),
|
||
[600_000, 1_200_000]
|
||
);
|
||
assert_eq!(r.entries[1].start_ms, r.entries[0].end_ms + 30_000);
|
||
assert_eq!(r.gaps.len(), 2);
|
||
let json = export::ontime(&r).unwrap();
|
||
for e in &r.entries {
|
||
assert_eq!(
|
||
json["rundowns"]["default"]["entries"][&e.id]["duration"],
|
||
e.duration_ms
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn ignoring_a_split_part_retains_its_sibling_and_recalculates_timing() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["15:30", "30min\n25min + 5 min QR", "Talk"],
|
||
&["16:00", "30 min", "Break"],
|
||
]);
|
||
let base = Profile {
|
||
duration_split: true,
|
||
duration_mode: Some("median".into()),
|
||
..Profile::default()
|
||
};
|
||
let original = analyze(&t, &base).rundown.unwrap();
|
||
for ignored in [1, 2] {
|
||
let mut profile = base.clone();
|
||
profile
|
||
.ignored_parts
|
||
.insert(2, [ignored].into_iter().collect());
|
||
let profile: Profile =
|
||
serde_json::from_str(&serde_json::to_string(&profile).unwrap()).unwrap();
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries.len(), 2);
|
||
assert_eq!(r.ignored_entries.len(), 1);
|
||
let remaining = if ignored == 1 { 2 } else { 1 };
|
||
assert_eq!(r.entries[0].split_part, Some(remaining));
|
||
assert_eq!(r.entries[0].id, original.entries[remaining - 1].id);
|
||
assert_eq!(r.entries[0].start_ms, 55_800_000);
|
||
assert!(r.entries[0].explicit_start);
|
||
assert_eq!(
|
||
r.entries[0].duration_ms,
|
||
if ignored == 1 { 1_500_000 } else { 1_800_000 }
|
||
);
|
||
let json = export::ontime(&r).unwrap();
|
||
let entries = json["rundowns"]["default"]["entries"].as_object().unwrap();
|
||
assert!(!entries.contains_key(&r.ignored_entries[0].id));
|
||
assert!(entries.contains_key(&r.entries[0].id));
|
||
}
|
||
let mut margin = base.clone();
|
||
margin.duration_add_margin = true;
|
||
margin.duration_margin = Some("5 min".into());
|
||
margin.ignored_parts.insert(2, [1].into_iter().collect());
|
||
// The next source row also has a margin, but the excluded part does not.
|
||
let a = analyze(&t, &margin);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(r.entries[0].start_ms, 55_800_000);
|
||
assert_eq!(r.entries[0].end_ms, 57_300_000);
|
||
assert_eq!(r.gaps.iter().filter(|g| g.after_row == Some(2)).count(), 1);
|
||
margin.duration_split = false;
|
||
assert!(
|
||
analyze(&t, &margin)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "INVALID_SPLIT_RESOLUTION")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn gap_distribution_preserves_block_bounds_and_exports_generated_timers() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "10 min", "A"],
|
||
&["09:10", "10 min", "B"],
|
||
&["09:30", "10 min", "C"],
|
||
&["09:40", "10 min", "D"],
|
||
]);
|
||
let baseline = analyze(&t, &Profile::default()).rundown.unwrap();
|
||
let gap = &baseline.gaps[0];
|
||
for (action, direction) in [
|
||
("extend_previous", "previous"),
|
||
("add_to_next", "following"),
|
||
("keep", "previous"),
|
||
("keep", "following"),
|
||
("create_event", "previous"),
|
||
("create_event", "following"),
|
||
] {
|
||
let mut profile = Profile::default();
|
||
profile.gap_resolutions.insert(gap.key(), action.into());
|
||
profile.gap_options.insert(
|
||
gap.key(),
|
||
GapOptions {
|
||
distribute: true,
|
||
count: 2,
|
||
direction: direction.into(),
|
||
title: "Questions".into(),
|
||
},
|
||
);
|
||
let profile: Profile =
|
||
serde_json::from_str(&serde_json::to_string(&profile).unwrap()).unwrap();
|
||
let a = analyze(&t, &profile);
|
||
assert!(
|
||
a.diagnostics.is_empty(),
|
||
"{action} {direction}: {:?}",
|
||
a.diagnostics
|
||
);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(
|
||
r.entries.first().unwrap().start_ms,
|
||
baseline.entries[0].start_ms
|
||
);
|
||
assert_eq!(r.entries.last().unwrap().end_ms, baseline.entries[3].end_ms);
|
||
assert_eq!(r.resolved_gaps.len(), 1);
|
||
assert_eq!(r.gaps.len(), if action == "keep" { 2 } else { 0 });
|
||
let original: Vec<_> = r
|
||
.entries
|
||
.iter()
|
||
.filter(|e| e.gap_origin.is_none())
|
||
.collect();
|
||
assert_eq!(
|
||
original
|
||
.iter()
|
||
.map(|e| e.title.as_str())
|
||
.collect::<Vec<_>>(),
|
||
["A", "B", "C", "D"]
|
||
);
|
||
for (index, event) in original.iter().enumerate() {
|
||
let affected = if direction == "previous" {
|
||
index < 2
|
||
} else {
|
||
index >= 2
|
||
};
|
||
let extend = affected && matches!(action, "extend_previous" | "add_to_next");
|
||
assert_eq!(event.duration_ms, if extend { 900_000 } else { 600_000 });
|
||
}
|
||
let generated: Vec<_> = r
|
||
.entries
|
||
.iter()
|
||
.filter(|e| e.gap_origin.is_some())
|
||
.collect();
|
||
assert_eq!(
|
||
generated.len(),
|
||
if action == "create_event" { 2 } else { 0 }
|
||
);
|
||
for (part, event) in generated.iter().enumerate() {
|
||
assert_eq!(event.duration_ms, 300_000);
|
||
assert_eq!(event.title, format!("Questions ({}/2)", part + 1));
|
||
assert!(event.source_rows.is_empty());
|
||
}
|
||
if action == "create_event" {
|
||
let kinds: Vec<_> = r.entries.iter().map(|e| e.gap_origin.is_some()).collect();
|
||
assert_eq!(
|
||
kinds,
|
||
if direction == "previous" {
|
||
vec![false, true, false, true, false, false]
|
||
} else {
|
||
vec![false, false, true, false, true, false]
|
||
}
|
||
);
|
||
}
|
||
let json = export::ontime(&r).unwrap();
|
||
assert_eq!(
|
||
json["rundowns"]["default"]["order"]
|
||
.as_array()
|
||
.unwrap()
|
||
.len(),
|
||
r.entries.len()
|
||
);
|
||
for e in &generated {
|
||
assert_eq!(json["rundowns"]["default"]["entries"][&e.id]["cue"], "");
|
||
assert_eq!(
|
||
json["rundowns"]["default"]["entries"][&e.id]["duration"],
|
||
e.duration_ms
|
||
);
|
||
}
|
||
let dir = tempfile::tempdir().unwrap();
|
||
let path = dir.path().join("result.xlsx");
|
||
std::fs::write(&path, export::xlsx(&r).unwrap()).unwrap();
|
||
let sheets = reader::read(&path).unwrap();
|
||
assert_eq!(sheets[0].rows.len(), r.entries.len() + 1);
|
||
assert_eq!(
|
||
serde_json::to_value(&r).unwrap(),
|
||
serde_json::to_value(analyze(&t, &profile).rundown.unwrap()).unwrap()
|
||
);
|
||
}
|
||
let mut profile = Profile::default();
|
||
profile
|
||
.gap_resolutions
|
||
.insert(gap.key(), "create_event".into());
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
let e = r.entries.iter().find(|e| e.gap_origin.is_some()).unwrap();
|
||
assert_eq!(
|
||
(e.start_ms, e.end_ms),
|
||
(gap.start_ms.unwrap(), gap.end_ms.unwrap())
|
||
);
|
||
assert_eq!(e.title, "Break");
|
||
assert_eq!(r.entries.len(), 5);
|
||
profile.default_break_name = " Pause ".into();
|
||
let saved = serde_json::to_string(&profile).unwrap();
|
||
let profile_roundtrip: Profile = serde_json::from_str(&saved).unwrap();
|
||
let renamed = analyze(&t, &profile_roundtrip).rundown.unwrap();
|
||
assert_eq!(
|
||
renamed
|
||
.entries
|
||
.iter()
|
||
.find(|e| e.gap_origin.is_some())
|
||
.unwrap()
|
||
.title,
|
||
"Pause"
|
||
);
|
||
profile.gap_options.insert(
|
||
gap.key(),
|
||
GapOptions {
|
||
title: "Coffee".into(),
|
||
..Default::default()
|
||
},
|
||
);
|
||
let overridden = analyze(&t, &profile).rundown.unwrap();
|
||
assert_eq!(
|
||
overridden
|
||
.entries
|
||
.iter()
|
||
.find(|e| e.gap_origin.is_some())
|
||
.unwrap()
|
||
.title,
|
||
"Coffee"
|
||
);
|
||
profile.gap_resolutions.clear();
|
||
let retained = analyze(&t, &profile).rundown.unwrap();
|
||
assert_eq!(retained.gaps[0].title, "Pause");
|
||
assert_eq!(retained.gaps[0].key(), gap.key());
|
||
|
||
assert_eq!(
|
||
serde_json::to_value(analyze(&t, &Profile::default()).rundown.unwrap()).unwrap(),
|
||
serde_json::to_value(baseline).unwrap()
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn gap_distribution_rejects_invalid_blocks_and_keeps_whole_second_remainders() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00:00", "10 s", "A"],
|
||
&["09:00:10", "10 s", "B"],
|
||
&["09:00:31", "10 s", "C"],
|
||
]);
|
||
let baseline = analyze(&t, &Profile::default()).rundown.unwrap();
|
||
let key = baseline.gaps[0].key();
|
||
let mut profile = Profile::default();
|
||
profile
|
||
.gap_resolutions
|
||
.insert(key.clone(), "create_event".into());
|
||
profile.gap_options.insert(
|
||
key.clone(),
|
||
GapOptions {
|
||
distribute: true,
|
||
count: 2,
|
||
..Default::default()
|
||
},
|
||
);
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(
|
||
r.entries
|
||
.iter()
|
||
.filter(|e| e.gap_origin.is_some())
|
||
.map(|e| e.duration_ms)
|
||
.collect::<Vec<_>>(),
|
||
[6000, 5000]
|
||
);
|
||
for (count, direction) in [
|
||
(0, "previous"),
|
||
(3, "previous"),
|
||
(2, "following"),
|
||
(2, "bad"),
|
||
] {
|
||
let options = profile.gap_options.get_mut(&key).unwrap();
|
||
options.count = count;
|
||
options.direction = direction.into();
|
||
let a = analyze(&t, &profile);
|
||
assert!(
|
||
a.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "GAP_RESOLUTION_UNAVAILABLE"),
|
||
"{count} {direction}"
|
||
);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(
|
||
serde_json::to_value(&r.entries).unwrap(),
|
||
serde_json::to_value(&baseline.entries).unwrap()
|
||
);
|
||
assert!(r.resolved_gaps.is_empty());
|
||
}
|
||
let noncontiguous = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "5 min", "A"],
|
||
&["09:10", "5 min", "B"],
|
||
&["09:30", "5 min", "C"],
|
||
]);
|
||
let base = analyze(&noncontiguous, &Profile::default())
|
||
.rundown
|
||
.unwrap();
|
||
let key = base.gaps[1].key();
|
||
profile.gap_resolutions = [(key.clone(), "extend_previous".into())].into();
|
||
profile.gap_options = [(
|
||
key,
|
||
GapOptions {
|
||
distribute: true,
|
||
count: 2,
|
||
..Default::default()
|
||
},
|
||
)]
|
||
.into();
|
||
assert!(
|
||
analyze(&noncontiguous, &profile)
|
||
.diagnostics
|
||
.iter()
|
||
.any(|d| d.code == "GAP_RESOLUTION_UNAVAILABLE")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn named_gaps_create_timers_and_multiple_gap_choices_remain_independent() {
|
||
let t = table(&[
|
||
&["Start", "Duration", "Title"],
|
||
&["09:00", "5 min", "Opening"],
|
||
&["", "", "Coffee break"],
|
||
&["09:15", "5 min", "Middle"],
|
||
&["09:30", "5 min", "Closing"],
|
||
]);
|
||
let baseline = analyze(&t, &Profile::default()).rundown.unwrap();
|
||
assert_eq!(baseline.gaps.len(), 2);
|
||
let mut profile = Profile::default();
|
||
for gap in &baseline.gaps {
|
||
profile
|
||
.gap_resolutions
|
||
.insert(gap.key(), "create_event".into());
|
||
}
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
|
||
let r = a.rundown.unwrap();
|
||
assert_eq!(
|
||
r.entries
|
||
.iter()
|
||
.map(|e| e.title.as_str())
|
||
.collect::<Vec<_>>(),
|
||
["Opening", "Coffee break", "Middle", "Break", "Closing"]
|
||
);
|
||
assert!(r.gaps.is_empty());
|
||
assert_eq!(r.resolved_gaps.len(), 2);
|
||
assert_eq!(
|
||
r.entries
|
||
.iter()
|
||
.map(|e| &e.id)
|
||
.collect::<std::collections::BTreeSet<_>>()
|
||
.len(),
|
||
5
|
||
);
|
||
let json = export::ontime(&r).unwrap();
|
||
assert_eq!(
|
||
json["rundowns"]["default"]["order"]
|
||
.as_array()
|
||
.unwrap()
|
||
.len(),
|
||
5
|
||
);
|
||
profile.gap_resolutions.remove(&baseline.gaps[0].key());
|
||
let a = analyze(&t, &profile);
|
||
assert!(a.diagnostics.is_empty());
|
||
assert_eq!(a.rundown.unwrap().gaps.len(), 1);
|
||
}
|
||
|
||
#[test]
|
||
fn french_action_header_allows_data_inference_for_temps() {
|
||
let t = table(&[
|
||
&["Heure", "Action", "Temps", "Intervenant"],
|
||
&["09:00", "Welcome", "5 min", "Host"],
|
||
&["09:05", "Presentation", "20 min", "Speaker"],
|
||
]);
|
||
let mapping = detect::infer(&t, &Profile::default()).unwrap();
|
||
assert_eq!(mapping.header_row, 1);
|
||
assert_eq!(mapping.start, 0);
|
||
assert_eq!(mapping.title, 1);
|
||
assert_eq!(mapping.duration, Some(2));
|
||
let mut invalid = t;
|
||
invalid.rows[2][2].text = "Ask the stage manager".into();
|
||
let mapping = detect::infer(&invalid, &Profile::default()).unwrap();
|
||
assert_eq!(
|
||
mapping.duration, None,
|
||
"Temps must not force a duration meaning"
|
||
);
|
||
}
|