summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Web/Page/Metadata/Tests.hs
blob: f14bfecf6e1525ec44f37727989b3bff46fde194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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") ""
        ]

    , 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")
        ]
    ]