use crate::basic_type::ST_Loc;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Document {
pub common_data: Option<String>,
pub pages: Vec<PageRef>,
pub outlines: Option<String>,
pub permissions: Option<String>,
pub actions: Option<String>,
pub v_preferences: Option<String>,
pub bookmarks: Option<String>,
pub annotations: Option<ST_Loc>,
pub custom_tags: Option<ST_Loc>,
pub attachments: Option<ST_Loc>,
pub extensions: Option<ST_Loc>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PageRef {
pub id: u32,
pub base_loc: ST_Loc,
}
impl PageRef {
#[must_use]
pub fn new(id: u32, base_loc: ST_Loc) -> Self {
Self { id, base_loc }
}
}
impl Document {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn add_page(&mut self, page: PageRef) {
self.pages.push(page);
}
#[must_use]
pub fn page_count(&self) -> usize {
self.pages.len()
}
#[must_use]
pub fn annotations(mut self, path: ST_Loc) -> Self {
self.annotations = Some(path);
self
}
#[must_use]
pub fn attachments(mut self, path: ST_Loc) -> Self {
self.attachments = Some(path);
self
}
#[must_use]
pub fn extensions(mut self, path: ST_Loc) -> Self {
self.extensions = Some(path);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn document_new() {
let doc = Document::new();
assert!(doc.pages.is_empty());
assert!(doc.annotations.is_none());
}
#[test]
fn document_add_page() {
let mut doc = Document::new();
doc.add_page(PageRef::new(1, ST_Loc::new("Pages/Page_0.xml")));
doc.add_page(PageRef::new(2, ST_Loc::new("Pages/Page_1.xml")));
assert_eq!(doc.page_count(), 2);
}
#[test]
fn page_ref_new() {
let pr = PageRef::new(1, ST_Loc::new("Pages/Page_0.xml"));
assert_eq!(pr.id, 1);
assert_eq!(pr.base_loc.loc(), "Pages/Page_0.xml");
}
#[test]
fn document_builder() {
let doc = Document::new()
.annotations(ST_Loc::new("Annotations.xml"))
.attachments(ST_Loc::new("Attachments.xml"));
assert!(doc.annotations.is_some());
assert!(doc.attachments.is_some());
}
#[test]
fn document_clone_debug() {
let doc = Document::new();
let doc2 = doc.clone();
assert_eq!(doc2.page_count(), 0);
assert!(format!("{doc:?}").contains("Document"));
}
}