2012-11-26 15:11:37 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2011-05-24 12:40:45 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Hakyll.Core.Rules.Tests
|
2011-05-24 21:17:32 +00:00
|
|
|
( tests
|
|
|
|
) where
|
2011-05-24 12:40:45 +00:00
|
|
|
|
|
|
|
|
2012-11-26 15:11:37 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import qualified Data.Set as S
|
|
|
|
import Test.Framework (Test, testGroup)
|
|
|
|
import Test.Framework.Providers.HUnit (testCase)
|
|
|
|
import Test.HUnit (Assertion, assert, (@=?))
|
2011-05-24 12:40:45 +00:00
|
|
|
|
|
|
|
|
2012-11-26 15:11:37 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Hakyll.Core.Compiler
|
|
|
|
import Hakyll.Core.Identifier
|
2012-11-29 22:09:11 +00:00
|
|
|
import Hakyll.Core.Identifier.Pattern
|
2012-11-26 15:11:37 +00:00
|
|
|
import Hakyll.Core.Routes
|
|
|
|
import Hakyll.Core.Rules
|
|
|
|
import Hakyll.Core.Rules.Internal
|
2012-11-29 22:09:11 +00:00
|
|
|
import Hakyll.Core.Writable.CopyFile
|
2012-11-26 15:11:37 +00:00
|
|
|
import Hakyll.Web.Page
|
|
|
|
import TestSuite.Util
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
tests :: Test
|
|
|
|
tests = testGroup "Hakyll.Core.Rules.Tests"
|
2011-05-24 20:29:47 +00:00
|
|
|
[ testCase "runRules" rulesTest
|
|
|
|
]
|
|
|
|
|
2012-11-26 15:11:37 +00:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2011-05-24 20:29:47 +00:00
|
|
|
rulesTest :: Assertion
|
2012-11-26 15:11:37 +00:00
|
|
|
rulesTest = withTestStore $ \store -> do
|
|
|
|
provider <- newTestProvider store
|
|
|
|
ruleSet <- runRules rules provider
|
|
|
|
let identifiers = S.fromList $ map fst $ rulesCompilers ruleSet
|
|
|
|
routes = rulesRoutes ruleSet
|
|
|
|
|
|
|
|
-- Test that we have some identifiers and that the routes work out
|
|
|
|
assert $ all (`S.member` identifiers) expected
|
|
|
|
Just "example.html" @=? runRoutes routes "example.md"
|
2012-11-30 09:40:46 +00:00
|
|
|
Just "example.md" @=? runRoutes routes (sv "raw" "example.md")
|
|
|
|
Just "example.md" @=? runRoutes routes (sv "nav" "example.md")
|
2011-05-24 20:29:47 +00:00
|
|
|
where
|
2012-11-30 09:40:46 +00:00
|
|
|
sv g = setVersion (Just g)
|
2012-11-26 15:11:37 +00:00
|
|
|
expected =
|
|
|
|
[ "example.md"
|
|
|
|
, "russian.md"
|
2012-11-30 09:40:46 +00:00
|
|
|
, sv "raw" "example.md"
|
|
|
|
, sv "raw" "russian.md"
|
|
|
|
, sv "nav" "example.md"
|
2011-05-24 20:29:47 +00:00
|
|
|
]
|
|
|
|
|
2011-05-24 12:40:45 +00:00
|
|
|
|
2012-11-26 15:11:37 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
rules :: Rules ()
|
2011-05-24 12:40:45 +00:00
|
|
|
rules = do
|
|
|
|
-- Compile some posts
|
2012-11-26 15:11:37 +00:00
|
|
|
match "*.md" $ do
|
2011-05-24 12:40:45 +00:00
|
|
|
route $ setExtension "html"
|
|
|
|
compile pageCompiler
|
|
|
|
|
|
|
|
-- Compile them, raw
|
2012-11-26 15:11:37 +00:00
|
|
|
match "*.md" $ version "raw" $ do
|
2011-05-24 20:29:47 +00:00
|
|
|
route idRoute
|
2012-11-26 15:11:37 +00:00
|
|
|
compile getResourceString
|
2012-11-29 22:09:11 +00:00
|
|
|
|
|
|
|
-- Regression test
|
|
|
|
version "nav" $ match (fromList ["example.md"]) $ do
|
|
|
|
route idRoute
|
|
|
|
compile copyFileCompiler
|