From 88ffd3c5bea6b5e5cb1004173130b5691a7591f6 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 19 Nov 2012 14:59:55 +0100 Subject: Add tests again --- tests/Hakyll/Web/Template/Tests.hs | 81 ++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 48 deletions(-) (limited to 'tests/Hakyll/Web/Template') 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 - (("noticeA paragraph" @=?) . - filter (/= '\n')) - "\n\ - \ #{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 -- cgit v1.2.3