Debian Codegraph @

tests/Hakyll/Core/Routes/Tests.hs

raw
1 --------------------------------------------------------------------------------
2 {-# LANGUAGE OverloadedStrings #-}
3 module Hakyll.Core.Routes.Tests
4 ( tests
5 ) where
6
7
8 --------------------------------------------------------------------------------
9 import Data.Maybe (fromMaybe)
10 import Hakyll.Core.Identifier
11 import Hakyll.Core.Metadata
12 import Hakyll.Core.Routes
13 import System.FilePath ((</>), normalise)
14 import Test.Tasty (TestTree, testGroup)
15 import Test.Tasty.HUnit (Assertion, (@=?))
16 import TestSuite.Util
17
18
19 --------------------------------------------------------------------------------
20 tests :: TestTree
21 tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
22 [ testRoutes "foo.html" (setExtension "html") "foo"
23 , testRoutes "foo.html" (setExtension ".html") "foo"
24 , testRoutes "foo.html" (setExtension "html") "foo.markdown"
25 , testRoutes "foo.html" (setExtension ".html") "foo.markdown"
26
27 , testRoutes "neve ro ddo reven"
28 (customRoute (reverse . toFilePath )) "never odd or even"
29
30 , testRoutes "foo" (constRoute "foo") "bar"
31
32 , testRoutes "tags/bar.xml" (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
33 , testRoutes "tags/bar.xml"
34 (gsubRoute "rss/" (const "") `composeRoutes` setExtension "xml")
35 "tags/rss/bar"
36
37 , testRoutes "food/example.md" (metadataRoute $ \md -> customRoute $ \id' ->
38 fromMaybe "?" (lookupString "subblog" md) </> toFilePath id')
39 "example.md"
40 ]
41
42
43 --------------------------------------------------------------------------------
44 testRoutes :: FilePath -> Routes -> Identifier -> Assertion
45 testRoutes expected r id' = do
46 store <- newTestStore
47 provider <- newTestProvider store
48 (route, _) <- runRoutes r provider id'
49 Just (normalise expected) @=? route
50 cleanTestEnv