Files
archlens/crates/application/tests/fakes/source_analyzer.rs
Gabriel Kaszewski 35f27d00b0
Some checks failed
CI / Check / Test (push) Failing after 1m24s
init: archlens — architecture diagram generator
Hex arch + DDD, tree-sitter parsing, Mermaid/ASCII output.
Supports Rust + Python. 92 tests. CI, diff, --check for staleness detection.
2026-06-16 16:13:04 +02:00

44 lines
1.2 KiB
Rust

use std::collections::HashMap;
use archlens_domain::{AnalysisResult, DomainError, SourceFile, ports::SourceAnalyzer};
enum FakeResponse {
Success(AnalysisResult),
Failure(DomainError),
}
pub struct FakeSourceAnalyzer {
results: HashMap<String, FakeResponse>,
}
impl FakeSourceAnalyzer {
pub fn new() -> Self {
Self {
results: HashMap::new(),
}
}
pub fn with_result(mut self, file_path: &str, result: AnalysisResult) -> Self {
self.results
.insert(file_path.to_string(), FakeResponse::Success(result));
self
}
pub fn with_error(mut self, file_path: &str, error: DomainError) -> Self {
self.results
.insert(file_path.to_string(), FakeResponse::Failure(error));
self
}
}
impl SourceAnalyzer for FakeSourceAnalyzer {
fn analyze_file(&self, file: &SourceFile) -> Result<AnalysisResult, DomainError> {
let key = file.path().as_str().to_string();
match self.results.get(&key) {
Some(FakeResponse::Success(result)) => Ok(result.clone()),
Some(FakeResponse::Failure(_)) => Err(DomainError::AnalysisError(key)),
None => Ok(AnalysisResult::empty()),
}
}
}