From 3ec749c7ac3a0ea8c197481e4ad538b1aaa3a3ff Mon Sep 17 00:00:00 2001 From: ynfeng Date: Thu, 25 Feb 2021 14:13:20 +0800 Subject: [PATCH] feat(psa): add sub moudle to module struct. --- psa/src/psa_module.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/psa/src/psa_module.rs b/psa/src/psa_module.rs index 0f93260d..37769889 100644 --- a/psa/src/psa_module.rs +++ b/psa/src/psa_module.rs @@ -7,6 +7,7 @@ pub struct Module { pub path: String, pub facets: Vec, pub libraries: Vec, + pub sub_modules: Vec, pub content_root: ContentRoot, } @@ -19,12 +20,17 @@ impl Module { self.libraries.push(lib); } + pub fn add_sub_module(&mut self, sub_module: Module) { + self.sub_modules.push(sub_module); + } + pub fn new(name: &str, path: &str) -> Self { Module { name: name.to_string(), path: path.to_string(), facets: vec![], libraries: vec![], + sub_modules: vec![], content_root: ContentRoot::default(), } } @@ -56,15 +62,27 @@ mod tests { #[test] fn should_add_library() { let mut module = Module::new("foo", "test/path"); - let lib = Library { + + module.add_library(Library { group: "org.springframework.boot".to_string(), name: "spring-boot-starter-web".to_string(), version: "1.0.0-RELEASE".to_string(), scope: LibraryScope::Compile, - }; - - module.add_library(lib); + }); + let lib = module.libraries.get(0).unwrap(); assert_eq!(module.libraries.len(), 1); + assert_eq!(lib.name, "spring-boot-starter-web"); + } + + #[test] + fn should_add_sub_module() { + let mut module = Module::new("parent", "test/path"); + + module.add_sub_module(Module::new("child", "test/child/path")); + + let sub_module = module.sub_modules.get(0).unwrap(); + assert_eq!(module.sub_modules.len(), 1); + assert_eq!(sub_module.name, "child") } }