use stern4rust::reporting::offence::Offence;
use stern4rust::reporting::offence_threshold::OffenceThreshold;
fn offences(count: usize) -> Vec<Offence> {
(1..=count)
.map(|line| {
Offence::new(
"src/a.rs",
line,
"header",
"wrong".to_string(),
"fix it".to_string(),
)
})
.collect()
}
#[test]
fn default_is_one_hundred() {
let threshold = OffenceThreshold::default();
assert_eq!(threshold.limit(), 100);
}
#[test]
fn is_unlimited_of_a_positive_limit_is_false() {
let threshold = OffenceThreshold::new(1);
assert!(!threshold.is_unlimited());
}
#[test]
fn is_unlimited_of_zero_is_true() {
let threshold = OffenceThreshold::new(0);
assert!(threshold.is_unlimited());
}
#[test]
fn kept_of_fewer_offences_than_the_limit_returns_all_of_them() {
let found = offences(3);
let kept = OffenceThreshold::new(10).kept(&found);
assert_eq!(kept.len(), 3);
}
#[test]
fn kept_of_more_offences_than_the_limit_returns_the_limit() {
let found = offences(7);
let kept = OffenceThreshold::new(2).kept(&found);
assert_eq!(kept.len(), 2);
}
#[test]
fn kept_returns_the_offences_in_the_order_it_was_given() {
let found = offences(7);
let kept = OffenceThreshold::new(2).kept(&found);
assert_eq!(kept[0].line, 1);
assert_eq!(kept[1].line, 2);
}
#[test]
fn kept_with_no_limit_returns_all_of_them() {
let found = offences(500);
let kept = OffenceThreshold::new(0).kept(&found);
assert_eq!(kept.len(), 500);
}
#[test]
fn omitted_of_fewer_offences_than_the_limit_is_none() {
let omitted = OffenceThreshold::new(10).omitted(&offences(3));
assert_eq!(omitted, 0);
}
#[test]
fn omitted_of_more_offences_than_the_limit_is_the_remainder() {
let omitted = OffenceThreshold::new(2).omitted(&offences(7));
assert_eq!(omitted, 5);
}
#[test]
fn omitted_with_no_limit_is_none() {
let omitted = OffenceThreshold::new(0).omitted(&offences(500));
assert_eq!(omitted, 0);
}