blob: 4f975aeb394be012035ef9375d281687bb73395a (
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
|
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Routes.Tests
( tests
) where
--------------------------------------------------------------------------------
import qualified Data.Map as M
import System.FilePath ((</>))
import Test.Framework (Test, testGroup)
import Test.HUnit (Assertion, (@=?))
--------------------------------------------------------------------------------
import Hakyll.Core.Identifier
import Hakyll.Core.Routes
import TestSuite.Util
--------------------------------------------------------------------------------
tests :: Test
tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
[ testRoutes "foo.html" (setExtension "html") "foo"
, testRoutes "foo.html" (setExtension ".html") "foo"
, testRoutes "foo.html" (setExtension "html") "foo.markdown"
, testRoutes "foo.html" (setExtension ".html") "foo.markdown"
, testRoutes "neve ro ddo reven"
(customRoute (reverse . toFilePath )) "never odd or even"
, testRoutes "foo" (constRoute "foo") "bar"
, testRoutes "tags/bar.xml" (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
, testRoutes "tags/bar.xml"
(gsubRoute "rss/" (const "") `composeRoutes` setExtension "xml")
"tags/rss/bar"
, testRoutes "food/example.md" (metadataRoute $ \md -> customRoute $ \id' ->
M.findWithDefault "?" "subblog" md </> toFilePath id')
"example.md"
]
--------------------------------------------------------------------------------
testRoutes :: FilePath -> Routes -> Identifier -> Assertion
testRoutes expected r id' = do
store <- newTestStore
provider <- newTestProvider store
(route, _) <- runRoutes r provider id'
Just expected @=? route
cleanTestEnv
|