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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/// reqif-rs: Help library to write reqif files implemented in Rust.
/// Copyright (C) <2024>  INVAP S.E.
///
/// This file is part of reqif-rs.
///
/// reqif-rs is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program.  If not, see <https://www.gnu.org/licenses/>.
pub mod req_if;

#[cfg(test)]
mod tests {

    use crate::req_if::{Object, ReqIf, SpecHierarchy, SpecObjectRequirement};
    use chrono::{DateTime, Local, SecondsFormat};

    #[test]
    fn test_serialize() {

        let local: DateTime<Local> = Local::now();
        let identifier = "1234567890".to_string();
        let repository_id = "123456789io0pxazsxdbghnjmk".to_string();
        let req_if_tool_id = "Doorstop".to_string();
        let source_tool_id = "Doorstop".to_string();
        let title = "Requirements examples".to_string();

        let mut reqif = ReqIf::new(
            identifier,
            local,
            repository_id,
            req_if_tool_id,
            source_tool_id,
            title,
        );

        let local: DateTime<Local> = Local::now();

        let now = local.to_rfc3339_opts(SecondsFormat::Millis, false);

        reqif.add_requirement(SpecObjectRequirement::new(
            "REQS-1".to_string(),
            now.clone(),
            "Titulo del requerimiento 1".to_string(),
            "Texto del requerimiento 1.".to_string(),
            &reqif.core_content.req_if_content.spec_types,
        ));

        reqif.add_requirement(SpecObjectRequirement::new(
            "REQS-2".to_string(),
            now.clone(),
            "Titulo del requerimiento 2".to_string(),
            "Texto del requerimiento 2.".to_string(),
            &reqif.core_content.req_if_content.spec_types,
        ));

        let mut specification = reqif.build_module_specification(
            "REQS".to_string(),
            now.to_string(),
            "Project User Requirements".to_string(),
        );

        specification
            .children
            .add_spec_hierarchy(
                SpecHierarchy {
                    identifier: "h1".to_string(),
                    last_change: now.clone(),
                    object: Object {
                        object_ref: "REQS-1".to_string(),
                    },
                    children: None,
                },
                0,
            )
            .expect("Unexpected error adding children");

        specification
            .children
            .add_spec_hierarchy(
                SpecHierarchy {
                    identifier: "h2".to_string(),
                    last_change: now.clone(),
                    object: Object {
                        object_ref: "REQS-2".to_string(),
                    },
                    children: None,
                },
                1,
            )
            .expect("Unexpected error adding children");

        reqif.add_specification(specification);
        reqif.write_to("libtest.reqif").unwrap();
    }
}