Skip to content

Commit 3e3d15c

Browse files
committed
Make Encode tests order agnostic.
This _should_ prevent ci failure due to different orders in the children elements.
1 parent 2924c65 commit 3e3d15c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,23 @@ pub fn run_test<
103103
tests: &[(T, &str)],
104104
) {
105105
for t in tests {
106-
let tree1 = Element::parse(t.1.as_bytes()).unwrap();
107-
let elem = T::parse(&tree1).unwrap();
106+
let mut tree1 = Element::parse(t.1.as_bytes()).unwrap();
107+
let mut elem = T::parse(&tree1).unwrap();
108+
// Hack to make assert be order agnostic
109+
tree1.children.sort_by(|e1,e2| e1.name.cmp(&e2.name));
110+
tree1.children.iter_mut().for_each(|e| {
111+
e.children.sort_by(|e1,e2| e1.name.cmp(&e2.name));
112+
});
108113
assert_eq!(
109114
elem, t.0,
110115
"Error parsing xml` (mismatch between parsed and expected)"
111116
);
112-
let tree2 = elem.encode().unwrap();
117+
let mut tree2 = elem.encode().unwrap();
118+
// Hack to make assert be order agnostic
119+
tree2.children.sort_by(|e1,e2| e1.name.cmp(&e2.name));
120+
tree2.children.iter_mut().for_each(|e| {
121+
e.children.sort_by(|e1,e2| e1.name.cmp(&e2.name));
122+
});
113123
assert_eq!(
114124
tree1, tree2,
115125
"Error encoding xml (mismatch between encoded and original)"

0 commit comments

Comments
 (0)