module Html (
html_tests,
replace_entities )
where
import Test.Tasty ( TestTree, testGroup )
import Test.Tasty.HUnit ( (@?=), testCase )
import Text.HTML.TagSoup.Entity ( lookupEntity )
replace_entities :: String -> String
replace_entities [] = []
replace_entities ('&':xs) =
let (b, a) = break (== ';') xs in
case (lookupEntity b, a) of
(Just s, ';':as) -> s ++ replace_entities as
_ -> '&' : replace_entities xs
replace_entities (x:xs) = x : replace_entities xs
html_tests :: TestTree
html_tests =
testGroup "HTML Tests" [ test_replace_entities ]
test_replace_entities :: TestTree
test_replace_entities =
testCase description $ actual @?= expected
where
description = "all entities are replaced correctly."
actual =
replace_entities $
""The moon is gay……" " ++
"said <insert the current president of the " ++
"United States of America>. “It’s " ++
"OK—–he’s not a real doctor.”"
expected =
"\"The moon is gay……\" said . " ++
"“It’s OK—–he’s not a real doctor.”"