diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-02-09 18:11:24 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-02-09 18:11:24 +0100 |
commit | 002cf4de32db979d515c2a9cdcd8c8f42859a797 (patch) | |
tree | 6992a3f05e693116ae6802ef48448a5a03aded1e /tests/Hakyll/Web/Template | |
parent | 7da7e0b96c245a14122896c24dcee52f038e583a (diff) | |
download | hakyll-002cf4de32db979d515c2a9cdcd8c8f42859a797.tar.gz |
Add hamlet templates and restructure tests
Diffstat (limited to 'tests/Hakyll/Web/Template')
-rw-r--r-- | tests/Hakyll/Web/Template/Tests.hs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs new file mode 100644 index 0000000..d95b151 --- /dev/null +++ b/tests/Hakyll/Web/Template/Tests.hs @@ -0,0 +1,46 @@ +{-# LANGUAGE OverloadedStrings #-} +module Hakyll.Web.Template.Tests + ( tests + ) where + +import Test.Framework +import Test.Framework.Providers.HUnit +import Test.HUnit hiding (Test) + +import qualified Data.Map as M + +import Hakyll.Web.Page +import Hakyll.Web.Template +import Hakyll.Web.Template.Read.Hakyll +import Hakyll.Web.Template.Read.Hamlet +import TestSuite.Util + +tests :: [Test] +tests = fromAssertions "applyTemplate" + -- Hakyll templates + [ applyTemplateAssertion readTemplate + "bar" "$foo$" [("foo", "bar")] + + , applyTemplateAssertion readTemplate + "$ barqux" "$$ $foo$$bar$" [("foo", "bar"), ("bar", "qux")] + + -- Hamlet templates + , applyTemplateAssertion readHamletTemplate + "<head><title>notice</title></head><body>A paragraph</body>" + "<head\n\ + \ <title>#{title}\n\ + \<body\n\ + \ A paragraph\n" + [("title", "notice")] + ] + +-- | Utility function to create quick template tests +-- +applyTemplateAssertion :: (String -> Template) -- ^ Template parser + -> String -- ^ Expected + -> String -- ^ Template + -> [(String, String)] -- ^ Page + -> Assertion -- ^ Resulting assertion +applyTemplateAssertion parser expected template page = + expected @=? pageBody (applyTemplate (parser template) + (fromMap $ M.fromList page)) |