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
53
54
55
56
57
58
59
60
61
62
63
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::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()]
        );
    }
}