compares attributes -- '==' didn't seems to work
(attrs1: Vec<Attribute>, attrs2: Vec<Attribute>)
| 623 | |
| 624 | /// compares attributes -- '==' didn't seems to work |
| 625 | fn attrs_are_same(attrs1: Vec<Attribute>, attrs2: Vec<Attribute>) -> Result<()> { |
| 626 | if attrs1.len() != attrs2.len() { |
| 627 | bail!("Attributes have different length: {:?} != {:?}", attrs1, attrs2); |
| 628 | } |
| 629 | // can't guarantee attrs are in the same order |
| 630 | for attr1 in attrs1 { |
| 631 | if let Some(found_attr2) = attrs2.iter().find(|&attr2| attr1.name().local_part() == attr2.name().local_part()) { |
| 632 | if attr1.value() == found_attr2.value() { |
| 633 | continue; |
| 634 | } else { |
| 635 | bail!("Attribute named {} has differing values:\n '{}'\n '{}'", attr1.name().local_part(), attr1.value(), found_attr2.value()); |
| 636 | } |
| 637 | } else { |
| 638 | bail!("Attribute name {} not in [{}]", print_attr(&attr1), print_attrs(&attrs2)); |
| 639 | } |
| 640 | } |
| 641 | return Ok( () ); |
| 642 | |
| 643 | fn print_attr(attr: &Attribute) -> String { |
| 644 | return format!("@{}='{}'", attr.name().local_part(), attr.value()); |
| 645 | } |
| 646 | fn print_attrs(attrs: &[Attribute]) -> String { |
| 647 | return attrs.iter() |
| 648 | .map(print_attr) |
| 649 | .collect::<Vec<String>>() |
| 650 | .join(", "); |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 |