summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Web/Template/Tests.hs
blob: 6c5c77a64a910a36a08114bb9fcaa80bda0a3c66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Web.Template.Tests
    ( tests
    ) where


--------------------------------------------------------------------------------
import           Data.Monoid                    (mconcat)
import           Test.Framework                 (Test, testGroup)
import           Test.Framework.Providers.HUnit (testCase)
import           Test.HUnit                     (Assertion, (@=?))


--------------------------------------------------------------------------------
import           Hakyll.Core.Item
import           Hakyll.Core.Provider
import           Hakyll.Web.Pandoc
import           Hakyll.Web.Template
import           Hakyll.Web.Template.Context
import           TestSuite.Util


--------------------------------------------------------------------------------
tests :: Test
tests = testGroup "Hakyll.Core.Template.Tests"
    [ testCase "case01" case01
    ]


--------------------------------------------------------------------------------
case01 :: Assertion
case01 = withTestStore $ \store -> do
    provider <- newTestProvider store

    out  <- resourceString provider "template.html.out"
    tpl  <- testCompilerDone store provider "template.html" $ templateCompiler
    item <- testCompilerDone store provider "example.md"    $
        pandocCompiler >>= applyTemplate (itemBody tpl) testContext

    out @=? itemBody item


--------------------------------------------------------------------------------
testContext :: Context String
testContext = mconcat
    [ functionField "echo" (\args _ -> return $ unwords args)
    , defaultContext
    ]