]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Html.hs
Bump all dependencies and switch from test-framework to tasty for tests.
[dead/halcyon.git] / src / Html.hs
1 module Html (
2 html_tests,
3 replace_entities )
4 where
5
6 import Test.Tasty ( TestTree, testGroup )
7 import Test.Tasty.HUnit ( (@?=), testCase )
8 import Text.HTML.TagSoup.Entity ( lookupEntity )
9
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
18
19
20 html_tests :: TestTree
21 html_tests =
22 testGroup "HTML Tests" [ test_replace_entities ]
23
24
25 test_replace_entities :: TestTree
26 test_replace_entities =
27 testCase description $ actual @?= expected
28 where
29 description = "all entities are replaced correctly."
30 actual =
31 replace_entities $
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.”"
36 expected =
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.”"