Fix the PartialEq implementation for Element

The order of attributes in an `Element` doesn't matter anymore.
`<elem a="b" c="d" />` and `<elem c="d" a="b" />` are now correctly
considered equal.

For that I had to derive `PartialOrd` and `Ord` for `Attribute`.
This allows us to sort cloned vectors of `Attribute` in the `PartialEq`
implementation and compare them instead of the struct `attributes`.

Fixes #3
This commit is contained in:
Eijebong 2017-04-24 20:06:21 +02:00
commit 0d0c4b76eb
3 changed files with 27 additions and 2 deletions

View file

@ -94,3 +94,14 @@ fn namespace_propagation_works() {
.get_child("grandchild", "root_ns").unwrap()
.ns(), root.ns());
}
#[test]
fn two_elements_with_same_arguments_different_order_are_equal() {
let elem1: Element = "<a b='a' c=''/>".parse().unwrap();
let elem2: Element = "<a c='' b='a'/>".parse().unwrap();
assert_eq!(elem1, elem2);
let elem1: Element = "<a b='a' c=''/>".parse().unwrap();
let elem2: Element = "<a c='d' b='a'/>".parse().unwrap();
assert_ne!(elem1, elem2);
}