2019-11-15 11:15:43 +02:00
|
|
|
use crate::documents::{BuildXML, HistoryId, Run};
|
|
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Insert<'a> {
|
|
|
|
|
author: &'a str,
|
|
|
|
|
date: &'a str,
|
2019-12-04 11:26:09 +02:00
|
|
|
run: Run<'a>,
|
2019-11-15 11:15:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Default for Insert<'a> {
|
|
|
|
|
fn default() -> Insert<'a> {
|
|
|
|
|
Insert {
|
|
|
|
|
author: "unnamed",
|
|
|
|
|
date: "1970-01-01T00:00:00Z",
|
|
|
|
|
run: Run::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Insert<'a> {
|
|
|
|
|
pub fn new() -> Insert<'a> {
|
|
|
|
|
Default::default()
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 11:26:09 +02:00
|
|
|
pub fn run(mut self, run: Run<'a>) -> Insert<'a> {
|
2019-11-15 11:15:43 +02:00
|
|
|
self.run = run;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> HistoryId for Insert<'a> {}
|
|
|
|
|
|
|
|
|
|
impl<'a> BuildXML for Insert<'a> {
|
|
|
|
|
fn build(&self) -> Vec<u8> {
|
|
|
|
|
XMLBuilder::new()
|
|
|
|
|
.open_insert(&self.generate(), self.author, self.date)
|
|
|
|
|
.add_child(&self.run)
|
|
|
|
|
.close()
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ins_default() {
|
|
|
|
|
let b = Insert::new().build();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
str::from_utf8(&b).unwrap(),
|
2019-12-04 11:26:09 +02:00
|
|
|
r#"<w:ins w:id="123" w:author="unnamed" w:date="1970-01-01T00:00:00Z"><w:r><w:rPr /></w:r></w:ins>"#
|
2019-11-15 11:15:43 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|