From 5a1ef42369a632f4d343498abd5cb6a062fdf95c Mon Sep 17 00:00:00 2001 From: Kristoffer Andersson Date: Tue, 5 Sep 2023 14:19:35 +0200 Subject: [PATCH] fix: make eq num nodes is unequal fixes #99 --- minidom/src/element.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/minidom/src/element.rs b/minidom/src/element.rs index b01adcc..6366fa2 100644 --- a/minidom/src/element.rs +++ b/minidom/src/element.rs @@ -146,6 +146,9 @@ impl PartialEq for Element { fn eq(&self, other: &Self) -> bool { if self.name() == other.name() && self.ns() == other.ns() && self.attrs().eq(other.attrs()) { + if self.nodes().count() != other.nodes().count() { + return false; + } self.nodes() .zip(other.nodes()) .all(|(node1, node2)| node1 == node2) @@ -978,6 +981,16 @@ mod tests { assert_eq!(elem, elem4); } + #[test] + fn test_compare_empty_children() { + let elem1 = Element::bare("p", ""); + let elem2 = Element::builder("p", "") + .append(Node::Element(Element::bare("span", ""))) + .build(); + + assert_ne!(elem1, elem2); + } + #[test] fn test_from_reader_with_prefixes() { let xml = b"";