use crate::domain::types::{
BranchCoverage, ComplexityMetric, CrapError, FileChangeKind, FunctionComplexity, LineCoverage,
};
use serde::Serialize;
use serde::de::DeserializeOwned;
use std::collections::HashMap;
use std::fmt::Debug;
use std::path::Path;
pub trait ComplexityPort {
fn extract(
&self,
source: &str,
file_path: &str,
metric: ComplexityMetric,
) -> Result<Vec<FunctionComplexity>, CrapError>;
}
pub trait ParseDiagnostic: Debug + Clone + Serialize + DeserializeOwned {}
#[derive(Debug)]
pub struct ParseOutput<P: ParseDiagnostic> {
pub coverage: HashMap<String, Vec<LineCoverage>>,
pub branches: Option<HashMap<String, Vec<BranchCoverage>>>,
pub diagnostics: Vec<P>,
}
pub trait CoveragePort {
type Diagnostic: ParseDiagnostic;
fn parse(&self, data: &str) -> Result<ParseOutput<Self::Diagnostic>, CrapError>;
}
pub trait DiffPort {
fn changed_regions(
&self,
diff_ref: &str,
working_dir: &Path,
paths: &[String],
) -> Result<HashMap<String, FileChangeKind>, CrapError>;
}
#[cfg(test)]
mod object_safety {
use super::*;
use crate::test_strategies::DummyParseDiagnostic;
#[allow(dead_code)]
fn _coverage_port_is_dyn_safe(_port: &dyn CoveragePort<Diagnostic = DummyParseDiagnostic>) {}
#[allow(dead_code)]
fn _complexity_port_is_dyn_safe(_port: &dyn ComplexityPort) {}
}