summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hakyll.cabal1
-rw-r--r--src/Hakyll/Web/Template/Read.hs7
-rw-r--r--tests/Hakyll/Web/Page/Metadata/Tests.hs77
-rw-r--r--tests/Hakyll/Web/Page/Tests.hs40
-rw-r--r--tests/Hakyll/Web/Template/Context/Tests.hs51
-rw-r--r--tests/TestSuite.hs4
-rw-r--r--tests/data/example.md.metadata1
-rw-r--r--tests/data/posts/2010-08-26-birthday.md1
-rw-r--r--tests/data/template.html2
-rw-r--r--tests/data/template.html.out2
10 files changed, 62 insertions, 124 deletions
diff --git a/hakyll.cabal b/hakyll.cabal
index c72b284..c68cfca 100644
--- a/hakyll.cabal
+++ b/hakyll.cabal
@@ -208,6 +208,7 @@ Test-suite hakyll-tests
Hakyll.Core.Store.Tests
Hakyll.Core.UnixFilter.Tests
Hakyll.Core.Util.String.Tests
+ Hakyll.Web.Template.Context.Tests
Hakyll.Web.Template.Tests
Hakyll.Web.Urls.Tests
Hakyll.Web.Urls.Relativize.Tests
diff --git a/src/Hakyll/Web/Template/Read.hs b/src/Hakyll/Web/Template/Read.hs
index f8583ff..7dfe003 100644
--- a/src/Hakyll/Web/Template/Read.hs
+++ b/src/Hakyll/Web/Template/Read.hs
@@ -6,12 +6,11 @@ module Hakyll.Web.Template.Read
--------------------------------------------------------------------------------
-import Data.List (isPrefixOf)
-import Data.Char (isAlphaNum)
+import Data.List (isPrefixOf)
--------------------------------------------------------------------------------
-import Hakyll.Web.Template.Internal
+import Hakyll.Web.Template.Internal
--------------------------------------------------------------------------------
@@ -39,4 +38,4 @@ readTemplate = Template . readTemplate'
then Just (key, drop 1 rest)
else Nothing
- validKeyChar x = isAlphaNum x || x == ' '
+ validKeyChar x = x `notElem` ['$', '\n', '\r']
diff --git a/tests/Hakyll/Web/Page/Metadata/Tests.hs b/tests/Hakyll/Web/Page/Metadata/Tests.hs
deleted file mode 100644
index badb9fb..0000000
--- a/tests/Hakyll/Web/Page/Metadata/Tests.hs
+++ /dev/null
@@ -1,77 +0,0 @@
-module Hakyll.Web.Page.Metadata.Tests
- ( tests
- ) where
-
-import Test.Framework
-import Test.HUnit hiding (Test)
-
-import qualified Data.Map as M
-import Data.Monoid (mempty)
-import Data.Char (toLower)
-
-import Hakyll.Web.Page
-import Hakyll.Web.Page.Metadata
-import TestSuite.Util
-
-tests :: [Test]
-tests = concat $
- [ fromAssertions "getField"
- [ "bar" @=? getField "foo" (Page (M.singleton "foo" "bar") "body\n")
- , "" @=? getField "foo" (Page M.empty "body")
- ]
-
- , fromAssertions "getFieldMaybe"
- [ Just "bar" @=? getFieldMaybe "foo" (Page (M.singleton "foo" "bar") "")
- , Nothing @=? getFieldMaybe "foo" (Page M.empty "body")
- ]
-
- , fromAssertions "setField"
- [ (Page (M.singleton "bar" "foo") "") @=? setField "bar" "foo" mempty
- , (Page (M.singleton "bar" "foo") "") @=?
- setField "bar" "foo" (Page (M.singleton "bar" "qux") "")
- ]
-
- , fromAssertions "trySetField"
- [ (Page (M.singleton "bar" "foo") "") @=? trySetField "bar" "foo" mempty
- , (Page (M.singleton "bar" "qux") "") @=?
- trySetField "bar" "foo" (Page (M.singleton "bar" "qux") "")
- ]
-
- , fromAssertions "setFieldA"
- [ (Page (M.singleton "bar" "foo") "") @=?
- setFieldA "bar" (map toLower) (mempty, "FOO")
- ]
-
- , fromAssertions "renderDateField"
- [ (@=?) "January 31, 2010" $ getField "date" $ renderDateField
- "date" "%B %e, %Y" "Date unknown" $ Page
- (M.singleton "path" "/posts/2010-01-31-a-post.mkdwn") ""
- , (@=?) "Date unknown" $ getField "date" $ renderDateField
- "date" "%B %e, %Y" "Date unknown" $ Page
- (M.singleton "path" "/posts/a-post.mkdwn") ""
- , (@=?) "February 20, 2000" $ getField "date" $ renderDateField
- "date" "%B %e, %Y" "Date unknown" $ flip Page "" $ M.fromList
- [ ("path", "/posts/2010-01-31-a-post.mkdwn")
- , ("published", "February 20, 2000 1:00 PM")
- ]
- , (@=?) "October 22, 2012" $ getField "date" $ renderDateField
- "date" "%B %e, %Y" "Date unknown" $ Page
- (M.singleton "date" "2012-10-22 14:35:24") ""
- ]
-
- , fromAssertions "copyBodyToField"
- [ (Page (M.singleton "bar" "foo") "foo") @=?
- copyBodyToField "bar" (Page M.empty "foo")
- ]
-
- , fromAssertions "copyBodyFromField"
- [ (Page (M.singleton "bar" "foo") "foo") @=?
- copyBodyFromField "bar" (Page (M.singleton "bar" "foo") "qux")
- ]
-
- , fromAssertions "comparePagesByDate"
- [ GT @=? comparePagesByDate
- (Page (M.singleton "path" "/posts/1990-08-26-foo.mkdwn") "")
- (Page (M.singleton "path" "/posts/1990-06-18-qux.mkdwn") "")
- ]
- ]
diff --git a/tests/Hakyll/Web/Page/Tests.hs b/tests/Hakyll/Web/Page/Tests.hs
deleted file mode 100644
index 8e01302..0000000
--- a/tests/Hakyll/Web/Page/Tests.hs
+++ /dev/null
@@ -1,40 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-module Hakyll.Web.Page.Tests
- ( tests
- ) where
-
-import Test.Framework
-import Test.HUnit hiding (Test)
-
-import qualified Data.Map as M
-
-import Hakyll.Web.Page
-import Hakyll.Web.Page.Read
-import TestSuite.Util
-
-tests :: [Test]
-tests = fromAssertions "readPage"
- [ Page (M.singleton "foo" "bar") "body" @=? readPage
- "--- \n\
- \foo: bar \n\
- \--- \n\
- \body"
-
- , Page M.empty "line one\nlijn twee" @=? readPage
- "line one\n\
- \lijn twee"
-
- , Page (M.fromList [("field1", "unos"), ("veld02", "deux")]) "" @=? readPage
- "---\n\
- \veld02: deux\n\
- \field1: unos\n\
- \---\n"
-
- , Page (M.fromList [("author", "jasper"), ("title", "lol")]) "O hai\n"
- @=? readPage
- "---\n\
- \author: jasper\n\
- \title: lol\n\
- \...\n\
- \O hai\n"
- ]
diff --git a/tests/Hakyll/Web/Template/Context/Tests.hs b/tests/Hakyll/Web/Template/Context/Tests.hs
new file mode 100644
index 0000000..f2fb42a
--- /dev/null
+++ b/tests/Hakyll/Web/Template/Context/Tests.hs
@@ -0,0 +1,51 @@
+--------------------------------------------------------------------------------
+{-# LANGUAGE OverloadedStrings #-}
+module Hakyll.Web.Template.Context.Tests
+ ( tests
+ ) where
+
+
+--------------------------------------------------------------------------------
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.HUnit (testCase)
+import Test.HUnit (Assertion, (@=?))
+
+
+--------------------------------------------------------------------------------
+import Hakyll.Core.Compiler
+import Hakyll.Core.Identifier
+import Hakyll.Core.Provider
+import Hakyll.Core.Store (Store)
+import Hakyll.Web.Template.Context
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Core.Template.Context.Tests"
+ [ testCase "testDateField" testDateField
+ ]
+
+
+--------------------------------------------------------------------------------
+testDateField :: Assertion
+testDateField = withTestStore $ \store -> do
+ provider <- newTestProvider store
+
+ date1 <- testContextDone store provider "example.md" "date" $
+ dateField "date" "%B %e, %Y"
+ date1 @=? "October 22, 2012"
+
+ date2 <- testContextDone store provider
+ "posts/2010-08-26-birthday.md" "date" $
+ dateField "date" "%B %e, %Y"
+ date2 @=? "August 26, 2010"
+
+
+--------------------------------------------------------------------------------
+testContextDone :: Store -> Provider -> Identifier -> String
+ -> Context String -> IO String
+testContextDone store provider identifier key context =
+ testCompilerDone store provider identifier $ do
+ item <- getResourceBody
+ unContext context key item
diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs
index ef9d6d1..15eea6d 100644
--- a/tests/TestSuite.hs
+++ b/tests/TestSuite.hs
@@ -5,7 +5,7 @@ module Main
--------------------------------------------------------------------------------
-import Test.Framework (defaultMain)
+import Test.Framework (defaultMain)
--------------------------------------------------------------------------------
@@ -18,6 +18,7 @@ import qualified Hakyll.Core.Runtime.Tests
import qualified Hakyll.Core.Store.Tests
import qualified Hakyll.Core.UnixFilter.Tests
import qualified Hakyll.Core.Util.String.Tests
+import qualified Hakyll.Web.Template.Context.Tests
import qualified Hakyll.Web.Template.Tests
import qualified Hakyll.Web.Urls.Relativize.Tests
import qualified Hakyll.Web.Urls.Tests
@@ -36,6 +37,7 @@ main = defaultMain
, Hakyll.Core.Store.Tests.tests
, Hakyll.Core.UnixFilter.Tests.tests
, Hakyll.Core.Util.String.Tests.tests
+ , Hakyll.Web.Template.Context.Tests.tests
, Hakyll.Web.Template.Tests.tests
, Hakyll.Web.Urls.Relativize.Tests.tests
, Hakyll.Web.Urls.Tests.tests
diff --git a/tests/data/example.md.metadata b/tests/data/example.md.metadata
index b757d9b..9685918 100644
--- a/tests/data/example.md.metadata
+++ b/tests/data/example.md.metadata
@@ -1 +1,2 @@
external: External data
+date: 2012-10-22 14:35:24
diff --git a/tests/data/posts/2010-08-26-birthday.md b/tests/data/posts/2010-08-26-birthday.md
new file mode 100644
index 0000000..b88ede5
--- /dev/null
+++ b/tests/data/posts/2010-08-26-birthday.md
@@ -0,0 +1 @@
+It's my birthday today.
diff --git a/tests/data/template.html b/tests/data/template.html
index a8d78eb..153303c 100644
--- a/tests/data/template.html
+++ b/tests/data/template.html
@@ -1,5 +1,5 @@
<div>
I'm so rich I have $$3.
- $echo test$
+ $echo test!$
$body$
</div>
diff --git a/tests/data/template.html.out b/tests/data/template.html.out
index 8bd1879..07b0851 100644
--- a/tests/data/template.html.out
+++ b/tests/data/template.html.out
@@ -1,5 +1,5 @@
<div>
I'm so rich I have $3.
- test
+ test!
<p>This is an example.</p>
</div>