1use derive_builder::Builder;
4
5#[derive(Default, Debug, Builder, PartialEq, Clone)]
9#[builder(default, setter(into))]
10pub struct ProjectConfig {
11 pub include: Vec<String>,
13 pub exclude: Vec<String>,
15}
16
17impl ProjectConfig {
18 pub fn new() -> Self {
20 Self::default()
21 }
22
23 pub fn add_include<S: Into<String>>(mut self, include: S) -> Self {
25 self.include.push(include.into());
26 self
27 }
28
29 pub fn add_includes<I, S>(mut self, includes: I) -> Self
31 where
32 I: IntoIterator<Item = S>,
33 S: Into<String>,
34 {
35 self.include.extend(includes.into_iter().map(Into::into));
36 self
37 }
38
39 pub fn add_exclude<S: Into<String>>(mut self, exclude: S) -> Self {
41 self.exclude.push(exclude.into());
42 self
43 }
44
45 pub fn add_excludes<I, S>(mut self, excludes: I) -> Self
47 where
48 I: IntoIterator<Item = S>,
49 S: Into<String>,
50 {
51 self.exclude.extend(excludes.into_iter().map(Into::into));
52 self
53 }
54
55 pub fn clear_include(mut self) -> Self {
57 self.include.clear();
58 self
59 }
60
61 pub fn clear_exclude(mut self) -> Self {
63 self.exclude.clear();
64 self
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn test_init_config() {
75 let config = ProjectConfig::new();
76 println!("{:?}", config);
77 assert_eq!(config.include.len(), 0);
78 assert_eq!(config.exclude.len(), 0);
79 }
80
81 #[test]
82 fn test_width_include() {
84 let config = ProjectConfig::new()
85 .add_includes(["./src"])
86 .add_excludes(["./node_modules", "./dist"]);
87 println!("{:?}", config);
88 assert_eq!(config.include.len(), 1);
89 assert_eq!(config.exclude.len(), 2);
90 let config = config.add_include("123").add_exclude("321");
91 println!("{:?}", config);
92 assert_eq!(config.include.len(), 2);
93 assert_eq!(config.exclude.len(), 3);
94 }
95
96 #[test]
97 fn test_width_include_string() {
99 let config = ProjectConfig::new()
100 .add_includes(vec!["./src".to_string()])
101 .add_excludes(vec!["./node_modules".to_string(), "./dist".to_string()]);
102 println!("{:?}", config);
103 assert_eq!(config.include.len(), 1);
104 assert_eq!(config.exclude.len(), 2);
105 let config = config
106 .add_include("123".to_string())
107 .add_exclude("321".to_string());
108 println!("{:?}", config);
109 assert_eq!(config.include.len(), 2);
110 assert_eq!(config.exclude.len(), 3);
111 }
112
113 #[test]
114 fn test_clear() {
116 let mut config = ProjectConfig::new()
117 .add_excludes(["123", "1231"])
118 .add_includes(["1111"]);
119 config = config.clear_include().clear_exclude();
120 println!("{:?}", config);
121 assert_eq!(config.include.len(), 0);
122 assert_eq!(config.exclude.len(), 0);
123 }
124}