Skip to content

Commit

Permalink
feat(psa): add content root struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynfeng committed Feb 23, 2021
1 parent d656844 commit ae0968c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 32 deletions.
1 change: 1 addition & 0 deletions psa/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod pas_content_root;
pub mod psa_facet;
pub mod psa_library;
pub mod psa_module;
Expand Down
64 changes: 64 additions & 0 deletions psa/src/pas_content_root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
pub struct ContentRoot {
pub source_root: Vec<String>,
pub resource_root: Vec<String>,
pub test_source_root: Vec<String>,
pub test_resource_root: Vec<String>,
}

impl ContentRoot {
pub fn add_source_root(&mut self, root_path: &str) {
self.source_root.push(root_path.to_string());
}

pub fn add_resource_root(&mut self, root_path: &str) {
self.resource_root.push(root_path.to_string());
}

pub fn add_test_source_root(&mut self, root_path: &str) {
self.test_source_root.push(root_path.to_string());
}

pub fn add_test_resource_root(&mut self, root_path: &str) {
self.test_resource_root.push(root_path.to_string());
}
}

impl Default for ContentRoot {
fn default() -> Self {
ContentRoot {
source_root: vec![],
resource_root: vec![],
test_source_root: vec![],
test_resource_root: vec![],
}
}
}

#[cfg(test)]
mod tests {
use crate::pas_content_root::ContentRoot;

#[test]
fn should_add_various_roots() {
let mut content_root = ContentRoot::default();

content_root.add_source_root("src/main/java");
content_root.add_resource_root("src/main/resources");
content_root.add_test_source_root("src/test/java");
content_root.add_test_resource_root("src/test/resources");

assert_eq!(content_root.source_root, vec!["src/main/java".to_string()]);
assert_eq!(
content_root.resource_root,
vec!["src/main/resources".to_string()]
);
assert_eq!(
content_root.test_source_root,
vec!["src/test/java".to_string()]
);
assert_eq!(
content_root.test_resource_root,
vec!["src/test/resources".to_string()]
);
}
}
23 changes: 13 additions & 10 deletions psa/src/psa_module.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
use crate::pas_content_root::ContentRoot;
use crate::psa_facet::Facet;

pub struct Module {
pub name: String,
pub path: String,
pub facets: Vec<Facet>,
pub content_root: ContentRoot,
}

impl Module {
pub fn add_facet(&mut self, facet: Facet) {
self.facets.push(facet);
}

pub fn new(name: &str, path: &str) -> Self {
Module {
name: name.to_string(),
path: path.to_string(),
facets: vec![],
content_root: ContentRoot::default(),
}
}
}

#[cfg(test)]
Expand All @@ -19,23 +30,15 @@ mod tests {

#[test]
fn should_create_module() {
let module = Module {
name: "foo".to_string(),
path: "test/path".to_string(),
facets: vec![],
};
let module = Module::new("foo", "test/path");

assert_eq!(module.name, "foo".to_string());
assert_eq!(module.path, "test/path".to_string());
}

#[test]
fn should_add_facet() {
let mut module = Module {
name: "foo".to_string(),
path: "test/path".to_string(),
facets: vec![],
};
let mut module = Module::new("foo", "test/path");

module.add_facet(Facet {
name: "Java".to_string(),
Expand Down
35 changes: 13 additions & 22 deletions psa/src/psa_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ impl Project {
pub fn add_module(&mut self, module: Module) {
self.modules.push(module);
}

pub fn new(name: &str, path: &str) -> Self {
Project {
name: name.to_string(),
path: path.to_string(),
modules: vec![],
}
}
}

#[cfg(test)]
Expand All @@ -19,11 +27,7 @@ mod tests {

#[test]
fn should_create_project() {
let project = Project {
name: "foo".to_string(),
path: "test/path".to_string(),
modules: vec![],
};
let project = Project::new("foo", "test/path");

assert_eq!(project.name, "foo".to_string());
assert_eq!(project.path, "test/path".to_string());
Expand All @@ -32,23 +36,10 @@ mod tests {

#[test]
fn should_add_modules() {
let mut project = Project {
name: "foo".to_string(),
path: "test/path".to_string(),
modules: vec![],
};

project.add_module(Module {
name: "module1".to_string(),
path: "test/path/module1".to_string(),
facets: vec![],
});

project.add_module(Module {
name: "module2".to_string(),
path: "test/path/module2".to_string(),
facets: vec![],
});
let mut project = Project::new("foo", "test/path");

project.add_module(Module::new("module1", "test/path/module1"));
project.add_module(Module::new("module2", "test/path/module2"));

assert_eq!(project.modules.len(), 2);
}
Expand Down

0 comments on commit ae0968c

Please sign in to comment.