]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Html.hs
Add missing Html.hs from previous commit.
[dead/halcyon.git] / src / Html.hs
1 module Html
2 where
3
4 import Test.HUnit
5 import Text.HTML.TagSoup.Entity (lookupEntity)
6
7 replace_entities :: String -> String
8 replace_entities [] = []
9 replace_entities ('&':xs) =
10 let (b, a) = break (== ';') xs in
11 case (lookupEntity b, a) of
12 (Just c, ';':as) -> c : replace_entities as
13 _ -> '&' : replace_entities xs
14 replace_entities (x:xs) = x : replace_entities xs
15
16
17 html_tests :: [Test]
18 html_tests = [ test_replace_entities ]
19
20 test_replace_entities :: Test
21 test_replace_entities =
22 TestCase $ assertEqual description expected_text actual_text
23 where
24 description = "All entities are replaced correctly."
25 actual_text =
26 replace_entities $
27 ""The moon is gay……" " ++
28 "said <insert the current president of the " ++
29 "United States of America>. “It’s " ++
30 "OK—–he’s not a real doctor.”"
31 expected_text =
32 "\"The moon is gay……\" said <insert " ++
33 "the current president of the United States of America>. " ++
34 "“It’s OK—–he’s not a real doctor.”"