summaryrefslogtreecommitdiff
path: root/tests/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-26 16:11:37 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-26 16:11:37 +0100
commit1bcce776e786eb6688bace653ecafa1a5a4fb563 (patch)
treefc889c8e4af23c32dec6637d5c4e2de1fe383830 /tests/Hakyll
parent25b8c8b199082ebbc41d1af03fc19202b798f156 (diff)
downloadhakyll-1bcce776e786eb6688bace653ecafa1a5a4fb563.tar.gz
Re-add some tests, cleanup...
Diffstat (limited to 'tests/Hakyll')
-rw-r--r--tests/Hakyll/Core/Routes/Tests.hs21
-rw-r--r--tests/Hakyll/Core/Rules/Tests.hs86
-rw-r--r--tests/Hakyll/Core/Util/String/Tests.hs19
-rw-r--r--tests/Hakyll/Web/Util/Html/Tests.hs19
4 files changed, 82 insertions, 63 deletions
diff --git a/tests/Hakyll/Core/Routes/Tests.hs b/tests/Hakyll/Core/Routes/Tests.hs
index d204b16..8bdbe85 100644
--- a/tests/Hakyll/Core/Routes/Tests.hs
+++ b/tests/Hakyll/Core/Routes/Tests.hs
@@ -1,17 +1,24 @@
+--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Routes.Tests
( tests
) where
-import Test.Framework
-import Test.HUnit hiding (Test)
-import Hakyll.Core.Identifier
-import Hakyll.Core.Routes
-import TestSuite.Util
+--------------------------------------------------------------------------------
+import Test.Framework (Test, testGroup)
+import Test.HUnit ((@=?))
-tests :: [Test]
-tests = fromAssertions "runRoutes"
+
+--------------------------------------------------------------------------------
+import Hakyll.Core.Identifier
+import Hakyll.Core.Routes
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
[ Just "foo.html" @=? runRoutes (setExtension "html") "foo"
, Just "foo.html" @=? runRoutes (setExtension ".html") "foo"
, Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
diff --git a/tests/Hakyll/Core/Rules/Tests.hs b/tests/Hakyll/Core/Rules/Tests.hs
index ac2126c..4f0b40e 100644
--- a/tests/Hakyll/Core/Rules/Tests.hs
+++ b/tests/Hakyll/Core/Rules/Tests.hs
@@ -1,67 +1,65 @@
+--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
module Hakyll.Core.Rules.Tests
( tests
) where
-import qualified Data.Map as M
-import qualified Data.Set as S
-import Test.Framework
-import Test.Framework.Providers.HUnit
-import Test.HUnit hiding (Test)
+--------------------------------------------------------------------------------
+import qualified Data.Set as S
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.HUnit (testCase)
+import Test.HUnit (Assertion, assert, (@=?))
-import Hakyll.Core.Rules
-import Hakyll.Core.Rules.Internal
-import Hakyll.Core.Identifier
-import Hakyll.Core.Routes
-import Hakyll.Core.Compiler
-import Hakyll.Core.Resource.Provider
-import Hakyll.Core.Resource.Provider.Dummy
-import Hakyll.Web.Page
-tests :: [Test]
-tests =
+--------------------------------------------------------------------------------
+import Hakyll.Core.Compiler
+import Hakyll.Core.Identifier
+import Hakyll.Core.Routes
+import Hakyll.Core.Rules
+import Hakyll.Core.Rules.Internal
+import Hakyll.Web.Page
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Core.Rules.Tests"
[ testCase "runRules" rulesTest
]
--- | Main test
---
+
+--------------------------------------------------------------------------------
rulesTest :: Assertion
-rulesTest = do
- p <- provider
- let ruleSet = runRules rules p
- assert $ expected == S.fromList (map fst (rulesCompilers ruleSet))
+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"
+ Just "example.md" @=? runRoutes routes (raw "example.md")
where
- expected = S.fromList
- [ Identifier Nothing "posts/a-post.markdown"
- , Identifier Nothing "posts/some-other-post.markdown"
- , Identifier (Just "raw") "posts/a-post.markdown"
- , Identifier (Just "raw") "posts/some-other-post.markdown"
+ raw = setVersion (Just "raw")
+ expected =
+ [ "example.md"
+ , "russian.md"
+ , raw "example.md"
+ , raw "russian.md"
]
--- | Dummy resource provider
---
-provider :: IO ResourceProvider
-provider = dummyResourceProvider $ M.fromList $ map (flip (,) "No content")
- [ "posts/a-post.markdown"
- , "posts/some-other-post.markdown"
- ]
--- | Example rules
---
-rules :: Rules
+--------------------------------------------------------------------------------
+rules :: Rules ()
rules = do
-- Compile some posts
- match "posts/*" $ do
+ match "*.md" $ do
route $ setExtension "html"
compile pageCompiler
-- Compile them, raw
- group "raw" $ do
+ match "*.md" $ version "raw" $ do
route idRoute
- match "posts/*" $ do
- route $ setExtension "html"
- compile getResourceString
-
- return ()
+ compile getResourceString
diff --git a/tests/Hakyll/Core/Util/String/Tests.hs b/tests/Hakyll/Core/Util/String/Tests.hs
index bbdfb96..d5dcdb7 100644
--- a/tests/Hakyll/Core/Util/String/Tests.hs
+++ b/tests/Hakyll/Core/Util/String/Tests.hs
@@ -1,15 +1,22 @@
+--------------------------------------------------------------------------------
module Hakyll.Core.Util.String.Tests
( tests
) where
-import Test.Framework (Test)
-import Test.HUnit ((@=?))
-import Hakyll.Core.Util.String
-import TestSuite.Util
+--------------------------------------------------------------------------------
+import Test.Framework (Test, testGroup)
+import Test.HUnit ((@=?))
-tests :: [Test]
-tests = concat
+
+--------------------------------------------------------------------------------
+import Hakyll.Core.Util.String
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Core.Util.String.Tests" $ concat
[ fromAssertions "trim"
[ "foo" @=? trim " foo\n\t "
]
diff --git a/tests/Hakyll/Web/Util/Html/Tests.hs b/tests/Hakyll/Web/Util/Html/Tests.hs
index e73c88b..3a99ca7 100644
--- a/tests/Hakyll/Web/Util/Html/Tests.hs
+++ b/tests/Hakyll/Web/Util/Html/Tests.hs
@@ -1,15 +1,22 @@
+--------------------------------------------------------------------------------
module Hakyll.Web.Util.Html.Tests
( tests
) where
-import Test.Framework
-import Test.HUnit hiding (Test)
-import Hakyll.Web.Util.Html
-import TestSuite.Util
+--------------------------------------------------------------------------------
+import Test.Framework (Test, testGroup)
+import Test.HUnit ((@=?))
-tests :: [Test]
-tests = concat
+
+--------------------------------------------------------------------------------
+import Hakyll.Web.Util.Html
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Web.Util.Html" $ concat
[ fromAssertions "stripTags"
[ "foo" @=? stripTags "<p>foo</p>"
, "foo bar" @=? stripTags "<p>foo</p> bar"