on master help sign in
Add a recursive check that the find functions work properly
commit8b0f045169084fb3b9d1e823fc9df54a343c142e authorNeil Mitchell <ndmitchell@gmail.com> dateWed 30 Nov 2016, 19:08 (10 years ago) parent4acde7e
1 file changed+11
src/Main.hs+11
src/Main.hs+11
@@ -28,6 +28,7 @@ main = do
2828 Left err -> when parses $ fail $ "Unexpected parse failure, " ++ show err
2929 Right doc -> do
3030 unless parses $ fail "Unexpected parse success"
31+ checkFind doc
3132 let r = render doc
3233 print r
3334 print $ rerender doc
@@ -54,6 +55,16 @@ main = do
5455 putStrLn "Done"
5556
5657
58+checkFind :: Node -> IO ()
59+checkFind n = do
60+ forM_ (attributes n) $ \a -> attributeBy n (attributeName a) === Just a
61+ attributeBy n "xxx" === Nothing
62+ let cs = children n
63+ forM_ ("xxx":map name cs) $ \c ->
64+ map outer (filter ((==) c . name) cs) === map outer (childrenBy n c)
65+ mapM_ checkFind $ children n
66+
67+
5768a === b = if a == b then putStrLn "success" else fail "mismatch"
5869
5970rerender :: Node -> BS.ByteString