use stern4rust::reporting::column_widths::ColumnWidths;
use stern4rust::reporting::offence::Offence;
fn offence(file: &str, line: usize, rule: &'static str, description: &str) -> Offence {
Offence::new(file, line, rule, description.to_string(), "fix".to_string())
}
#[test]
fn of_no_offences_falls_back_to_the_heading_widths() {
let widths = ColumnWidths::of(&[]);
assert_eq!(widths.file, "file".len());
assert_eq!(widths.line, "line".len());
assert_eq!(widths.rule, "rule".len());
assert_eq!(widths.description, "offence".len());
}
#[test]
fn of_offences_narrower_than_their_headings_keeps_the_heading_width() {
let widths = ColumnWidths::of(&[offence("a.rs", 1, "x", "y")]);
assert_eq!(widths.line, "line".len());
assert_eq!(widths.rule, "rule".len());
assert_eq!(widths.description, "offence".len());
}
#[test]
fn of_offences_takes_the_widest_entry_of_each_column() {
let long = "crates/deeply/nested/package/src/module/subject.rs";
let widths = ColumnWidths::of(&[
offence("src/a.rs", 1, "header", "short"),
offence(
long,
1234,
"test-file-structure",
"a much longer description",
),
]);
assert_eq!(widths.file, long.len());
assert_eq!(widths.line, "1234".len());
assert_eq!(widths.rule, "test-file-structure".len());
assert_eq!(widths.description, "a much longer description".len());
}