Debian Codegraph @

tests/Hakyll/Web/Feed/Tests.hs

raw
1 --------------------------------------------------------------------------------
2 {-# LANGUAGE OverloadedStrings #-}
3 module Hakyll.Web.Feed.Tests
4 ( tests
5 ) where
6
7
8 --------------------------------------------------------------------------------
9 import Test.Tasty (TestTree, testGroup)
10 import Test.Tasty.HUnit (Assertion, testCase)
11
12
13 --------------------------------------------------------------------------------
14 import Hakyll.Core.Compiler
15 import Hakyll.Core.Provider
16 import Hakyll.Web.Feed
17 import Hakyll.Web.Template.Context
18 import TestSuite.Util
19 --------------------------------------------------------------------------------
20 tests :: TestTree
21 tests = testGroup "Hakyll.Web.Feed.Tests"
22 [ testCase "validateSucceeds" validateSucceeds
23 , testCase "validateFails" validateFails
24 ]
25
26 validateFails :: Assertion
27 validateFails = do
28 store <- newTestStore
29 provider <- newTestProvider store
30
31 item <- testCompilerDone store provider "example.md"
32 $ makeItem (resourceFilePath provider "example.md")
33
34 testCompilerError store provider "feed.xml"
35 (renderRss feedConfiguration ctx [item])
36 "Generated feed contains invalid XML (perhaps you id not escape a metadata field?)"
37 cleanTestEnv
38 where
39 title = "invalid & not xml"
40 ctx = constField "title" title `mappend`
41 constField "description" "" `mappend`
42 defaultContext
43
44 validateSucceeds :: Assertion
45 validateSucceeds = do
46 store <- newTestStore
47 provider <- newTestProvider store
48
49 item <- testCompilerDone store provider "example.md"
50 $ makeItem (resourceFilePath provider "example.md")
51
52 _ <- testCompilerDone store provider "feed.xml"
53 $ renderRss feedConfiguration ctx [item]
54 cleanTestEnv
55 where
56 title = "valid xml"
57 ctx = constField "title" title `mappend`
58 constField "description" "" `mappend`
59 defaultContext
60
61 feedConfiguration :: FeedConfiguration
62 feedConfiguration = FeedConfiguration
63 { feedTitle = "test"
64 , feedDescription = "test"
65 , feedAuthorName = "test"
66 , feedAuthorEmail = ""
67 , feedRoot = "example.org"
68 }