2012-11-19 13:59:55 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2011-02-09 17:11:24 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Hakyll.Web.Template.Tests
|
|
|
|
( tests
|
|
|
|
) where
|
|
|
|
|
2012-11-19 13:59:55 +00:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2012-11-19 14:12:53 +00:00
|
|
|
import Data.Monoid (mconcat)
|
2012-11-19 13:59:55 +00:00
|
|
|
import Test.Framework (Test, testGroup)
|
|
|
|
import Test.Framework.Providers.HUnit (testCase)
|
2013-01-16 09:50:01 +00:00
|
|
|
import Test.HUnit (Assertion, (@=?), (@?=))
|
2012-11-19 13:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Hakyll.Core.Item
|
|
|
|
import Hakyll.Core.Provider
|
2012-12-15 17:02:47 +00:00
|
|
|
import Hakyll.Web.Pandoc
|
2012-11-19 13:59:55 +00:00
|
|
|
import Hakyll.Web.Template
|
|
|
|
import Hakyll.Web.Template.Context
|
2013-01-16 09:50:01 +00:00
|
|
|
import Hakyll.Web.Template.Internal
|
|
|
|
import Hakyll.Web.Template.List
|
2012-11-19 13:59:55 +00:00
|
|
|
import TestSuite.Util
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
tests :: Test
|
|
|
|
tests = testGroup "Hakyll.Core.Template.Tests"
|
2013-01-16 09:50:01 +00:00
|
|
|
[ testCase "case01" case01
|
|
|
|
, testCase "applyJoinTemplateList" testApplyJoinTemplateList
|
2011-02-09 17:11:24 +00:00
|
|
|
]
|
|
|
|
|
2012-11-19 13:59:55 +00:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
case01 :: Assertion
|
2013-01-06 17:33:00 +00:00
|
|
|
case01 = do
|
|
|
|
store <- newTestStore
|
2012-11-19 13:59:55 +00:00
|
|
|
provider <- newTestProvider store
|
|
|
|
|
2012-11-19 14:12:53 +00:00
|
|
|
out <- resourceString provider "template.html.out"
|
2013-01-06 17:33:00 +00:00
|
|
|
tpl <- testCompilerDone store provider "template.html" $
|
|
|
|
templateCompiler
|
2012-11-19 13:59:55 +00:00
|
|
|
item <- testCompilerDone store provider "example.md" $
|
2012-12-15 17:02:47 +00:00
|
|
|
pandocCompiler >>= applyTemplate (itemBody tpl) testContext
|
2012-11-19 13:59:55 +00:00
|
|
|
|
|
|
|
out @=? itemBody item
|
2013-02-09 14:11:40 +00:00
|
|
|
cleanTestEnv
|
2012-11-19 14:12:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
testContext :: Context String
|
|
|
|
testContext = mconcat
|
|
|
|
[ functionField "echo" (\args _ -> return $ unwords args)
|
|
|
|
, defaultContext
|
|
|
|
]
|
2013-01-16 09:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
testApplyJoinTemplateList :: Assertion
|
|
|
|
testApplyJoinTemplateList = do
|
|
|
|
store <- newTestStore
|
|
|
|
provider <- newTestProvider store
|
|
|
|
str <- testCompilerDone store provider "item3" $
|
|
|
|
applyJoinTemplateList ", " tpl defaultContext [i1, i2]
|
|
|
|
|
|
|
|
str @?= "<b>Hello</b>, <b>World</b>"
|
2013-02-09 14:11:40 +00:00
|
|
|
cleanTestEnv
|
2013-01-16 09:50:01 +00:00
|
|
|
where
|
|
|
|
i1 = Item "item1" "Hello"
|
|
|
|
i2 = Item "item2" "World"
|
|
|
|
tpl = Template [Chunk "<b>", Key "body", Chunk "</b>"]
|