6 import Test.Tasty ( TestTree, testGroup )
7 import Test.Tasty.HUnit ( (@?=), testCase )
8 import Text.HTML.TagSoup.Entity ( lookupEntity )
10 replace_entities :: String -> String
11 replace_entities [] = []
12 replace_entities ('&':xs) =
13 let (b, a) = break (== ';') xs in
14 case (lookupEntity b, a) of
15 (Just s, ';':as) -> s ++ replace_entities as
16 _ -> '&' : replace_entities xs
17 replace_entities (x:xs) = x : replace_entities xs
20 html_tests :: TestTree
22 testGroup "HTML Tests" [ test_replace_entities ]
25 test_replace_entities :: TestTree
26 test_replace_entities =
27 testCase description $ actual @?= expected
29 description = "all entities are replaced correctly."
32 ""The moon is gay……" " ++
33 "said <insert the current president of the " ++
34 "United States of America>. “It’s " ++
35 "OK—–he’s not a real doctor.”"
37 "\"The moon is gay……\" said <insert " ++
38 "the current president of the United States of America>. " ++
39 "“It’s OK—–he’s not a real doctor.”"