use crate::common::group;
use crate::common::result_with;
use dry4rust::cli::output_format::OutputFormat;
use dry4rust::cli::report_command::ReportCommand;
use dry4rust::grouper::DuplicateGroup;
fn report_of(exact: Vec<DuplicateGroup>, near: Vec<DuplicateGroup>) -> String {
let result = result_with(exact, near, vec![], vec![]);
let reporter = OutputFormat::Text.reporter(None);
let mut out = Vec::new();
ReportCommand::new(&result, reporter.as_ref())
.run(&mut out)
.expect("reporting succeeds");
String::from_utf8(out).expect("utf-8")
}
#[test]
fn run_over_a_clean_result_says_so_rather_than_printing_an_empty_section() {
let text = report_of(vec![], vec![]);
assert!(text.contains("No exact duplicates found."), "{text}");
assert!(
!text.contains("Near Duplicates"),
"an empty near section is left out entirely, got: {text}"
);
}
#[test]
fn run_writes_both_the_stats_and_the_groups() {
let text = report_of(vec![group(0x11, &["a", "b"])], vec![]);
assert!(text.contains("Duplication Statistics"), "{text}");
assert!(text.contains("Exact Duplicates"), "{text}");
}
#[test]
fn run_writes_the_near_section_when_there_is_one() {
let text = report_of(vec![], vec![group(0x22, &["c", "d"])]);
assert!(text.contains("Near Duplicates"), "{text}");
}