use std::path::PathBuf;
use crate::SymbolId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ImpactLevel {
Local = 1,
Reference = 2,
Structural = 3,
Semantic = 4,
}
impl ImpactLevel {
pub fn description(&self) -> &'static str {
match self {
Self::Local => "Local (same file only)",
Self::Reference => "Reference (cross-file references)",
Self::Structural => "Structural (type structure changes)",
Self::Semantic => "Semantic (behavior changes)",
}
}
}
#[derive(Debug, Default)]
pub struct ImpactSet {
pub symbols: Vec<SymbolId>,
pub files: Vec<PathBuf>,
}
impl ImpactSet {
pub fn new() -> Self {
Self::default()
}
pub fn add_symbol(&mut self, symbol: SymbolId) {
if !self.symbols.contains(&symbol) {
self.symbols.push(symbol);
}
}
pub fn add_file(&mut self, file: PathBuf) {
if !self.files.contains(&file) {
self.files.push(file);
}
}
pub fn is_empty(&self) -> bool {
self.symbols.is_empty() && self.files.is_empty()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_impact_level_ordering() {
assert!(ImpactLevel::Local < ImpactLevel::Reference);
assert!(ImpactLevel::Reference < ImpactLevel::Structural);
assert!(ImpactLevel::Structural < ImpactLevel::Semantic);
}
#[test]
fn test_impact_set() {
let mut set = ImpactSet::new();
assert!(set.is_empty());
set.add_file(PathBuf::from("test.rs"));
assert!(!set.is_empty());
}
}