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,8 +926,11 @@ impl ElementBuilder {
} }
#[cfg(test)] #[cfg(test)]
#[test] mod tests {
fn test_element_new() { use super::*;
#[test]
fn test_element_new() {
use std::iter::FromIterator; use std::iter::FromIterator;
let elem = Element::new( "name".to_owned() let elem = Element::new( "name".to_owned()
@ -940,10 +943,10 @@ fn test_element_new() {
assert_eq!(elem.ns(), Some("namespace".to_owned())); assert_eq!(elem.ns(), Some("namespace".to_owned()));
assert_eq!(elem.attr("name"), Some("value")); assert_eq!(elem.attr("name"), Some("value"));
assert_eq!(elem.attr("inexistent"), None); assert_eq!(elem.attr("inexistent"), None);
} }
#[test] #[test]
fn test_from_reader_simple() { fn test_from_reader_simple() {
let xml = "<foo></foo>"; let xml = "<foo></foo>";
let mut reader = EventReader::from_str(xml); let mut reader = EventReader::from_str(xml);
let elem = Element::from_reader(&mut reader); let elem = Element::from_reader(&mut reader);
@ -951,10 +954,10 @@ fn test_from_reader_simple() {
let elem2 = Element::builder("foo").build(); let elem2 = Element::builder("foo").build();
assert_eq!(elem.unwrap(), elem2); assert_eq!(elem.unwrap(), elem2);
} }
#[test] #[test]
fn test_from_reader_nested() { fn test_from_reader_nested() {
let xml = "<foo><bar baz='qxx' /></foo>"; let xml = "<foo><bar baz='qxx' /></foo>";
let mut reader = EventReader::from_str(xml); let mut reader = EventReader::from_str(xml);
let elem = Element::from_reader(&mut reader); let elem = Element::from_reader(&mut reader);
@ -967,10 +970,10 @@ fn test_from_reader_nested() {
.build(); .build();
assert_eq!(elem.unwrap(), elem2); assert_eq!(elem.unwrap(), elem2);
} }
#[test] #[test]
fn test_from_reader_with_prefix() { fn test_from_reader_with_prefix() {
let xml = "<foo><prefix:bar baz='qxx' /></foo>"; let xml = "<foo><prefix:bar baz='qxx' /></foo>";
let mut reader = EventReader::from_str(xml); let mut reader = EventReader::from_str(xml);
let elem = Element::from_reader(&mut reader); let elem = Element::from_reader(&mut reader);
@ -983,10 +986,10 @@ fn test_from_reader_with_prefix() {
.build(); .build();
assert_eq!(elem.unwrap(), elem2); assert_eq!(elem.unwrap(), elem2);
} }
#[test] #[test]
fn parses_spectest_xml() { // From: https://gitlab.com/lumi/minidom-rs/issues/8 fn parses_spectest_xml() { // From: https://gitlab.com/lumi/minidom-rs/issues/8
let xml = r#" let xml = r#"
<rng:grammar xmlns:rng="http://relaxng.org/ns/structure/1.0"> <rng:grammar xmlns:rng="http://relaxng.org/ns/structure/1.0">
<rng:name xmlns:rng="http://relaxng.org/ns/structure/1.0"></rng:name> <rng:name xmlns:rng="http://relaxng.org/ns/structure/1.0"></rng:name>
@ -994,12 +997,13 @@ fn parses_spectest_xml() { // From: https://gitlab.com/lumi/minidom-rs/issues/8
"#; "#;
let mut reader = EventReader::from_str(xml); let mut reader = EventReader::from_str(xml);
let _ = Element::from_reader(&mut reader).unwrap(); let _ = Element::from_reader(&mut reader).unwrap();
} }
#[test] #[test]
fn does_not_unescape_cdata() { fn does_not_unescape_cdata() {
let xml = "<test><![CDATA[&apos;&gt;blah<blah>]]></test>"; let xml = "<test><![CDATA[&apos;&gt;blah<blah>]]></test>";
let mut reader = EventReader::from_str(xml); let mut reader = EventReader::from_str(xml);
let elem = Element::from_reader(&mut reader).unwrap(); let elem = Element::from_reader(&mut reader).unwrap();
assert_eq!(elem.text(), "&apos;&gt;blah<blah>"); assert_eq!(elem.text(), "&apos;&gt;blah<blah>");
}
} }