driven/context/
analyzer.rs1use super::scanner::ScanResult;
4use crate::Result;
5
6#[derive(Debug, Default)]
8pub struct PatternAnalyzer;
9
10impl PatternAnalyzer {
11 pub fn new() -> Self {
13 Self
14 }
15
16 pub fn analyze(&self, scan_result: &ScanResult) -> Result<Vec<String>> {
18 let mut patterns = Vec::new();
19
20 if let Some(&count) = scan_result.file_counts.get("rs") {
22 if count > 0 {
23 patterns.push("Rust codebase".to_string());
24 }
25 }
26
27 if let Some(&count) = scan_result.file_counts.get("ts") {
28 if count > 0 {
29 patterns.push("TypeScript codebase".to_string());
30 }
31 }
32
33 if scan_result.key_directories.contains(&"src".to_string()) {
35 patterns.push("Standard src directory structure".to_string());
36 }
37
38 if scan_result.key_directories.contains(&"crates".to_string()) {
39 patterns.push("Cargo workspace structure".to_string());
40 }
41
42 if scan_result
43 .key_directories
44 .contains(&"packages".to_string())
45 {
46 patterns.push("Monorepo structure".to_string());
47 }
48
49 if scan_result.has_tests {
51 patterns.push("Has testing infrastructure".to_string());
52 }
53
54 if scan_result.has_ci {
55 patterns.push("Has CI/CD pipeline".to_string());
56 }
57
58 if scan_result.has_docs {
59 patterns.push("Has documentation".to_string());
60 }
61
62 Ok(patterns)
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_analyzer_new() {
72 let _analyzer = PatternAnalyzer::new();
73 }
74
75 #[test]
76 fn test_analyze_empty() {
77 let analyzer = PatternAnalyzer::new();
78 let scan_result = ScanResult::default();
79 let patterns = analyzer.analyze(&scan_result).unwrap();
80 assert!(patterns.is_empty());
81 }
82}