reqif_rs/
lib.rs

1/// reqif-rs: Help library to write reqif files implemented in Rust.
2/// Copyright (C) <2024>  INVAP S.E.
3///
4/// This file is part of reqif-rs.
5///
6/// reqif-rs is free software: you can redistribute it and/or modify
7/// it under the terms of the GNU Affero General Public License as published by
8/// the Free Software Foundation, either version 3 of the License, or
9/// (at your option) any later version.
10///
11/// This program is distributed in the hope that it will be useful,
12/// but WITHOUT ANY WARRANTY; without even the implied warranty of
13/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14/// GNU Affero General Public License for more details.
15///
16/// You should have received a copy of the GNU Affero General Public License
17/// along with this program.  If not, see <https://www.gnu.org/licenses/>.
18pub mod req_if;
19
20#[cfg(test)]
21mod tests {
22
23    use crate::req_if::{Object, ReqIf, SpecHierarchy, SpecObjectRequirement};
24    use chrono::{DateTime, Local, SecondsFormat};
25
26    #[test]
27    fn test_serialize() {
28
29        let local: DateTime<Local> = Local::now();
30        let identifier = "1234567890".to_string();
31        let repository_id = "123456789io0pxazsxdbghnjmk".to_string();
32        let req_if_tool_id = "Doorstop".to_string();
33        let source_tool_id = "Doorstop".to_string();
34        let title = "Requirements examples".to_string();
35
36        let mut reqif = ReqIf::new(
37            identifier,
38            local,
39            repository_id,
40            req_if_tool_id,
41            source_tool_id,
42            title,
43        );
44
45        let local: DateTime<Local> = Local::now();
46
47        let now = local.to_rfc3339_opts(SecondsFormat::Millis, false);
48
49        reqif.add_requirement(SpecObjectRequirement::new(
50            "REQS-1".to_string(),
51            now.clone(),
52            "Titulo del requerimiento 1".to_string(),
53            "Texto del requerimiento 1.".to_string(),
54            &reqif.core_content.req_if_content.spec_types,
55        ));
56
57        reqif.add_requirement(SpecObjectRequirement::new(
58            "REQS-2".to_string(),
59            now.clone(),
60            "Titulo del requerimiento 2".to_string(),
61            "Texto del requerimiento 2.".to_string(),
62            &reqif.core_content.req_if_content.spec_types,
63        ));
64
65        let mut specification = reqif.build_module_specification(
66            "REQS".to_string(),
67            now.to_string(),
68            "Project User Requirements".to_string(),
69        );
70
71        specification
72            .children
73            .add_spec_hierarchy(
74                SpecHierarchy {
75                    identifier: "h1".to_string(),
76                    last_change: now.clone(),
77                    object: Object {
78                        object_ref: "REQS-1".to_string(),
79                    },
80                    children: None,
81                },
82                0,
83            )
84            .expect("Unexpected error adding children");
85
86        specification
87            .children
88            .add_spec_hierarchy(
89                SpecHierarchy {
90                    identifier: "h2".to_string(),
91                    last_change: now.clone(),
92                    object: Object {
93                        object_ref: "REQS-2".to_string(),
94                    },
95                    children: None,
96                },
97                1,
98            )
99            .expect("Unexpected error adding children");
100
101        reqif.add_specification(specification);
102        reqif.write_to("libtest.reqif").unwrap();
103    }
104}