MCPcopy Create free account
hub / github.com/daisy/MathCAT / is_same_element

Function is_same_element

src/interface.rs:569–653  ·  view source on GitHub ↗
(e1: &Element, e2: &Element)

Source from the content-addressed store, hash-verified

567// Not really meant to be public -- used by tests in some packages
568#[allow(dead_code)]
569pub fn is_same_element(e1: &Element, e2: &Element) -> Result<()> {
570 if name(e1) != name(e2) {
571 bail!("Names not the same: {}, {}", name(e1), name(e2));
572 }
573
574 // assume 'e' doesn't have element children until proven otherwise
575 // this means we keep Text children until we are proven they aren't needed
576 if e1.children().len() != e2.children().len() {
577 bail!("Children of {} have {} != {} children", name(e1), e1.children().len(), e2.children().len());
578 }
579
580 if let Err(e) = attrs_are_same(e1.attributes(), e2.attributes()) {
581 bail!("In element {}, {}", name(e1), e);
582 }
583
584 for (i, (c1, c2)) in e1.children().iter().zip(e2.children().iter()).enumerate() {
585 match c1 {
586 ChildOfElement::Element(child1) => {
587 if let ChildOfElement::Element(child2) = c2 {
588 is_same_element(child1, child2)?;
589 } else {
590 bail!("{} child #{}, first is element, second is something else", name(e1), i);
591 }
592 },
593 ChildOfElement::Comment(com1) => {
594 if let ChildOfElement::Comment(com2) = c2 {
595 if com1.text() != com2.text() {
596 bail!("{} child #{} -- comment text differs", name(e1), i);
597 }
598 } else {
599 bail!("{} child #{}, first is comment, second is something else", name(e1), i);
600 }
601 }
602 ChildOfElement::ProcessingInstruction(p1) => {
603 if let ChildOfElement::ProcessingInstruction(p2) = c2 {
604 if p1.target() != p2.target() || p1.value() != p2.value() {
605 bail!("{} child #{} -- processing instruction differs", name(e1), i);
606 }
607 } else {
608 bail!("{} child #{}, first is processing instruction, second is something else", name(e1), i);
609 }
610 }
611 ChildOfElement::Text(t1) => {
612 if let ChildOfElement::Text(t2) = c2 {
613 if t1.text() != t2.text() {
614 bail!("{} child #{} -- text differs", name(e1), i);
615 }
616 } else {
617 bail!("{} child #{}, first is text, second is something else", name(e1), i);
618 }
619 }
620 }
621 };
622 return Ok( () );
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() {

Callers 3

test_intentFunction · 0.85
is_same_docFunction · 0.85

Calls 3

nameFunction · 0.85
attrs_are_sameFunction · 0.85
lenMethod · 0.80

Tested by 1

test_intentFunction · 0.68