use super::*;
#[test]
fn test_find_duplicates_exact_marks_second_occurrence() {
let verdicts = find_duplicates(&["a fact", "other", "a fact"], true);
assert!(verdicts[0].is_none());
assert!(verdicts[1].is_none());
let dup = verdicts[2].expect("third entry duplicates the first");
assert_eq!(dup.kind, DupKind::Exact);
assert_eq!(dup.kept_seq, 0);
}
#[test]
fn test_find_duplicates_near_matches_case_and_spacing() {
let verdicts = find_duplicates(&["The Server restarts.", "the server restarts."], true);
let dup = verdicts[1].expect("second entry near-duplicates the first");
assert_eq!(dup.kind, DupKind::Near);
assert_eq!(dup.kept_seq, 0);
}
#[test]
fn test_find_duplicates_near_detection_can_be_disabled() {
let verdicts = find_duplicates(&["The Server restarts.", "the server restarts."], false);
assert!(verdicts[1].is_none(), "near detection was disabled");
}
#[test]
fn test_find_duplicates_exact_still_found_when_near_disabled() {
let verdicts = find_duplicates(&["same", "same"], false);
assert_eq!(verdicts[1].expect("exact duplicate").kind, DupKind::Exact);
}
#[test]
fn test_find_duplicates_distinct_contents_are_all_kept() {
let verdicts = find_duplicates(&["alpha", "beta", "gamma"], true);
assert!(verdicts.iter().all(Option::is_none));
}
#[test]
fn test_find_duplicates_exact_copy_of_a_near_duplicate_reports_exact() {
let verdicts = find_duplicates(&["Hello World", "hello world", "hello world"], true);
let dup = verdicts[2].expect("third entry duplicates the second");
assert_eq!(
dup.kind,
DupKind::Exact,
"a byte-identical copy must be recorded as an exact duplicate"
);
assert_eq!(
dup.kept_seq, 1,
"the byte-identical twin is #1, not the near-duplicate root #0"
);
}
#[test]
fn test_find_duplicates_near_dup_still_anchors_the_near_chain_at_the_root() {
let verdicts = find_duplicates(
&["Hello World", "hello world", "hello world", "HELLO WORLD"],
true,
);
assert_eq!(verdicts[3].expect("near dup").kept_seq, 0);
}
#[test]
fn test_find_duplicates_chain_points_to_first_occurrence() {
let verdicts = find_duplicates(&["x", "x", "x"], true);
assert_eq!(verdicts[1].expect("dup").kept_seq, 0);
assert_eq!(verdicts[2].expect("dup").kept_seq, 0);
}