]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Html.hs
Use test-framework instead of bare HUnit for the test suite.
[dead/halcyon.git] / src / Html.hs
1 module Html
2 where
3
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)
8
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
17
18
19 html_tests :: Test
20 html_tests =
21 testGroup "HTML Tests" [ tc1 ]
22 where
23 tc1 = testCase
24 "All entities are replaced correctly."
25 test_replace_entities
26
27 test_replace_entities :: Assertion
28 test_replace_entities =
29 assertEqual description expected_text actual_text
30 where
31 description = "All entities are replaced correctly."
32 actual_text =
33 replace_entities $
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.”"
38 expected_text =
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.”"