summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Core/Dependencies/Tests.hs
blob: efa848bc4d738a14a02e2094204064adbb7febc5 (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
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Dependencies.Tests
    ( tests
    ) where


--------------------------------------------------------------------------------
import           Data.List                (delete)
import qualified Data.Map                 as M
import qualified Data.Set                 as S
import           Test.Framework           (Test, testGroup)
import           Test.HUnit               (Assertion, (@=?))


--------------------------------------------------------------------------------
import           Hakyll.Core.Dependencies
import           Hakyll.Core.Identifier
import           TestSuite.Util


--------------------------------------------------------------------------------
tests :: Test
tests = testGroup "Hakyll.Core.Dependencies.Tests" $
    fromAssertions "analyze" [case01, case02, case03]


--------------------------------------------------------------------------------
oldUniverse :: [Identifier]
oldUniverse = M.keys oldFacts


--------------------------------------------------------------------------------
oldFacts :: DependencyFacts
oldFacts = M.fromList
    [ ("posts/01.md",
        [])
    , ("posts/02.md",
        [])
    , ("index.md",
        [ PatternDependency "posts/*"
            (S.fromList ["posts/01.md", "posts/02.md"])
        , IdentifierDependency "posts/01.md"
        , IdentifierDependency "posts/02.md"
        ])
    ]


--------------------------------------------------------------------------------
-- | posts/02.md has changed
case01 :: Assertion
case01 = S.fromList ["posts/02.md", "index.md"] @=? ood
  where
    (ood, _, _) = outOfDate oldUniverse (S.singleton "posts/02.md") oldFacts


--------------------------------------------------------------------------------
-- | about.md was added
case02 :: Assertion
case02 = S.singleton "about.md" @=? ood
  where
    (ood, _, _) = outOfDate ("about.md" : oldUniverse) S.empty oldFacts


--------------------------------------------------------------------------------
-- | posts/01.md was removed
case03 :: Assertion
case03 = S.singleton "index.md" @=? ood
  where
    (ood, _, _) =
        outOfDate ("posts/01.md" `delete` oldUniverse) S.empty oldFacts