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

58 lines
1.5 KiB
Rust
Raw Normal View History

2019-11-05 11:03:23 +02:00
use super::XMLBuilder;
2019-11-06 07:55:14 +02:00
use super::XmlEvent;
use std::io::Write;
2019-11-05 11:03:23 +02:00
impl<W: Write> XMLBuilder<W> {
2019-11-05 11:03:23 +02:00
// Build RelationShips element
// i.e. <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
open!(open_relationships, "Relationships", "xmlns");
2019-11-05 11:03:23 +02:00
// Build Relationship
closed!(relationship, "Relationship", "Id", "Type", "Target");
closed!(
relationship_with_mode,
"Relationship",
"Id",
"Type",
"Target",
"TargetMode"
);
2019-11-05 11:03:23 +02:00
}
#[cfg(test)]
mod tests {
use super::*;
2019-11-05 11:03:23 +02:00
use std::str;
use xml::writer::Result;
2019-11-05 11:03:23 +02:00
#[test]
fn test_open_relationships() -> Result<()> {
let b = XMLBuilder::new(Vec::new());
2019-11-05 11:03:23 +02:00
let r = b
.open_relationships("http://example")?
.plain_text("child")?
.close()?
.into_inner()?
.into_inner();
2019-11-05 11:03:23 +02:00
assert_eq!(
str::from_utf8(&r).unwrap(),
r#"<Relationships xmlns="http://example">child</Relationships>"#
);
Ok(())
2019-11-05 11:03:23 +02:00
}
#[test]
fn test_relationship() -> Result<()> {
let b = XMLBuilder::new(Vec::new());
let r = b
.relationship("rId1", "http://example", "core.xml")?
.into_inner()?
.into_inner();
2019-11-05 11:03:23 +02:00
assert_eq!(
str::from_utf8(&r).unwrap(),
r#"<Relationship Id="rId1" Type="http://example" Target="core.xml" />"#
);
Ok(())
2019-11-05 11:03:23 +02:00
}
}