From 9c498044ee15ee0afc8df7a7c8d32f5d49aea073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 31 Dec 2017 07:19:24 +0100 Subject: [PATCH] element: Add tests for Element::from_reader --- src/element.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/element.rs b/src/element.rs index b2cde3a3..e363cbb6 100644 --- a/src/element.rs +++ b/src/element.rs @@ -843,3 +843,46 @@ fn test_element_new() { 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); +}