docx_rs/xml_builder/
relationship.rs1use super::XMLBuilder;
2use super::XmlEvent;
3use std::io::Write;
4
5impl<W: Write> XMLBuilder<W> {
6 open!(open_relationships, "Relationships", "xmlns");
9
10 closed!(relationship, "Relationship", "Id", "Type", "Target");
12 closed!(
13 relationship_with_mode,
14 "Relationship",
15 "Id",
16 "Type",
17 "Target",
18 "TargetMode"
19 );
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25 use std::str;
26 use xml::writer::Result;
27
28 #[test]
29 fn test_open_relationships() -> Result<()> {
30 let b = XMLBuilder::new(Vec::new());
31 let r = b
32 .open_relationships("http://example")?
33 .plain_text("child")?
34 .close()?
35 .into_inner()?
36 .into_inner();
37 assert_eq!(
38 str::from_utf8(&r).unwrap(),
39 r#"<Relationships xmlns="http://example">child</Relationships>"#
40 );
41 Ok(())
42 }
43
44 #[test]
45 fn test_relationship() -> Result<()> {
46 let b = XMLBuilder::new(Vec::new());
47 let r = b
48 .relationship("rId1", "http://example", "core.xml")?
49 .into_inner()?
50 .into_inner();
51 assert_eq!(
52 str::from_utf8(&r).unwrap(),
53 r#"<Relationship Id="rId1" Type="http://example" Target="core.xml" />"#
54 );
55 Ok(())
56 }
57}