{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- {{{ Imports
import Text.RSS.Conduit.Parse as Parser
import Text.RSS.Conduit.Render as Renderer
import Text.RSS.Extensions
import Text.RSS.Extensions.Atom
import Text.RSS.Extensions.Content
import Text.RSS.Extensions.DublinCore
import Text.RSS.Extensions.Syndication
import Text.RSS.Lens
import Text.RSS.Types
import Text.RSS1.Conduit.Parse as Parser
import Conduit
import Control.Exception.Safe as Exception
import Control.Monad
import Control.Monad.Trans.Resource
import Data.Char
import Data.Conduit
import Data.Conduit.List
import Data.Default
import Data.Maybe
import Data.String
import qualified Data.Text.Lazy.Encoding as Lazy
import Data.Time.Calendar hiding (DayOfWeek (..))
import Data.Time.LocalTime
import Data.Version
import Data.Void
import Data.XML.Types
import Lens.Micro
import System.FilePath
import System.IO
import System.Timeout
import Test.Tasty
import Test.Tasty.Golden (findByExtension, goldenVsString)
import Test.Tasty.HUnit
import Text.Atom.Conduit.Parse
import Text.Atom.Types
import Text.XML.Stream.Parse as XML hiding (choose)
import Text.XML.Stream.Render
import URI.ByteString
import URI.ByteString.QQ
-- }}}
main :: IO ()
main = do
goldenTests <- genGoldenTests
defaultMain $ testGroup "Tests"
[ unitTests
, goldenTests
]
unitTests :: TestTree
unitTests = testGroup "Unit tests"
[ skipHoursCase
, skipDaysCase
, rss1TextInputCase
, rss2TextInputCase
, rss1ImageCase
, rss2ImageCase
, categoryCase
, cloudCase
, guidCase
, enclosureCase
, sourceCase
, rss1ItemCase
, rss2ItemCase1
, rss2ItemCase2
, rss1ChannelItemsCase
, rss1DocumentCase
, dublinCoreChannelCase
, dublinCoreItemCase
, contentItemCase
, syndicationChannelCase
, atomChannelCase
, multipleExtensionsCase
]
genGoldenTests :: IO TestTree
genGoldenTests = do
xmlFiles <- findByExtension [".xml"] "."
return $ testGroup "RSS golden tests" $ do
xmlFile <- xmlFiles
let goldenFile = addExtension xmlFile ".golden"
f file = fmap (Lazy.encodeUtf8 . fromString . show) $ runResourceT $ runConduit $ sourceFile file .| Conduit.decodeUtf8C .| XML.parseText' def .| parser
parser = rssDocument :: MonadThrow m => ConduitM Event o m (Maybe (RssDocument NoExtensions))
return $ goldenVsString xmlFile goldenFile $ f xmlFile
skipHoursCase :: TestTree
skipHoursCase = testCase "
What a beautiful day!
" (AtomItem (Just link) NoItemExtensions) where input = [ "