summaryrefslogtreecommitdiff
path: root/tests/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2016-04-06 14:26:46 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2016-04-06 14:26:46 +0200
commite81468e0f64fdbe05794d5f8ccaebc00ee474ee2 (patch)
tree882c422a312ed3e6eb8eaacfcc9c292a09296845 /tests/Hakyll
parent3f3e09672d3d279bc5cbaa8b3ac7508abc98aa2d (diff)
downloadhakyll-e81468e0f64fdbe05794d5f8ccaebc00ee474ee2.tar.gz
Initial YAML support
See #225
Diffstat (limited to 'tests/Hakyll')
-rw-r--r--tests/Hakyll/Core/Provider/Metadata/Tests.hs27
-rw-r--r--tests/Hakyll/Core/Provider/Tests.hs13
-rw-r--r--tests/Hakyll/Core/Routes/Tests.hs12
-rw-r--r--tests/Hakyll/Core/Rules/Tests.hs13
4 files changed, 29 insertions, 36 deletions
diff --git a/tests/Hakyll/Core/Provider/Metadata/Tests.hs b/tests/Hakyll/Core/Provider/Metadata/Tests.hs
index 1217180..fc609f2 100644
--- a/tests/Hakyll/Core/Provider/Metadata/Tests.hs
+++ b/tests/Hakyll/Core/Provider/Metadata/Tests.hs
@@ -5,14 +5,13 @@ module Hakyll.Core.Provider.Metadata.Tests
--------------------------------------------------------------------------------
+import qualified Data.HashMap.Strict as HMS
+import qualified Data.Text as T
+import qualified Data.Yaml as Yaml
+import Hakyll.Core.Metadata
+import Hakyll.Core.Provider.Metadata
import Test.Framework (Test, testGroup)
import Test.HUnit (Assertion, (@=?))
-import Text.Parsec as P
-import Text.Parsec.String (Parser)
-
-
---------------------------------------------------------------------------------
-import Hakyll.Core.Provider.Metadata
import TestSuite.Util
@@ -22,9 +21,11 @@ tests = testGroup "Hakyll.Core.Provider.Metadata.Tests" $
fromAssertions "page" [testPage01, testPage02]
+
--------------------------------------------------------------------------------
testPage01 :: Assertion
-testPage01 = testParse page ([("foo", "bar")], "qux\n")
+testPage01 =
+ Right (meta [("foo", "bar")], "qux\n") @=? parsePage
"---\n\
\foo: bar\n\
\---\n\
@@ -33,21 +34,21 @@ testPage01 = testParse page ([("foo", "bar")], "qux\n")
--------------------------------------------------------------------------------
testPage02 :: Assertion
-testPage02 = testParse page
- ([("description", descr)], "Hello I am dog\n")
+testPage02 =
+ Right (meta [("description", descr)], "Hello I am dog\n") @=?
+ parsePage
"---\n\
\description: A long description that would look better if it\n\
\ spanned multiple lines and was indented\n\
\---\n\
\Hello I am dog\n"
where
+ descr :: String
descr =
"A long description that would look better if it \
\spanned multiple lines and was indented"
--------------------------------------------------------------------------------
-testParse :: (Eq a, Show a) => Parser a -> a -> String -> Assertion
-testParse parser expected input = case P.parse parser "<inline>" input of
- Left err -> error $ show err
- Right x -> expected @=? x
+meta :: Yaml.ToJSON a => [(String, a)] -> Metadata
+meta pairs = HMS.fromList [(T.pack k, Yaml.toJSON v) | (k, v) <- pairs]
diff --git a/tests/Hakyll/Core/Provider/Tests.hs b/tests/Hakyll/Core/Provider/Tests.hs
index abe5c1d..8a505d2 100644
--- a/tests/Hakyll/Core/Provider/Tests.hs
+++ b/tests/Hakyll/Core/Provider/Tests.hs
@@ -6,14 +6,11 @@ module Hakyll.Core.Provider.Tests
--------------------------------------------------------------------------------
-import qualified Data.Map as M
+import Hakyll.Core.Metadata
+import Hakyll.Core.Provider
import Test.Framework (Test, testGroup)
import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit (Assertion, assert, (@=?))
-
-
---------------------------------------------------------------------------------
-import Hakyll.Core.Provider
import TestSuite.Util
@@ -32,9 +29,9 @@ case01 = do
assert $ resourceExists provider "example.md"
metadata <- resourceMetadata provider "example.md"
- Just "An example" @=? M.lookup "title" metadata
- Just "External data" @=? M.lookup "external" metadata
+ Just "An example" @=? lookupString "title" metadata
+ Just "External data" @=? lookupString "external" metadata
doesntExist <- resourceMetadata provider "doesntexist.md"
- M.empty @=? doesntExist
+ mempty @=? doesntExist
cleanTestEnv
diff --git a/tests/Hakyll/Core/Routes/Tests.hs b/tests/Hakyll/Core/Routes/Tests.hs
index 4f975ae..5a833b0 100644
--- a/tests/Hakyll/Core/Routes/Tests.hs
+++ b/tests/Hakyll/Core/Routes/Tests.hs
@@ -6,15 +6,13 @@ module Hakyll.Core.Routes.Tests
--------------------------------------------------------------------------------
-import qualified Data.Map as M
+import Data.Maybe (fromMaybe)
+import Hakyll.Core.Identifier
+import Hakyll.Core.Metadata
+import Hakyll.Core.Routes
import System.FilePath ((</>))
import Test.Framework (Test, testGroup)
import Test.HUnit (Assertion, (@=?))
-
-
---------------------------------------------------------------------------------
-import Hakyll.Core.Identifier
-import Hakyll.Core.Routes
import TestSuite.Util
@@ -37,7 +35,7 @@ tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
"tags/rss/bar"
, testRoutes "food/example.md" (metadataRoute $ \md -> customRoute $ \id' ->
- M.findWithDefault "?" "subblog" md </> toFilePath id')
+ fromMaybe "?" (lookupString "subblog" md) </> toFilePath id')
"example.md"
]
diff --git a/tests/Hakyll/Core/Rules/Tests.hs b/tests/Hakyll/Core/Rules/Tests.hs
index dbd077d..ec81c1c 100644
--- a/tests/Hakyll/Core/Rules/Tests.hs
+++ b/tests/Hakyll/Core/Rules/Tests.hs
@@ -8,22 +8,19 @@ module Hakyll.Core.Rules.Tests
--------------------------------------------------------------------------------
import Data.IORef (IORef, newIORef, readIORef,
writeIORef)
-import qualified Data.Map as M
import qualified Data.Set as S
-import System.FilePath ((</>))
-import Test.Framework (Test, testGroup)
-import Test.HUnit (Assertion, assert, (@=?))
-
-
---------------------------------------------------------------------------------
import Hakyll.Core.Compiler
import Hakyll.Core.File
import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
+import Hakyll.Core.Metadata
import Hakyll.Core.Routes
import Hakyll.Core.Rules
import Hakyll.Core.Rules.Internal
import Hakyll.Web.Pandoc
+import System.FilePath ((</>))
+import Test.Framework (Test, testGroup)
+import Test.HUnit (Assertion, assert, (@=?))
import TestSuite.Util
@@ -89,7 +86,7 @@ rules01 ioref = do
compile getResourceString
version "metadataMatch" $
- matchMetadata "*.md" (\md -> M.lookup "subblog" md == Just "food") $ do
+ matchMetadata "*.md" (\md -> lookupString "subblog" md == Just "food") $ do
route $ customRoute $ \id' -> "food" </> toFilePath id'
compile getResourceString