hakyll/tests/Hakyll/Core/Routes/Tests.hs

53 lines
1.9 KiB
Haskell
Raw Normal View History

2012-11-26 15:11:37 +00:00
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Routes.Tests
( tests
) where
2012-11-26 15:11:37 +00:00
--------------------------------------------------------------------------------
2014-01-03 14:56:27 +00:00
import qualified Data.Map as M
import System.FilePath ((</>))
2012-11-26 15:11:37 +00:00
import Test.Framework (Test, testGroup)
2013-01-21 21:45:50 +00:00
import Test.HUnit (Assertion, (@=?))
2012-11-26 15:11:37 +00:00
--------------------------------------------------------------------------------
import Hakyll.Core.Identifier
import Hakyll.Core.Routes
import TestSuite.Util
--------------------------------------------------------------------------------
tests :: Test
tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
2013-01-21 21:45:50 +00:00
[ 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"
2011-02-28 21:40:23 +00:00
2013-01-21 21:45:50 +00:00
, testRoutes "neve ro ddo reven"
(customRoute (reverse . toFilePath )) "never odd or even"
2012-05-29 21:39:07 +00:00
2013-01-21 21:45:50 +00:00
, testRoutes "foo" (constRoute "foo") "bar"
2012-05-29 21:39:07 +00:00
2013-01-21 21:45:50 +00:00
, testRoutes "tags/bar.xml" (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
, testRoutes "tags/bar.xml"
(gsubRoute "rss/" (const "") `composeRoutes` setExtension "xml")
"tags/rss/bar"
2014-01-03 14:56:27 +00:00
, testRoutes "food/example.md" (metadataRoute $ \md -> customRoute $ \id' ->
M.findWithDefault "?" "subblog" md </> toFilePath id')
"example.md"
]
2013-01-21 21:45:50 +00:00
--------------------------------------------------------------------------------
testRoutes :: FilePath -> Routes -> Identifier -> Assertion
testRoutes expected r id' = do
2014-01-03 14:56:27 +00:00
store <- newTestStore
provider <- newTestProvider store
(route, _) <- runRoutes r provider id'
2013-01-21 21:45:50 +00:00
Just expected @=? route
2014-01-03 14:56:27 +00:00
cleanTestEnv