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