docx-rs/docx-core/src/xml_builder/declaration.rs

34 lines
770 B
Rust
Raw Normal View History

2019-11-05 11:03:23 +02:00
use super::XMLBuilder;
impl XMLBuilder {
// Build XML declaration
// i.e. <?xml version="1.0" encoding="UTF-8"?>
pub(crate) fn declaration(mut self) -> Self {
self.writer
.write(super::XmlEvent::StartDocument {
version: super::XmlVersion::Version10,
encoding: Some("UTF-8"),
standalone: None,
})
.expect("should write to buf");
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::str;
#[test]
fn test_declaration() {
let b = XMLBuilder::new();
let r = b.declaration().build();
assert_eq!(
str::from_utf8(&r).unwrap(),
r#"<?xml version="1.0" encoding="UTF-8"?>"#
);
}
}