pub const CONTENT_TYPES: &str = "[Content_Types].xml";
pub const ROOT_RELS: &str = "_rels/.rels";
pub const DOCUMENT: &str = "word/document.xml";
pub const REQUIRED_PARTS: &[&str] = &[CONTENT_TYPES, ROOT_RELS, DOCUMENT];
pub const HEADER_PREFIX: &str = "word/header";
pub const FOOTER_PREFIX: &str = "word/footer";
pub const FOOTNOTES: &str = "word/footnotes.xml";
pub const ENDNOTES: &str = "word/endnotes.xml";
pub const STYLES: &str = "word/styles.xml";
pub const SETTINGS: &str = "word/settings.xml";
pub fn is_main_document(name: &str) -> bool {
name == DOCUMENT
}
pub fn is_header(name: &str) -> bool {
name.starts_with(HEADER_PREFIX) && name.ends_with(".xml")
}
pub fn is_footer(name: &str) -> bool {
name.starts_with(FOOTER_PREFIX) && name.ends_with(".xml")
}
pub fn is_footnotes(name: &str) -> bool {
name == FOOTNOTES
}
pub fn is_endnotes(name: &str) -> bool {
name == ENDNOTES
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing)]
use super::*;
#[test]
fn required_parts_contains_three_entries() {
assert_eq!(REQUIRED_PARTS.len(), 3);
assert!(REQUIRED_PARTS.contains(&CONTENT_TYPES));
assert!(REQUIRED_PARTS.contains(&ROOT_RELS));
assert!(REQUIRED_PARTS.contains(&DOCUMENT));
}
#[test]
fn is_main_document_matches_only_document() {
assert!(is_main_document("word/document.xml"));
assert!(!is_main_document("word/header1.xml"));
assert!(!is_main_document("word/document.xml.rels"));
}
#[test]
fn is_header_matches_numbered_headers() {
assert!(is_header("word/header1.xml"));
assert!(is_header("word/header2.xml"));
assert!(is_header("word/header10.xml"));
assert!(!is_header("word/footer1.xml"));
assert!(!is_header("word/header1.xml.rels"));
}
#[test]
fn is_footer_matches_numbered_footers() {
assert!(is_footer("word/footer1.xml"));
assert!(is_footer("word/footer2.xml"));
assert!(!is_footer("word/header1.xml"));
}
#[test]
fn is_footnotes_and_endnotes() {
assert!(is_footnotes("word/footnotes.xml"));
assert!(!is_footnotes("word/endnotes.xml"));
assert!(is_endnotes("word/endnotes.xml"));
assert!(!is_endnotes("word/footnotes.xml"));
}
}