use std::str;
use xmlwriter::{XmlWriter, Options};
#[derive(Clone, Copy, PartialEq)]
struct TStr<'a>(pub &'a str);
macro_rules! text_eq {
($result:expr, $expected:expr) => { assert_eq!($result, $expected) };
}
#[test]
fn write_element_01() {
let mut w = XmlWriter::new(Options::default());
w.start_element("svg");
w.end_element();
text_eq!(w.end_document(), "\n");
}
#[test]
fn write_element_02() {
let mut w = XmlWriter::new(Options::default());
w.start_element("svg");
w.start_element("rect");
w.end_element();
w.end_element();
text_eq!(w.end_document(),
"
");
}
#[test]
fn write_element_03() {
let mut w = XmlWriter::new(Options::default());
w.start_element("svg");
w.end_element();
w.end_element(); // Should not panic.
text_eq!(w.end_document(), "\n");
}
#[test]
fn write_element_05() {
let mut w = XmlWriter::new(Options::default());
w.start_element("svg");
// end_document() will call `close_element` automatically.
text_eq!(w.end_document(), "\n");
}
#[test]
fn write_element_06() {
let mut w = XmlWriter::new(Options::default());
w.start_element("svg");
w.start_element("rect");
w.start_element("rect");
w.start_element("rect");
w.start_element("rect");
w.start_element("rect");
text_eq!(w.end_document(),
"
");
}
#[test]
#[should_panic]
fn write_attribute_01() {
let mut w = XmlWriter::new(Options::default());
// must be used only after write_element
w.write_attribute("id", "q");
}
#[test]
fn write_attribute_02() {
let mut w = XmlWriter::new(Options::default());
w.start_element("svg");
w.write_attribute("id", "q");
w.end_element();
text_eq!(w.end_document(), "
");
}
#[test]
fn write_text_07() {
let mut w = XmlWriter::new(Options::default());
w.start_element("div");
w.start_element("p");
w.write_text("text");
w.start_element("p");
w.write_text("text");
text_eq!(w.end_document(),
"
");
}
#[test]
fn write_text_08() {
let mut w = XmlWriter::new(Options::default());
w.start_element("p");
w.write_text("<");
text_eq!(w.end_document(),
"
<
");
}
#[test]
fn write_text_09() {
let mut w = XmlWriter::new(Options::default());
w.start_element("p");
w.write_text("<&>");
text_eq!(w.end_document(),
"
<&>
");
}
#[test]
fn write_text_10() {
let mut w = XmlWriter::new(Options::default());
w.start_element("p");
w.write_text("<");
text_eq!(w.end_document(),
"
<
");
}
#[test]
fn write_text_11() {
let mut w = XmlWriter::new(Options::default());
w.start_element("p");
w.write_text("text");
w.start_element("p");
w.end_element();
w.write_text("text");
text_eq!(w.end_document(),
"
text
text
");
}
#[test]
fn write_preserve_text_01() {
let mut w = XmlWriter::new(Options::default());
w.set_preserve_whitespaces(true);
w.start_element("p");
w.write_text("text");
w.start_element("p");
w.end_element();
w.write_text("text");
text_eq!(w.end_document(),
"text
text");
}
#[test]
fn write_preserve_text_02() {
let mut w = XmlWriter::new(Options::default());
w.start_element("p");
w.start_element("p");
w.set_preserve_whitespaces(true);
w.write_text("text");
w.start_element("p");
w.end_element();
w.write_text("text");
w.end_element();
w.set_preserve_whitespaces(false);
text_eq!(w.end_document(),
"
text
text
");
}
#[test]
fn attrs_indent_01() {
let opt = Options {
attributes_indent: xmlwriter::Indent::Spaces(2),
.. Options::default()
};
let mut w = XmlWriter::new(opt);
w.start_element("rect");
w.write_attribute("x", "5");
w.start_element("rect");
w.write_attribute("x", "10");
w.write_attribute("y", "15");
text_eq!(w.end_document(),
"
");
}