summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Web
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-19 14:59:55 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-19 14:59:55 +0100
commit88ffd3c5bea6b5e5cb1004173130b5691a7591f6 (patch)
tree8205d11882dc3a78f6ea03fe0adef390bc023670 /tests/Hakyll/Web
parent6b5c299ec945cdfea2dbf2df0922f8753588b729 (diff)
downloadhakyll-88ffd3c5bea6b5e5cb1004173130b5691a7591f6.tar.gz
Add tests again
Diffstat (limited to 'tests/Hakyll/Web')
-rw-r--r--tests/Hakyll/Web/Template/Tests.hs81
1 files changed, 33 insertions, 48 deletions
diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs
index 991a76f..42be506 100644
--- a/tests/Hakyll/Web/Template/Tests.hs
+++ b/tests/Hakyll/Web/Template/Tests.hs
@@ -1,55 +1,40 @@
+--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Web.Template.Tests
( tests
) where
-import Test.Framework
-import Test.HUnit hiding (Test)
-
-import qualified Data.Map as M
-
-import Hakyll.Web.Page
-import Hakyll.Web.Template
-import Hakyll.Web.Template.Read
-import TestSuite.Util
-
-tests :: [Test]
-tests = fromAssertions "applyTemplate"
- -- Hakyll templates
- [ applyTemplateAssertion readTemplate applyTemplate
- ("bar" @=?) "$foo$" [("foo", "bar")]
-
- , applyTemplateAssertion readTemplate applyTemplate
- ("$ barqux" @=?) "$$ $foo$$bar$" [("foo", "bar"), ("bar", "qux")]
-
- , applyTemplateAssertion readTemplate applyTemplate
- ("$foo$" @=?) "$foo$" []
-
- -- Hamlet templates
- , applyTemplateAssertion readHamletTemplate applyTemplate
- (("<head><title>notice</title></head><body>A paragraph</body>" @=?) .
- filter (/= '\n'))
- "<head>\n\
- \ <title>#{title}\n\
- \<body>\n\
- \ A paragraph\n"
- [("title", "notice")]
-
- -- Missing keys
- , let missing "foo" = "bar"
- missing "bar" = "qux"
- missing x = reverse x
- in applyTemplateAssertion readTemplate (applyTemplateWith missing)
- ("bar foo ver" @=?) "$foo$ $bar$ $rev$" [("bar", "foo")]
+
+--------------------------------------------------------------------------------
+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.Page
+import Hakyll.Web.Template
+import Hakyll.Web.Template.Context
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Core.Template.Tests"
+ [ testCase "case01" case01
]
--- | Utility function to create quick template tests
---
-applyTemplateAssertion :: (String -> Template)
- -> (Template -> Page String -> Page String)
- -> (String -> Assertion)
- -> String
- -> [(String, String)]
- -> Assertion
-applyTemplateAssertion parser apply correct template page =
- correct $ pageBody (apply (parser template) (fromMap $ M.fromList page))
+
+--------------------------------------------------------------------------------
+case01 :: Assertion
+case01 = withTestStore $ \store -> do
+ provider <- newTestProvider store
+
+ out <- resourceString provider "example.md.out"
+ tpl <- testCompilerDone store provider "template.html" $ templateCompiler
+ item <- testCompilerDone store provider "example.md" $
+ pageCompiler >>= applyTemplate (itemBody tpl) defaultContext
+
+ out @=? itemBody item