easyofd_core/doc/bookmark/
bookmarks.rs1use super::Bookmark;
4
5#[derive(Debug, Clone)]
9pub struct Bookmarks {
10 pub bookmarks: Vec<Bookmark>,
12}
13
14impl Bookmarks {
15 #[must_use]
17 pub fn new() -> Self {
18 Self {
19 bookmarks: Vec::new(),
20 }
21 }
22
23 pub fn push(&mut self, bookmark: Bookmark) {
25 self.bookmarks.push(bookmark);
26 }
27
28 #[must_use]
30 pub fn to_xml_string(&self) -> String {
31 let inner: String = self.bookmarks.iter().map(Bookmark::to_xml_string).collect();
32 format!("<Bookmarks>{inner}</Bookmarks>")
33 }
34}
35
36impl Default for Bookmarks {
37 fn default() -> Self {
38 Self::new()
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_bookmarks_new() {
48 let b = Bookmarks::new();
49 assert!(b.bookmarks.is_empty());
50 let b2 = Bookmarks::default();
51 assert!(b2.bookmarks.is_empty());
52 }
53
54 #[test]
55 fn test_bookmarks_push_and_xml() {
56 let mut b = Bookmarks::new();
57 b.push(Bookmark::new("Chapter 1", 1));
58 b.push(Bookmark::new("Chapter 2", 5));
59 assert_eq!(b.bookmarks.len(), 2);
60 let xml = b.to_xml_string();
61 assert!(xml.contains("<Bookmarks>"));
62 assert!(xml.contains("</Bookmarks>"));
63 assert!(xml.contains("Chapter 1"));
64 assert!(xml.contains("Chapter 2"));
65 }
66}