https://gitlab.inria.fr/abrenon/soprano
Tip revision: 3fc6efcf5444dee0c690d4d57aab06a50593ad8a authored by Alice Brenon on 25 November 2025, 13:33:00 UTC
Switch license to GPLv3 (https://www.gnu.org/licenses/gpl.html)
Switch license to GPLv3 (https://www.gnu.org/licenses/gpl.html)
Tip revision: 3fc6efc
Cleaning.hs
{-# LANGUAGE NamedFieldPuns #-}
module Cleaning (
testCleaning
) where
import Control.Monad.IO.Class (liftIO)
import Data.Map as Map (Map, (!), fromList, keys)
import Distribution.TestSuite (Progress(..), Result(..), Test, testGroup)
import Mock.Resource (simpleTest)
import Mock.XML (leafElements)
import Text.XML.Light.ALTO.Clean (text)
import Text.XML.Light.ALTO.Dump (dumpString)
import Text.XML.Light.ALTO.RectElement (RectElement(..))
import Text.Printf (printf)
testFilterString :: String -> Test
testFilterString key = simpleTest testName [] $ do
actual <- (fmap $ head . dumpString . xml) <$> text (leafElements ! key)
Finished <$>
if actual == filteredStrings ! key
then return Pass
else liftIO $ putStrLn (show actual) >> return (Fail "Wrong filtered output")
where
testName = printf "filter string %s" key
testFilterStrings :: Test
testFilterStrings = testGroup "filterString" $ testFilterString <$> inputs
where
inputs = Map.keys leafElements
filteredStrings :: Map String (Maybe String)
filteredStrings = Map.fromList [
("regular word", Just "Encyclopédie")
, ("word with noise", Just "Encyclopédie")
, ("word on denyList", Nothing)
]
testCleaning :: Test
testCleaning = testGroup "cleaning" [
testFilterStrings
]
