easyofd_core/versions/
file_list.rs1use super::File;
4
5#[derive(Debug, Clone)]
9pub struct FileList {
10 pub files: Vec<File>,
12}
13
14impl FileList {
15 #[must_use]
17 pub fn new() -> Self {
18 Self { files: Vec::new() }
19 }
20
21 #[must_use]
23 pub fn with(mut self, file: File) -> Self {
24 self.files.push(file);
25 self
26 }
27
28 pub fn push(&mut self, file: File) {
30 self.files.push(file);
31 }
32
33 #[must_use]
35 pub fn to_xml_string(&self) -> String {
36 let inner: String = self.files.iter().map(File::to_xml_string).collect();
37 format!("<FileList>{inner}</FileList>")
38 }
39}
40
41impl Default for FileList {
42 fn default() -> Self {
43 Self::new()
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_file_list_new() {
53 let fl = FileList::new();
54 assert!(fl.files.is_empty());
55 let fl2 = FileList::default();
56 assert!(fl2.files.is_empty());
57 }
58
59 #[test]
60 fn test_file_list_with_and_xml() {
61 let fl = FileList::new()
62 .with(File::new("a.xml", 100))
63 .with(File::new("b.xml", 200));
64 assert_eq!(fl.files.len(), 2);
65 let xml = fl.to_xml_string();
66 assert!(xml.contains("<FileList>"));
67 assert!(xml.contains("a.xml"));
68 assert!(xml.contains("b.xml"));
69 }
70}