hakyll/tests/Hakyll/Core/Provider/Metadata/Tests.hs

63 lines
2.1 KiB
Haskell
Raw Normal View History

2013-02-26 18:20:55 +00:00
--------------------------------------------------------------------------------
module Hakyll.Core.Provider.Metadata.Tests
( tests
) where
--------------------------------------------------------------------------------
2016-04-06 12:26:46 +00:00
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
2013-02-26 18:20:55 +00:00
import Test.Framework (Test, testGroup)
2016-04-21 19:16:52 +00:00
import Test.HUnit (Assertion, (@=?), assertFailure)
2013-02-26 18:20:55 +00:00
import TestSuite.Util
--------------------------------------------------------------------------------
tests :: Test
tests = testGroup "Hakyll.Core.Provider.Metadata.Tests" $
fromAssertions "page" [testPage01, testPage02]
2016-04-06 12:26:46 +00:00
2013-02-26 18:20:55 +00:00
--------------------------------------------------------------------------------
testPage01 :: Assertion
2016-04-06 12:26:46 +00:00
testPage01 =
2016-04-21 19:16:52 +00:00
(meta [("foo", "bar")], "qux\n") `expectRight` parsePage
2013-02-26 18:20:55 +00:00
"---\n\
\foo: bar\n\
\---\n\
\qux\n"
--------------------------------------------------------------------------------
testPage02 :: Assertion
2016-04-06 12:26:46 +00:00
testPage02 =
2016-04-21 19:16:52 +00:00
(meta [("description", descr)], "Hello I am dog\n") `expectRight`
2016-04-06 12:26:46 +00:00
parsePage
2013-02-26 18:20:55 +00:00
"---\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
2016-04-06 12:26:46 +00:00
descr :: String
2013-02-26 18:20:55 +00:00
descr =
"A long description that would look better if it \
\spanned multiple lines and was indented"
--------------------------------------------------------------------------------
2016-04-06 12:26:46 +00:00
meta :: Yaml.ToJSON a => [(String, a)] -> Metadata
meta pairs = HMS.fromList [(T.pack k, Yaml.toJSON v) | (k, v) <- pairs]
2016-04-21 19:16:52 +00:00
--------------------------------------------------------------------------------
-- | This is useful when the 'Left' side of 'Either' doesn't have an 'Eq'
-- instance.
expectRight :: (Eq b, Show a, Show b) => b -> Either a b -> Assertion
expectRight _ (Left err) = assertFailure (show err)
expectRight expected (Right res) = expected @=? res