Debian Codegraph @

tests/Hakyll/Web/Template/Context/Tests.hs

raw
1 --------------------------------------------------------------------------------
2 {-# LANGUAGE OverloadedStrings #-}
3 module Hakyll.Web.Template.Context.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.Identifier
16 import Hakyll.Core.Provider
17 import Hakyll.Core.Store (Store)
18 import Hakyll.Web.Template.Context
19 import TestSuite.Util
20
21
22 --------------------------------------------------------------------------------
23 tests :: TestTree
24 tests = testGroup "Hakyll.Web.Template.Context.Tests"
25 [ testCase "testDateField" testDateField
26 ]
27
28
29 --------------------------------------------------------------------------------
30 testDateField :: Assertion
31 testDateField = do
32 store <- newTestStore
33 provider <- newTestProvider store
34
35 date1 <- testContextDone store provider "example.md" "date" $
36 dateField "date" "%B %e, %Y"
37 date1 @=? "October 22, 2012"
38
39 date2 <- testContextDone store provider
40 "posts/2010-08-26-birthday.md" "date" $
41 dateField "date" "%B %e, %Y"
42 date2 @=? "August 26, 2010"
43
44 date3 <- testContextDone store provider
45 "posts/2018-09-26.md" "date" $
46 dateField "date" "%B %e, %Y"
47 date3 @=? "September 26, 2018"
48
49 date4 <- testContextDone store provider
50 "posts/2019/05/10/tomorrow.md" "date" $
51 dateField "date" "%B %e, %Y"
52 date4 @=? "May 10, 2019"
53 cleanTestEnv
54
55
56 --------------------------------------------------------------------------------
57 testContextDone :: Store -> Provider -> Identifier -> String
58 -> Context String -> IO String
59 testContextDone store provider identifier key context =
60 testCompilerDone store provider identifier $ do
61 item <- getResourceBody
62 cf <- unContext context key [] item
63 case cf of
64 StringField str -> return str
65 _ -> error $
66 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
67 "expected StringField"