2020-02-11 10:01:39 +02:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
2019-11-15 11:15:43 +02:00
|
|
|
use crate::documents::{BuildXML, HistoryId, Run};
|
2020-02-11 10:01:39 +02:00
|
|
|
|
2019-11-15 11:15:43 +02:00
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
#[derive(Serialize, Debug, Clone, PartialEq)]
|
2019-12-08 21:14:27 +02:00
|
|
|
pub struct Insert {
|
2019-12-19 09:37:28 +02:00
|
|
|
pub run: Run,
|
|
|
|
|
pub author: String,
|
|
|
|
|
pub date: String,
|
2019-11-15 11:15:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-08 21:14:27 +02:00
|
|
|
impl Default for Insert {
|
|
|
|
|
fn default() -> Insert {
|
2019-11-15 11:15:43 +02:00
|
|
|
Insert {
|
2019-12-08 21:14:27 +02:00
|
|
|
author: "unnamed".to_owned(),
|
|
|
|
|
date: "1970-01-01T00:00:00Z".to_owned(),
|
2019-11-15 11:15:43 +02:00
|
|
|
run: Run::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 21:14:27 +02:00
|
|
|
impl Insert {
|
2019-12-19 09:37:28 +02:00
|
|
|
pub fn new(run: Run) -> Insert {
|
|
|
|
|
Self {
|
|
|
|
|
run,
|
|
|
|
|
..Default::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn author(mut self, author: impl Into<String>) -> Insert {
|
|
|
|
|
self.author = author.into();
|
|
|
|
|
self
|
2019-11-15 11:15:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-19 09:37:28 +02:00
|
|
|
pub fn date(mut self, date: impl Into<String>) -> Insert {
|
|
|
|
|
self.date = date.into();
|
2019-11-15 11:15:43 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 21:14:27 +02:00
|
|
|
impl HistoryId for Insert {}
|
2019-11-15 11:15:43 +02:00
|
|
|
|
2019-12-08 21:14:27 +02:00
|
|
|
impl BuildXML for Insert {
|
2019-11-15 11:15:43 +02:00
|
|
|
fn build(&self) -> Vec<u8> {
|
|
|
|
|
XMLBuilder::new()
|
2019-12-08 21:14:27 +02:00
|
|
|
.open_insert(&self.generate(), &self.author, &self.date)
|
2019-11-15 11:15:43 +02:00
|
|
|
.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() {
|
2019-12-19 09:37:28 +02:00
|
|
|
let b = Insert::new(Run::new()).build();
|
2019-11-15 11:15:43 +02:00
|
|
|
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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|