From fac64400f13a3aa8dd261cfd21429b111dc7c9e1 Mon Sep 17 00:00:00 2001 From: lumi Date: Tue, 29 May 2018 16:22:22 +0200 Subject: [PATCH] Put the tests in element.rs into a module block. --- src/element.rs | 152 +++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 74 deletions(-) diff --git a/src/element.rs b/src/element.rs index 485c97ff..e147a27d 100644 --- a/src/element.rs +++ b/src/element.rs @@ -926,80 +926,84 @@ impl ElementBuilder { } #[cfg(test)] -#[test] -fn test_element_new() { - use std::iter::FromIterator; +mod tests { + use super::*; - let elem = Element::new( "name".to_owned() - , None - , Some("namespace".to_owned()) - , BTreeMap::from_iter(vec![ ("name".to_string(), "value".to_string()) ].into_iter() ) - , Vec::new() ); + #[test] + fn test_element_new() { + use std::iter::FromIterator; - assert_eq!(elem.name(), "name"); - assert_eq!(elem.ns(), Some("namespace".to_owned())); - assert_eq!(elem.attr("name"), Some("value")); - assert_eq!(elem.attr("inexistent"), None); -} - -#[test] -fn test_from_reader_simple() { - let xml = ""; - let mut reader = EventReader::from_str(xml); - let elem = Element::from_reader(&mut reader); - - let elem2 = Element::builder("foo").build(); - - assert_eq!(elem.unwrap(), elem2); -} - -#[test] -fn test_from_reader_nested() { - let xml = ""; - let mut reader = EventReader::from_str(xml); - let elem = Element::from_reader(&mut reader); - - let nested = Element::builder("bar") - .attr("baz", "qxx") - .build(); - let elem2 = Element::builder("foo") - .append(nested) - .build(); - - assert_eq!(elem.unwrap(), elem2); -} - -#[test] -fn test_from_reader_with_prefix() { - let xml = ""; - let mut reader = EventReader::from_str(xml); - let elem = Element::from_reader(&mut reader); - - let nested = Element::builder("prefix:bar") - .attr("baz", "qxx") - .build(); - let elem2 = Element::builder("foo") - .append(nested) - .build(); - - assert_eq!(elem.unwrap(), elem2); -} - -#[test] -fn parses_spectest_xml() { // From: https://gitlab.com/lumi/minidom-rs/issues/8 - let xml = r#" - - - - "#; - let mut reader = EventReader::from_str(xml); - let _ = Element::from_reader(&mut reader).unwrap(); -} - -#[test] -fn does_not_unescape_cdata() { - let xml = "]]>"; - let mut reader = EventReader::from_str(xml); - let elem = Element::from_reader(&mut reader).unwrap(); - assert_eq!(elem.text(), "'>blah"); + let elem = Element::new( "name".to_owned() + , None + , Some("namespace".to_owned()) + , BTreeMap::from_iter(vec![ ("name".to_string(), "value".to_string()) ].into_iter() ) + , Vec::new() ); + + assert_eq!(elem.name(), "name"); + assert_eq!(elem.ns(), Some("namespace".to_owned())); + assert_eq!(elem.attr("name"), Some("value")); + assert_eq!(elem.attr("inexistent"), None); + } + + #[test] + fn test_from_reader_simple() { + let xml = ""; + let mut reader = EventReader::from_str(xml); + let elem = Element::from_reader(&mut reader); + + let elem2 = Element::builder("foo").build(); + + assert_eq!(elem.unwrap(), elem2); + } + + #[test] + fn test_from_reader_nested() { + let xml = ""; + let mut reader = EventReader::from_str(xml); + let elem = Element::from_reader(&mut reader); + + let nested = Element::builder("bar") + .attr("baz", "qxx") + .build(); + let elem2 = Element::builder("foo") + .append(nested) + .build(); + + assert_eq!(elem.unwrap(), elem2); + } + + #[test] + fn test_from_reader_with_prefix() { + let xml = ""; + let mut reader = EventReader::from_str(xml); + let elem = Element::from_reader(&mut reader); + + let nested = Element::builder("prefix:bar") + .attr("baz", "qxx") + .build(); + let elem2 = Element::builder("foo") + .append(nested) + .build(); + + assert_eq!(elem.unwrap(), elem2); + } + + #[test] + fn parses_spectest_xml() { // From: https://gitlab.com/lumi/minidom-rs/issues/8 + let xml = r#" + + + + "#; + let mut reader = EventReader::from_str(xml); + let _ = Element::from_reader(&mut reader).unwrap(); + } + + #[test] + fn does_not_unescape_cdata() { + let xml = "]]>"; + let mut reader = EventReader::from_str(xml); + let elem = Element::from_reader(&mut reader).unwrap(); + assert_eq!(elem.text(), "'>blah"); + } }