Skip to content

Commit d9cc820

Browse files
committed
1 parent 0d5d247 commit d9cc820

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

src/tests/net-core/Diff/DOMDifferenceEngineTest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,57 @@ public void NaiveRecursion() {
731731
Assert.AreEqual(0, ex.invoked);
732732
}
733733

734+
[Test]
735+
// see https://sourceforge.net/p/xmlunit/discussion/73273/thread/92c980ec5b/
736+
public void SourceforgeForumThread92c980ec5b() {
737+
XmlElement gp1 = doc.CreateElement("grandparent");
738+
XmlElement p1_0 = doc.CreateElement("parent");
739+
p1_0.SetAttribute("id", "0");
740+
gp1.AppendChild(p1_0);
741+
XmlElement p1_1 = doc.CreateElement("parent");
742+
p1_1.SetAttribute("id", "1");
743+
gp1.AppendChild(p1_1);
744+
XmlElement c1_1 = doc.CreateElement("child");
745+
c1_1.SetAttribute("id", "1");
746+
p1_1.AppendChild(c1_1);
747+
748+
XmlElement gp2 = doc.CreateElement("grandparent");
749+
XmlElement p2_1 = doc.CreateElement("parent");
750+
p2_1.SetAttribute("id", "1");
751+
gp2.AppendChild(p2_1);
752+
XmlElement c2_1 = doc.CreateElement("child");
753+
c2_1.SetAttribute("id", "1");
754+
p2_1.AppendChild(c2_1);
755+
XmlElement c2_2 = doc.CreateElement("child");
756+
c2_2.SetAttribute("id", "2");
757+
p2_1.AppendChild(c2_2);
758+
759+
DOMDifferenceEngine d = new DOMDifferenceEngine();
760+
DiffExpecter ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP,
761+
null, "/grandparent[1]/parent[1]/child[2]")
762+
.WithParentXPath("/grandparent[1]/parent[2]", "/grandparent[1]/parent[1]");
763+
d.DifferenceListener += ex.ComparisonPerformed;
764+
DifferenceEvaluator ev = delegate(Comparison comparison,
765+
ComparisonResult outcome) {
766+
if (comparison.Type == ComparisonType.CHILD_NODELIST_LENGTH
767+
|| comparison.Type == ComparisonType.CHILD_NODELIST_SEQUENCE) {
768+
return ComparisonResult.EQUAL;
769+
}
770+
if (comparison.Type == ComparisonType.CHILD_LOOKUP
771+
&& comparison.TestDetails.Target == null) {
772+
return ComparisonResult.EQUAL;
773+
}
774+
return outcome;
775+
};
776+
d.ComparisonController = ComparisonControllers.StopWhenDifferent;
777+
d.DifferenceEvaluator = ev;
778+
d.NodeMatcher = new DefaultNodeMatcher(ElementSelectors.ByNameAndAllAttributes);
779+
Assert.AreEqual(WrapAndStop(ComparisonResult.DIFFERENT),
780+
d.CompareNodes(gp1, new XPathContext(gp1),
781+
gp2, new XPathContext(gp2)));
782+
Assert.AreEqual(1, ex.invoked);
783+
}
784+
734785
[Test]
735786
public void TextAndCDataMatchRecursively() {
736787
XmlElement e1 = doc.CreateElement("foo");

0 commit comments

Comments
 (0)