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