summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Kreshchuk <akrsch@gmail.com>2013-10-18 01:23:14 +0400
committerAlexey Kreshchuk <akrsch@gmail.com>2013-10-18 01:23:14 +0400
commit46b6f78da8ed814bef6972f4712d8b13e76c1122 (patch)
treee8f0c803a4ea2e8af17289b36bf97177d531ba7f
parent712ffa39b5857fdc5cdae1db38a177267a430b11 (diff)
downloadhakyll-46b6f78da8ed814bef6972f4712d8b13e76c1122.tar.gz
Added test case for global metadata
-rw-r--r--src/Hakyll/Core/Provider/Metadata.hs2
-rw-r--r--tests/Hakyll/Core/Provider/GlobalMetadata/Tests.hs31
-rw-r--r--tests/TestSuite.hs2
-rw-r--r--tests/data/metadata27
-rw-r--r--tests/data/posts/2013-10-18-metadata-test.md4
-rw-r--r--tests/data/posts/2013-10-18-metadata-test.md.metadata2
-rw-r--r--tests/data/posts/metadata18
7 files changed, 85 insertions, 1 deletions
diff --git a/src/Hakyll/Core/Provider/Metadata.hs b/src/Hakyll/Core/Provider/Metadata.hs
index 4331861..a54b84a 100644
--- a/src/Hakyll/Core/Provider/Metadata.hs
+++ b/src/Hakyll/Core/Provider/Metadata.hs
@@ -151,7 +151,7 @@ loadGlobalMetadata p fp = liftM M.fromList $ loadgm fp where
-- TODO: It might be better to print warning and continue
in either (error.show) (findMetadata dir) . P.parse namedMetadata path <$> readFile path
findMetadata dir =
- concatMap snd . filter (flip matches fp . fromGlob . combine dir . fst)
+ concatMap snd . filter (flip matches fp . fromGlob . normalise . combine dir . fst)
namedMetadata :: Parser [(String, [(String, String)])]
namedMetadata = P.many namedMetadataBlock
diff --git a/tests/Hakyll/Core/Provider/GlobalMetadata/Tests.hs b/tests/Hakyll/Core/Provider/GlobalMetadata/Tests.hs
new file mode 100644
index 0000000..289e2ac
--- /dev/null
+++ b/tests/Hakyll/Core/Provider/GlobalMetadata/Tests.hs
@@ -0,0 +1,31 @@
+--------------------------------------------------------------------------------
+{-# LANGUAGE OverloadedStrings #-}
+module Hakyll.Core.Provider.GlobalMetadata.Tests
+ ( tests
+ ) where
+
+--------------------------------------------------------------------------------
+import qualified Data.Map as M
+import Control.Monad (forM_)
+import Test.Framework (Test, testGroup)
+import Test.HUnit (Assertion, (@=?))
+
+
+--------------------------------------------------------------------------------
+import Hakyll.Core.Provider (resourceMetadata)
+import TestSuite.Util
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Core.Provider.GlobalMetadata.Tests" $
+ fromAssertions "page" [testPage]
+
+testPage :: Assertion
+testPage = do
+ store <- newTestStore
+ provider <- newTestProvider store
+
+ metadata <- resourceMetadata provider "posts/2013-10-18-metadata-test.md"
+ forM_ ["1", "2", "3", "4", "5", "6", "7", "8"] $ \a ->
+ Just a @=? M.lookup ('a':a) metadata
+
diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs
index 3622301..9cc446e 100644
--- a/tests/TestSuite.hs
+++ b/tests/TestSuite.hs
@@ -12,6 +12,7 @@ import Test.Framework (defaultMain)
import qualified Hakyll.Core.Dependencies.Tests
import qualified Hakyll.Core.Identifier.Tests
import qualified Hakyll.Core.Provider.Metadata.Tests
+import qualified Hakyll.Core.Provider.GlobalMetadata.Tests
import qualified Hakyll.Core.Provider.Tests
import qualified Hakyll.Core.Routes.Tests
import qualified Hakyll.Core.Rules.Tests
@@ -32,6 +33,7 @@ main = defaultMain
[ Hakyll.Core.Dependencies.Tests.tests
, Hakyll.Core.Identifier.Tests.tests
, Hakyll.Core.Provider.Metadata.Tests.tests
+ , Hakyll.Core.Provider.GlobalMetadata.Tests.tests
, Hakyll.Core.Provider.Tests.tests
, Hakyll.Core.Routes.Tests.tests
, Hakyll.Core.Rules.Tests.tests
diff --git a/tests/data/metadata b/tests/data/metadata
new file mode 100644
index 0000000..1145976
--- /dev/null
+++ b/tests/data/metadata
@@ -0,0 +1,27 @@
+--- posts/2013-10-18-metadata-test.md
+a1: 8
+a2: 8
+a3: 8
+a4: 8
+a5: 8
+a6: 8
+a7: 8
+a8: 8
+
+--- posts/*
+a1: 7
+a2: 7
+a3: 7
+a4: 7
+a5: 7
+a6: 7
+a7: 7
+
+--- **
+a1: 6
+a2: 6
+a3: 6
+a4: 6
+a5: 6
+a6: 6
+
diff --git a/tests/data/posts/2013-10-18-metadata-test.md b/tests/data/posts/2013-10-18-metadata-test.md
new file mode 100644
index 0000000..86a3e67
--- /dev/null
+++ b/tests/data/posts/2013-10-18-metadata-test.md
@@ -0,0 +1,4 @@
+---
+a1: 1
+---
+Nothing interesting here.
diff --git a/tests/data/posts/2013-10-18-metadata-test.md.metadata b/tests/data/posts/2013-10-18-metadata-test.md.metadata
new file mode 100644
index 0000000..7ee78b6
--- /dev/null
+++ b/tests/data/posts/2013-10-18-metadata-test.md.metadata
@@ -0,0 +1,2 @@
+a1: 2
+a2: 2
diff --git a/tests/data/posts/metadata b/tests/data/posts/metadata
new file mode 100644
index 0000000..e5cd153
--- /dev/null
+++ b/tests/data/posts/metadata
@@ -0,0 +1,18 @@
+--- **
+a1: 5
+a2: 5
+a3: 5
+a4: 5
+a5: 5
+
+--- *
+a1: 4
+a2: 4
+a3: 4
+a4: 4
+
+--- 2013-10-18-metadata-test.md
+a1: 3
+a2: 3
+a3: 3
+