use super::*;
fn numbered(bytes: &[u8], target_chunks: usize) -> Vec<(usize, String)> {
let visit = |line: &[u8], line_no: usize| {
LineVerdict::Keep((line_no, String::from_utf8_lossy(line).into_owned()))
};
let (rows, skipped) = scan_lines_parallel_chunked(bytes, &visit, target_chunks);
assert_eq!(skipped, 0, "nothing here is a Skip verdict");
rows
}
#[test]
fn a_multi_chunk_split_visits_the_same_lines_under_the_same_numbers() {
let text: String = (1..=40).map(|i| format!("line-{i:02}\n")).collect();
let one = numbered(text.as_bytes(), 1);
assert_eq!(one.len(), 40, "one chunk visits every line once");
assert_eq!(one[0], (1, "line-01".to_string()));
assert_eq!(one[39], (40, "line-40".to_string()));
for chunks in [2usize, 3, 5, 8, 13, 40] {
assert_eq!(
numbered(text.as_bytes(), chunks),
one,
"target_chunks={chunks} must be byte-for-byte the serial answer"
);
}
}
#[test]
fn a_file_with_no_trailing_newline_is_chunked_the_same_way() {
let text = "alpha\nbravo\ncharlie\ndelta";
let one = numbered(text.as_bytes(), 1);
assert_eq!(one.len(), 4);
assert_eq!(one[3], (4, "delta".to_string()));
for chunks in [2usize, 3, 4, 9] {
assert_eq!(
numbered(text.as_bytes(), chunks),
one,
"target_chunks={chunks}"
);
}
}