1pub 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}