on master help sign in
Add a recursive check that the find functions work properly
8b0f045Neil Mitchell
src/Main.hs+11
@@ -28,6 +28,7 @@ main = do
28 Left err -> when parses $ fail $ "Unexpected parse failure, " ++ show err
28 Left err -> when parses $ fail $ "Unexpected parse failure, " ++ show err
29 Right doc -> do
29 Right doc -> do
30 unless parses $ fail "Unexpected parse success"
30 unless parses $ fail "Unexpected parse success"
31+ checkFind doc
31 let r = render doc
32 let r = render doc
32 print r
33 print r
33 print $ rerender doc
34 print $ rerender doc
@@ -54,6 +55,16 @@ main = do
54 putStrLn "Done"
55 putStrLn "Done"
55
56
56
57
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+
57a === b = if a == b then putStrLn "success" else fail "mismatch"
68a === b = if a == b then putStrLn "success" else fail "mismatch"
58
69
59rerender :: Node -> BS.ByteString
70rerender :: Node -> BS.ByteString