on master help sign in
Add tests for nodeChildrenBy and nodeAttributeBy
commitc30c21db017b1fd65b79ddd68b57a5beacc34a03 authorNeil Mitchell <ndmitchell@gmail.com> dateWed 30 Nov 2016, 19:08 (10 years ago) parent6da2ece
2 files changed+11−1
src/Main.hs+10 src/Text/XML/Hexml.hs+1−1
src/Main.hs+10
@@ -33,6 +33,16 @@ main = do
3333 let Right d = documentParse r
3434 when (r /= documentRender d) $ fail "Different after rerendering"
3535
36+ let Right doc = fmap documentNode $ documentParse "<test id=\"1\" extra=\"2\" /><test id=\"2\" /><b><test id=\"3\" /></b><test id=\"4\" /><test />"
37+ map nodeName (nodeChildren doc) === ["test","test","b","test","test"]
38+ length (nodeChildrenBy doc "test") === 4
39+ length (nodeChildrenBy doc "b") === 1
40+ length (nodeChildrenBy doc "extra") === 0
41+ nodeAttributes (head $ nodeChildren doc) === [Attribute "id" "1", Attribute "extra" "2"]
42+ map (`nodeAttributeBy` "id") (nodeChildrenBy doc "test") === map (fmap (Attribute "id")) [Just "1", Just "2", Just "4", Nothing]
43+
44+
45+a === b = if a == b then putStrLn "success" else fail "mismatch"
3646
3747rerender :: Document -> BS.ByteString
3848rerender = contents . documentNode
src/Text/XML/Hexml.hs+1−1
@@ -58,7 +58,7 @@ data Document = Document BS.ByteString (ForeignPtr CDocument)
5858
5959data Node = Node BS.ByteString (ForeignPtr CDocument) (Ptr CNode)
6060
61−data Attribute = Attribute BS.ByteString BS.ByteString deriving Show
61+data Attribute = Attribute BS.ByteString BS.ByteString deriving (Show, Eq, Ord)
6262
6363instance Show Document where
6464 show d = "Document " ++ show (BS.unpack $ nodeOuter $ documentNode d)