easyofd_core/versions/
doc_version.rs1use super::FileList;
4
5#[derive(Debug, Clone)]
9pub struct DocVersion {
10 pub doc_root: String,
12 pub file_list: Option<FileList>,
14}
15
16impl DocVersion {
17 #[must_use]
19 pub fn new(doc_root: impl Into<String>) -> Self {
20 Self {
21 doc_root: doc_root.into(),
22 file_list: None,
23 }
24 }
25
26 #[must_use]
28 pub fn with_file_list(mut self, file_list: FileList) -> Self {
29 self.file_list = Some(file_list);
30 self
31 }
32
33 #[must_use]
35 pub fn to_xml_string(&self) -> String {
36 let inner = match &self.file_list {
37 Some(fl) => fl.to_xml_string(),
38 None => String::new(),
39 };
40 format!(
41 "<DocVersion DocRoot=\"{}\">{inner}</DocVersion>",
42 self.doc_root
43 )
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50 use crate::versions::File;
51
52 #[test]
53 fn test_doc_version_new() {
54 let dv = DocVersion::new("Doc_0");
55 assert_eq!(dv.doc_root, "Doc_0");
56 assert!(dv.file_list.is_none());
57 }
58
59 #[test]
60 fn test_doc_version_with_file_list_and_xml() {
61 let fl = FileList::new().with(File::new("OFD.xml", 1024));
62 let dv = DocVersion::new("Doc_0").with_file_list(fl);
63 let xml = dv.to_xml_string();
64 assert!(xml.contains("DocRoot=\"Doc_0\""));
65 assert!(xml.contains("OFD.xml"));
66 assert!(xml.contains("1024"));
67 }
68}