use super::*;
use crate::adapters::analyzers::iosp::ComplexityMetrics;
use crate::findings::{Dimension, Suppression};
fn file_suppressed(fa_line: usize, sup_line: usize, dim: Dimension) -> (bool, bool) {
let mut fa = make_func_with_metrics(ComplexityMetrics::default());
fa.line = fa_line;
let sup = Suppression {
line: sup_line,
dimensions: vec![dim],
reason: None,
};
apply_file_suppressions(&mut fa, &[sup]);
(fa.suppressed, fa.complexity_suppressed)
}
#[test]
fn iosp_suppression_on_same_line_suppresses_iosp_only() {
assert_eq!(file_suppressed(5, 5, Dimension::Iosp), (true, false));
}
#[test]
fn complexity_suppression_on_same_line_suppresses_complexity_only() {
assert_eq!(file_suppressed(5, 5, Dimension::Complexity), (false, true));
}
#[test]
fn suppression_at_window_edge_applies() {
assert_eq!(file_suppressed(5, 2, Dimension::Iosp), (true, false));
}
#[test]
fn suppression_just_outside_window_does_not_apply() {
assert_eq!(file_suppressed(6, 2, Dimension::Iosp), (false, false));
}
#[test]
fn suppression_below_function_does_not_apply() {
assert_eq!(file_suppressed(2, 5, Dimension::Iosp), (false, false));
}
#[test]
fn recursive_annotation_drops_self_calls_only() {
let mut fa = make_func_with_metrics(ComplexityMetrics::default());
fa.name = "f".to_string();
fa.qualified_name = "Foo::f".to_string();
fa.line = 7;
fa.own_calls = vec!["f".to_string(), "Foo::f".to_string(), "other".to_string()];
let recursive_lines: HashMap<String, HashSet<usize>> =
[("test.rs".to_string(), HashSet::from([7]))].into();
apply_recursive_annotations(std::slice::from_mut(&mut fa), &recursive_lines);
assert_eq!(fa.own_calls, vec!["other".to_string()]);
}