test(docx): also compare number of children

This detects if a tag gets added/removed, or moves within the hierarchy.

Signed-off-by: Edwin Török <edwin@etorok.net>
This commit is contained in:
Edwin Török
2023-12-18 14:08:53 -08:00
committed by John MacFarlane
parent 806740805d
commit 2477fb50ff
+6
View File
@@ -45,6 +45,11 @@ compareXML (Elem goodElem) (Elem myElem) =
(Comparison { mine = sort (elAttribs myElem)
, good = sort (elAttribs goodElem)
})))
<|> (if length (elContent myElem) == length (elContent goodElem)
then Nothing
else Just
(ElemChildrenDiffer
(Comparison { mine = elContent myElem, good = elContent goodElem})))
<|> asum (zipWith compareXML (elContent myElem) (elContent goodElem))
compareXML (Text goodCData) (Text myCData) =
(if cdVerbatim myCData == cdVerbatim goodCData
@@ -60,6 +65,7 @@ compareXML g m = Just (OtherContentsDiffer (Comparison {mine = m, good = g}))
data XMLDifference
= ElemNamesDiffer (Comparison QName)
| ElemAttributesDiffer (Comparison [Attr])
| ElemChildrenDiffer (Comparison [Content])
| CDatasDiffer (Comparison CData)
| CRefsDiffer (Comparison String)
| OtherContentsDiffer (Comparison Content)