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

Function is_same_doc

src/interface.rs:527–564  ·  view source on GitHub ↗
(doc1: &Document, doc2: &Document)

Source from the content-addressed store, hash-verified

525/// returns Ok() if two Documents are equal or some info where they differ in the Err
526#[allow(dead_code)]
527fn is_same_doc(doc1: &Document, doc2: &Document) -> Result<()> {
528 // assume 'e' doesn't have element children until proven otherwise
529 // this means we keep Text children until we are proven they aren't needed
530 if doc1.root().children().len() != doc2.root().children().len() {
531 bail!("Children of docs have {} != {} children", doc1.root().children().len(), doc2.root().children().len());
532 }
533
534 for (i, (c1, c2)) in doc1.root().children().iter().zip(doc2.root().children().iter()).enumerate() {
535 match c1 {
536 ChildOfRoot::Element(e1) => {
537 if let ChildOfRoot::Element(e2) = c2 {
538 is_same_element(e1, e2)?;
539 } else {
540 bail!("child #{}, first is element, second is something else", i);
541 }
542 },
543 ChildOfRoot::Comment(com1) => {
544 if let ChildOfRoot::Comment(com2) = c2 {
545 if com1.text() != com2.text() {
546 bail!("child #{} -- comment text differs", i);
547 }
548 } else {
549 bail!("child #{}, first is comment, second is something else", i);
550 }
551 }
552 ChildOfRoot::ProcessingInstruction(p1) => {
553 if let ChildOfRoot::ProcessingInstruction(p2) = c2 {
554 if p1.target() != p2.target() || p1.value() != p2.value() {
555 bail!("child #{} -- processing instruction differs", i);
556 }
557 } else {
558 bail!("child #{}, first is processing instruction, second is something else", i);
559 }
560 }
561 }
562 };
563 return Ok( () );
564}
565
566/// returns Ok() if two Documents are equal or some info where they differ in the Err
567// Not really meant to be public -- used by tests in some packages

Callers 1

are_parsed_strs_equalFunction · 0.85

Calls 2

is_same_elementFunction · 0.85
lenMethod · 0.80

Tested by

no test coverage detected