psa/
psa_project.rs

1use crate::psa_module::Module;
2
3pub struct Project {
4    pub name: String,
5    pub path: String,
6    pub modules: Vec<Module>,
7    pub project_type: String,
8}
9
10impl Project {
11    pub fn add_module(&mut self, module: Module) {
12        self.modules.push(module);
13    }
14
15    pub fn add_modules(&mut self, modules: &mut Vec<Module>) {
16        self.modules.append(modules)
17    }
18
19    pub fn new(name: &str, path: &str, project_type: &str) -> Self {
20        Project {
21            name: name.to_string(),
22            path: path.to_string(),
23            modules: vec![],
24            project_type: project_type.to_string(),
25        }
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use crate::{Module, Project};
32
33    #[test]
34    fn should_create_project() {
35        let project = Project::new("foo", "test/path", "maven");
36
37        assert_eq!(project.name, "foo".to_string());
38        assert_eq!(project.path, "test/path".to_string());
39        assert_eq!(project.project_type, "maven".to_string());
40        assert_eq!(project.modules.is_empty(), true);
41    }
42
43    #[test]
44    fn should_add_modules() {
45        let mut project = Project::new("foo", "test/path", "maven");
46
47        project.add_module(Module::new("module1", "test/path/module1"));
48        project.add_module(Module::new("module2", "test/path/module2"));
49
50        assert_eq!(project.modules.len(), 2);
51    }
52}