summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Web/Page/Metadata/Tests.hs
blob: e3ceed928e1827979cfbdd8eab1dd51c8123c42a (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
64
65
66
67
68
69
70
71
72
73
74
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")
                ]
        ]

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