diff options
Diffstat (limited to 'tests/Hakyll/Web')
-rw-r--r-- | tests/Hakyll/Web/Page/Metadata/Tests.hs | 77 | ||||
-rw-r--r-- | tests/Hakyll/Web/Page/Tests.hs | 40 | ||||
-rw-r--r-- | tests/Hakyll/Web/Template/Context/Tests.hs | 51 |
3 files changed, 51 insertions, 117 deletions
diff --git a/tests/Hakyll/Web/Page/Metadata/Tests.hs b/tests/Hakyll/Web/Page/Metadata/Tests.hs deleted file mode 100644 index badb9fb..0000000 --- a/tests/Hakyll/Web/Page/Metadata/Tests.hs +++ /dev/null @@ -1,77 +0,0 @@ -module Hakyll.Web.Page.Metadata.Tests - ( tests - ) where - -import Test.Framework -import Test.HUnit hiding (Test) - -import qualified Data.Map as M -import Data.Monoid (mempty) -import Data.Char (toLower) - -import Hakyll.Web.Page -import Hakyll.Web.Page.Metadata -import TestSuite.Util - -tests :: [Test] -tests = concat $ - [ fromAssertions "getField" - [ "bar" @=? getField "foo" (Page (M.singleton "foo" "bar") "body\n") - , "" @=? getField "foo" (Page M.empty "body") - ] - - , fromAssertions "getFieldMaybe" - [ Just "bar" @=? getFieldMaybe "foo" (Page (M.singleton "foo" "bar") "") - , Nothing @=? getFieldMaybe "foo" (Page M.empty "body") - ] - - , fromAssertions "setField" - [ (Page (M.singleton "bar" "foo") "") @=? setField "bar" "foo" mempty - , (Page (M.singleton "bar" "foo") "") @=? - setField "bar" "foo" (Page (M.singleton "bar" "qux") "") - ] - - , fromAssertions "trySetField" - [ (Page (M.singleton "bar" "foo") "") @=? trySetField "bar" "foo" mempty - , (Page (M.singleton "bar" "qux") "") @=? - trySetField "bar" "foo" (Page (M.singleton "bar" "qux") "") - ] - - , fromAssertions "setFieldA" - [ (Page (M.singleton "bar" "foo") "") @=? - setFieldA "bar" (map toLower) (mempty, "FOO") - ] - - , fromAssertions "renderDateField" - [ (@=?) "January 31, 2010" $ getField "date" $ renderDateField - "date" "%B %e, %Y" "Date unknown" $ Page - (M.singleton "path" "/posts/2010-01-31-a-post.mkdwn") "" - , (@=?) "Date unknown" $ getField "date" $ renderDateField - "date" "%B %e, %Y" "Date unknown" $ Page - (M.singleton "path" "/posts/a-post.mkdwn") "" - , (@=?) "February 20, 2000" $ getField "date" $ renderDateField - "date" "%B %e, %Y" "Date unknown" $ flip Page "" $ M.fromList - [ ("path", "/posts/2010-01-31-a-post.mkdwn") - , ("published", "February 20, 2000 1:00 PM") - ] - , (@=?) "October 22, 2012" $ getField "date" $ renderDateField - "date" "%B %e, %Y" "Date unknown" $ Page - (M.singleton "date" "2012-10-22 14:35:24") "" - ] - - , fromAssertions "copyBodyToField" - [ (Page (M.singleton "bar" "foo") "foo") @=? - copyBodyToField "bar" (Page M.empty "foo") - ] - - , fromAssertions "copyBodyFromField" - [ (Page (M.singleton "bar" "foo") "foo") @=? - copyBodyFromField "bar" (Page (M.singleton "bar" "foo") "qux") - ] - - , fromAssertions "comparePagesByDate" - [ GT @=? comparePagesByDate - (Page (M.singleton "path" "/posts/1990-08-26-foo.mkdwn") "") - (Page (M.singleton "path" "/posts/1990-06-18-qux.mkdwn") "") - ] - ] diff --git a/tests/Hakyll/Web/Page/Tests.hs b/tests/Hakyll/Web/Page/Tests.hs deleted file mode 100644 index 8e01302..0000000 --- a/tests/Hakyll/Web/Page/Tests.hs +++ /dev/null @@ -1,40 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module Hakyll.Web.Page.Tests - ( tests - ) where - -import Test.Framework -import Test.HUnit hiding (Test) - -import qualified Data.Map as M - -import Hakyll.Web.Page -import Hakyll.Web.Page.Read -import TestSuite.Util - -tests :: [Test] -tests = fromAssertions "readPage" - [ Page (M.singleton "foo" "bar") "body" @=? readPage - "--- \n\ - \foo: bar \n\ - \--- \n\ - \body" - - , Page M.empty "line one\nlijn twee" @=? readPage - "line one\n\ - \lijn twee" - - , Page (M.fromList [("field1", "unos"), ("veld02", "deux")]) "" @=? readPage - "---\n\ - \veld02: deux\n\ - \field1: unos\n\ - \---\n" - - , Page (M.fromList [("author", "jasper"), ("title", "lol")]) "O hai\n" - @=? readPage - "---\n\ - \author: jasper\n\ - \title: lol\n\ - \...\n\ - \O hai\n" - ] diff --git a/tests/Hakyll/Web/Template/Context/Tests.hs b/tests/Hakyll/Web/Template/Context/Tests.hs new file mode 100644 index 0000000..f2fb42a --- /dev/null +++ b/tests/Hakyll/Web/Template/Context/Tests.hs @@ -0,0 +1,51 @@ +-------------------------------------------------------------------------------- +{-# LANGUAGE OverloadedStrings #-} +module Hakyll.Web.Template.Context.Tests + ( tests + ) where + + +-------------------------------------------------------------------------------- +import Test.Framework (Test, testGroup) +import Test.Framework.Providers.HUnit (testCase) +import Test.HUnit (Assertion, (@=?)) + + +-------------------------------------------------------------------------------- +import Hakyll.Core.Compiler +import Hakyll.Core.Identifier +import Hakyll.Core.Provider +import Hakyll.Core.Store (Store) +import Hakyll.Web.Template.Context +import TestSuite.Util + + +-------------------------------------------------------------------------------- +tests :: Test +tests = testGroup "Hakyll.Core.Template.Context.Tests" + [ testCase "testDateField" testDateField + ] + + +-------------------------------------------------------------------------------- +testDateField :: Assertion +testDateField = withTestStore $ \store -> do + provider <- newTestProvider store + + date1 <- testContextDone store provider "example.md" "date" $ + dateField "date" "%B %e, %Y" + date1 @=? "October 22, 2012" + + date2 <- testContextDone store provider + "posts/2010-08-26-birthday.md" "date" $ + dateField "date" "%B %e, %Y" + date2 @=? "August 26, 2010" + + +-------------------------------------------------------------------------------- +testContextDone :: Store -> Provider -> Identifier -> String + -> Context String -> IO String +testContextDone store provider identifier key context = + testCompilerDone store provider identifier $ do + item <- getResourceBody + unContext context key item |