minidom: Implement PartialEq manually for Node and Element

Move the NamespaceAwareCompare implementation from xmpp-parsers as Node
and Element's PartialEq implementation. Thanks Astro!

It's a lot more useful in tests to use `assert_eq!` than `assert!`, so
we get both items compared (left and right) instead of a "it failed."
message.

This "breaks" comparison for these two structs in the sense that it is
not strict object comparison anymore but it ensures that namespaces are
all present in the compared objects.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-11-29 14:33:17 +01:00
commit 1c5551a917
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2
20 changed files with 65 additions and 172 deletions

View file

@ -9,7 +9,7 @@ use quick_xml::events::{BytesText, Event};
use quick_xml::Writer as EventWriter;
/// A node in an element tree.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, Eq)]
pub enum Node {
/// An `Element`.
Element(Element),
@ -208,3 +208,13 @@ impl From<ElementBuilder> for Node {
Node::Element(builder.build())
}
}
impl PartialEq for Node {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(&Node::Element(ref elem1), &Node::Element(ref elem2)) => elem1 == elem2,
(&Node::Text(ref text1), &Node::Text(ref text2)) => text1 == text2,
_ => false,
}
}
}