Put the tests in element.rs into a module block.

This commit is contained in:
lumi 2018-05-29 16:22:22 +02:00
parent 956dff3ad4
commit fac64400f1

View file

@ -926,80 +926,84 @@ impl ElementBuilder {
} }
#[cfg(test)] #[cfg(test)]
#[test] mod tests {
fn test_element_new() { use super::*;
use std::iter::FromIterator;
let elem = Element::new( "name".to_owned() #[test]
, None fn test_element_new() {
, Some("namespace".to_owned()) use std::iter::FromIterator;
, BTreeMap::from_iter(vec![ ("name".to_string(), "value".to_string()) ].into_iter() )
, Vec::new() );
assert_eq!(elem.name(), "name"); let elem = Element::new( "name".to_owned()
assert_eq!(elem.ns(), Some("namespace".to_owned())); , None
assert_eq!(elem.attr("name"), Some("value")); , Some("namespace".to_owned())
assert_eq!(elem.attr("inexistent"), None); , BTreeMap::from_iter(vec![ ("name".to_string(), "value".to_string()) ].into_iter() )
} , Vec::new() );
#[test] assert_eq!(elem.name(), "name");
fn test_from_reader_simple() { assert_eq!(elem.ns(), Some("namespace".to_owned()));
let xml = "<foo></foo>"; assert_eq!(elem.attr("name"), Some("value"));
let mut reader = EventReader::from_str(xml); assert_eq!(elem.attr("inexistent"), None);
let elem = Element::from_reader(&mut reader); }
let elem2 = Element::builder("foo").build(); #[test]
fn test_from_reader_simple() {
assert_eq!(elem.unwrap(), elem2); let xml = "<foo></foo>";
} let mut reader = EventReader::from_str(xml);
let elem = Element::from_reader(&mut reader);
#[test]
fn test_from_reader_nested() { let elem2 = Element::builder("foo").build();
let xml = "<foo><bar baz='qxx' /></foo>";
let mut reader = EventReader::from_str(xml); assert_eq!(elem.unwrap(), elem2);
let elem = Element::from_reader(&mut reader); }
let nested = Element::builder("bar") #[test]
.attr("baz", "qxx") fn test_from_reader_nested() {
.build(); let xml = "<foo><bar baz='qxx' /></foo>";
let elem2 = Element::builder("foo") let mut reader = EventReader::from_str(xml);
.append(nested) let elem = Element::from_reader(&mut reader);
.build();
let nested = Element::builder("bar")
assert_eq!(elem.unwrap(), elem2); .attr("baz", "qxx")
} .build();
let elem2 = Element::builder("foo")
#[test] .append(nested)
fn test_from_reader_with_prefix() { .build();
let xml = "<foo><prefix:bar baz='qxx' /></foo>";
let mut reader = EventReader::from_str(xml); assert_eq!(elem.unwrap(), elem2);
let elem = Element::from_reader(&mut reader); }
let nested = Element::builder("prefix:bar") #[test]
.attr("baz", "qxx") fn test_from_reader_with_prefix() {
.build(); let xml = "<foo><prefix:bar baz='qxx' /></foo>";
let elem2 = Element::builder("foo") let mut reader = EventReader::from_str(xml);
.append(nested) let elem = Element::from_reader(&mut reader);
.build();
let nested = Element::builder("prefix:bar")
assert_eq!(elem.unwrap(), elem2); .attr("baz", "qxx")
} .build();
let elem2 = Element::builder("foo")
#[test] .append(nested)
fn parses_spectest_xml() { // From: https://gitlab.com/lumi/minidom-rs/issues/8 .build();
let xml = r#"
<rng:grammar xmlns:rng="http://relaxng.org/ns/structure/1.0"> assert_eq!(elem.unwrap(), elem2);
<rng:name xmlns:rng="http://relaxng.org/ns/structure/1.0"></rng:name> }
</rng:grammar>
"#; #[test]
let mut reader = EventReader::from_str(xml); fn parses_spectest_xml() { // From: https://gitlab.com/lumi/minidom-rs/issues/8
let _ = Element::from_reader(&mut reader).unwrap(); let xml = r#"
} <rng:grammar xmlns:rng="http://relaxng.org/ns/structure/1.0">
<rng:name xmlns:rng="http://relaxng.org/ns/structure/1.0"></rng:name>
#[test] </rng:grammar>
fn does_not_unescape_cdata() { "#;
let xml = "<test><![CDATA[&apos;&gt;blah<blah>]]></test>"; let mut reader = EventReader::from_str(xml);
let mut reader = EventReader::from_str(xml); let _ = Element::from_reader(&mut reader).unwrap();
let elem = Element::from_reader(&mut reader).unwrap(); }
assert_eq!(elem.text(), "&apos;&gt;blah<blah>");
#[test]
fn does_not_unescape_cdata() {
let xml = "<test><![CDATA[&apos;&gt;blah<blah>]]></test>";
let mut reader = EventReader::from_str(xml);
let elem = Element::from_reader(&mut reader).unwrap();
assert_eq!(elem.text(), "&apos;&gt;blah<blah>");
}
} }