Skip to content

Commit

Permalink
feat(psa): add sub moudle to module struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynfeng committed Feb 25, 2021
1 parent 7f90799 commit 3ec749c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions psa/src/psa_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Module {
pub path: String,
pub facets: Vec<Facet>,
pub libraries: Vec<Library>,
pub sub_modules: Vec<Module>,
pub content_root: ContentRoot,
}

Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -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")
}
}

0 comments on commit 3ec749c

Please sign in to comment.