4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
6 import Test.HUnit (Assertion, assertEqual)
7 import Text.HTML.TagSoup.Entity (lookupEntity)
9 replace_entities :: String -> String
10 replace_entities [] = []
11 replace_entities ('&':xs) =
12 let (b, a) = break (== ';') xs in
13 case (lookupEntity b, a) of
14 (Just c, ';':as) -> c : replace_entities as
15 _ -> '&' : replace_entities xs
16 replace_entities (x:xs) = x : replace_entities xs
21 testGroup "HTML Tests" [ tc1 ]
24 "All entities are replaced correctly."
27 test_replace_entities :: Assertion
28 test_replace_entities =
29 assertEqual description expected_text actual_text
31 description = "All entities are replaced correctly."
34 ""The moon is gay……" " ++
35 "said <insert the current president of the " ++
36 "United States of America>. “It’s " ++
37 "OK—–he’s not a real doctor.”"
39 "\"The moon is gay……\" said <insert " ++
40 "the current president of the United States of America>. " ++
41 "“It’s OK—–he’s not a real doctor.”"