fix: make eq num nodes is unequal

fixes #99
This commit is contained in:
Kristoffer Andersson 2023-09-05 14:19:35 +02:00
parent edf4347a5a
commit 5a1ef42369

View file

@ -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"<foo><bar xmlns='baz'/></foo>";