cc_audit/runtime/
context.rs1use crate::config::Config;
6use std::path::PathBuf;
7
8#[derive(Debug, Clone)]
10pub struct ScanContext {
11 pub paths: Vec<PathBuf>,
13 pub config: Config,
15 pub verbose: bool,
17 pub strict: bool,
19}
20
21impl ScanContext {
22 pub fn new(paths: Vec<PathBuf>, config: Config) -> Self {
24 Self {
25 paths,
26 config,
27 verbose: false,
28 strict: false,
29 }
30 }
31
32 pub fn with_verbose(mut self, verbose: bool) -> Self {
34 self.verbose = verbose;
35 self
36 }
37
38 pub fn with_strict(mut self, strict: bool) -> Self {
40 self.strict = strict;
41 self
42 }
43}
44
45impl Default for ScanContext {
46 fn default() -> Self {
47 Self::new(Vec::new(), Config::default())
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_scan_context_builder() {
57 let ctx = ScanContext::new(vec![PathBuf::from(".")], Config::default())
58 .with_verbose(true)
59 .with_strict(true);
60
61 assert!(ctx.verbose);
62 assert!(ctx.strict);
63 }
64
65 #[test]
66 fn test_scan_context_default() {
67 let ctx = ScanContext::default();
68 assert!(ctx.paths.is_empty());
69 assert!(!ctx.verbose);
70 assert!(!ctx.strict);
71 }
72
73 #[test]
74 fn test_scan_context_new() {
75 let paths = vec![PathBuf::from("/test/path")];
76 let ctx = ScanContext::new(paths.clone(), Config::default());
77 assert_eq!(ctx.paths, paths);
78 assert!(!ctx.verbose);
79 assert!(!ctx.strict);
80 }
81
82 #[test]
83 fn test_scan_context_debug() {
84 let ctx = ScanContext::default();
85 let debug_str = format!("{:?}", ctx);
86 assert!(debug_str.contains("ScanContext"));
87 }
88
89 #[test]
90 fn test_scan_context_clone() {
91 let ctx = ScanContext::new(vec![PathBuf::from(".")], Config::default()).with_verbose(true);
92 let cloned = ctx.clone();
93 assert_eq!(ctx.paths, cloned.paths);
94 assert_eq!(ctx.verbose, cloned.verbose);
95 }
96}