on master help sign in
Allow arbitrary keys, update some tests
commitdb45ea9d8cb8fd199de2239b6bc28aff3ad53cce authorJasper Van der Jeugt <m@jaspervdj.be> dateTue 27 Nov 2012, 16:10 (14 years ago) parent1bcce77
10 files changed+62−124
hakyll.cabal+1 src/Hakyll/Web/Template/Read.hs+3−4 tests/Hakyll/Web/Page/Metadata/Tests.hs−77 tests/Hakyll/Web/Page/Tests.hs−40 tests/Hakyll/Web/Template/Context/Tests.hs+51 tests/TestSuite.hs+3−1 tests/data/example.md.metadata+1 tests/data/posts/2010-08-26-birthday.md+1 tests/data/template.html+1−1 tests/data/template.html.out+1−1
hakyll.cabal+1
@@ -208,6 +208,7 @@ Test-suite hakyll-tests
208208 Hakyll.Core.Store.Tests
209209 Hakyll.Core.UnixFilter.Tests
210210 Hakyll.Core.Util.String.Tests
211+ Hakyll.Web.Template.Context.Tests
211212 Hakyll.Web.Template.Tests
212213 Hakyll.Web.Urls.Tests
213214 Hakyll.Web.Urls.Relativize.Tests
src/Hakyll/Web/Template/Read.hs+3−4
@@ -6,12 +6,11 @@ module Hakyll.Web.Template.Read
66
77
88--------------------------------------------------------------------------------
9−import Data.List (isPrefixOf)
10−import Data.Char (isAlphaNum)
9+import Data.List (isPrefixOf)
1110
1211
1312--------------------------------------------------------------------------------
14−import Hakyll.Web.Template.Internal
13+import Hakyll.Web.Template.Internal
1514
1615
1716--------------------------------------------------------------------------------
@@ -39,4 +38,4 @@ readTemplate = Template . readTemplate'
3938 then Just (key, drop 1 rest)
4039 else Nothing
4140
42− validKeyChar x = isAlphaNum x || x == ' '
41+ validKeyChar x = x `notElem` ['$', '\n', '\r']
tests/Hakyll/Web/Page/Metadata/Tests.hsdeleted−77
@@ -1,77 +0,0 @@
1−module Hakyll.Web.Page.Metadata.Tests
2− ( tests
3− ) where
4−
5−import Test.Framework
6−import Test.HUnit hiding (Test)
7−
8−import qualified Data.Map as M
9−import Data.Monoid (mempty)
10−import Data.Char (toLower)
11−
12−import Hakyll.Web.Page
13−import Hakyll.Web.Page.Metadata
14−import TestSuite.Util
15−
16−tests :: [Test]
17−tests = concat $
18− [ fromAssertions "getField"
19− [ "bar" @=? getField "foo" (Page (M.singleton "foo" "bar") "body\n")
20− , "" @=? getField "foo" (Page M.empty "body")
21− ]
22−
23− , fromAssertions "getFieldMaybe"
24− [ Just "bar" @=? getFieldMaybe "foo" (Page (M.singleton "foo" "bar") "")
25− , Nothing @=? getFieldMaybe "foo" (Page M.empty "body")
26− ]
27−
28− , fromAssertions "setField"
29− [ (Page (M.singleton "bar" "foo") "") @=? setField "bar" "foo" mempty
30− , (Page (M.singleton "bar" "foo") "") @=?
31− setField "bar" "foo" (Page (M.singleton "bar" "qux") "")
32− ]
33−
34− , fromAssertions "trySetField"
35− [ (Page (M.singleton "bar" "foo") "") @=? trySetField "bar" "foo" mempty
36− , (Page (M.singleton "bar" "qux") "") @=?
37− trySetField "bar" "foo" (Page (M.singleton "bar" "qux") "")
38− ]
39−
40− , fromAssertions "setFieldA"
41− [ (Page (M.singleton "bar" "foo") "") @=?
42− setFieldA "bar" (map toLower) (mempty, "FOO")
43− ]
44−
45− , fromAssertions "renderDateField"
46− [ (@=?) "January 31, 2010" $ getField "date" $ renderDateField
47− "date" "%B %e, %Y" "Date unknown" $ Page
48− (M.singleton "path" "/posts/2010-01-31-a-post.mkdwn") ""
49− , (@=?) "Date unknown" $ getField "date" $ renderDateField
50− "date" "%B %e, %Y" "Date unknown" $ Page
51− (M.singleton "path" "/posts/a-post.mkdwn") ""
52− , (@=?) "February 20, 2000" $ getField "date" $ renderDateField
53− "date" "%B %e, %Y" "Date unknown" $ flip Page "" $ M.fromList
54− [ ("path", "/posts/2010-01-31-a-post.mkdwn")
55− , ("published", "February 20, 2000 1:00 PM")
56− ]
57− , (@=?) "October 22, 2012" $ getField "date" $ renderDateField
58− "date" "%B %e, %Y" "Date unknown" $ Page
59− (M.singleton "date" "2012-10-22 14:35:24") ""
60− ]
61−
62− , fromAssertions "copyBodyToField"
63− [ (Page (M.singleton "bar" "foo") "foo") @=?
64− copyBodyToField "bar" (Page M.empty "foo")
65− ]
66−
67− , fromAssertions "copyBodyFromField"
68− [ (Page (M.singleton "bar" "foo") "foo") @=?
69− copyBodyFromField "bar" (Page (M.singleton "bar" "foo") "qux")
70− ]
71−
72− , fromAssertions "comparePagesByDate"
73− [ GT @=? comparePagesByDate
74− (Page (M.singleton "path" "/posts/1990-08-26-foo.mkdwn") "")
75− (Page (M.singleton "path" "/posts/1990-06-18-qux.mkdwn") "")
76− ]
77− ]
tests/Hakyll/Web/Page/Tests.hsdeleted−40
@@ -1,40 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Hakyll.Web.Page.Tests
3− ( tests
4− ) where
5−
6−import Test.Framework
7−import Test.HUnit hiding (Test)
8−
9−import qualified Data.Map as M
10−
11−import Hakyll.Web.Page
12−import Hakyll.Web.Page.Read
13−import TestSuite.Util
14−
15−tests :: [Test]
16−tests = fromAssertions "readPage"
17− [ Page (M.singleton "foo" "bar") "body" @=? readPage
18− "--- \n\
19− \foo: bar \n\
20− \--- \n\
21− \body"
22−
23− , Page M.empty "line one\nlijn twee" @=? readPage
24− "line one\n\
25− \lijn twee"
26−
27− , Page (M.fromList [("field1", "unos"), ("veld02", "deux")]) "" @=? readPage
28− "---\n\
29− \veld02: deux\n\
30− \field1: unos\n\
31− \---\n"
32−
33− , Page (M.fromList [("author", "jasper"), ("title", "lol")]) "O hai\n"
34− @=? readPage
35− "---\n\
36− \author: jasper\n\
37− \title: lol\n\
38− \...\n\
39− \O hai\n"
40− ]
tests/Hakyll/Web/Template/Context/Tests.hsnew file+51
@@ -0,0 +1,51 @@
1+--------------------------------------------------------------------------------
2+{-# LANGUAGE OverloadedStrings #-}
3+module Hakyll.Web.Template.Context.Tests
4+ ( tests
5+ ) where
6+
7+
8+--------------------------------------------------------------------------------
9+import Test.Framework (Test, testGroup)
10+import Test.Framework.Providers.HUnit (testCase)
11+import Test.HUnit (Assertion, (@=?))
12+
13+
14+--------------------------------------------------------------------------------
15+import Hakyll.Core.Compiler
16+import Hakyll.Core.Identifier
17+import Hakyll.Core.Provider
18+import Hakyll.Core.Store (Store)
19+import Hakyll.Web.Template.Context
20+import TestSuite.Util
21+
22+
23+--------------------------------------------------------------------------------
24+tests :: Test
25+tests = testGroup "Hakyll.Core.Template.Context.Tests"
26+ [ testCase "testDateField" testDateField
27+ ]
28+
29+
30+--------------------------------------------------------------------------------
31+testDateField :: Assertion
32+testDateField = withTestStore $ \store -> do
33+ provider <- newTestProvider store
34+
35+ date1 <- testContextDone store provider "example.md" "date" $
36+ dateField "date" "%B %e, %Y"
37+ date1 @=? "October 22, 2012"
38+
39+ date2 <- testContextDone store provider
40+ "posts/2010-08-26-birthday.md" "date" $
41+ dateField "date" "%B %e, %Y"
42+ date2 @=? "August 26, 2010"
43+
44+
45+--------------------------------------------------------------------------------
46+testContextDone :: Store -> Provider -> Identifier -> String
47+ -> Context String -> IO String
48+testContextDone store provider identifier key context =
49+ testCompilerDone store provider identifier $ do
50+ item <- getResourceBody
51+ unContext context key item
tests/TestSuite.hs+3−1
@@ -5,7 +5,7 @@ module Main
55
66
77--------------------------------------------------------------------------------
8−import Test.Framework (defaultMain)
8+import Test.Framework (defaultMain)
99
1010
1111--------------------------------------------------------------------------------
@@ -18,6 +18,7 @@ import qualified Hakyll.Core.Runtime.Tests
1818import qualified Hakyll.Core.Store.Tests
1919import qualified Hakyll.Core.UnixFilter.Tests
2020import qualified Hakyll.Core.Util.String.Tests
21+import qualified Hakyll.Web.Template.Context.Tests
2122import qualified Hakyll.Web.Template.Tests
2223import qualified Hakyll.Web.Urls.Relativize.Tests
2324import qualified Hakyll.Web.Urls.Tests
@@ -36,6 +37,7 @@ main = defaultMain
3637 , Hakyll.Core.Store.Tests.tests
3738 , Hakyll.Core.UnixFilter.Tests.tests
3839 , Hakyll.Core.Util.String.Tests.tests
40+ , Hakyll.Web.Template.Context.Tests.tests
3941 , Hakyll.Web.Template.Tests.tests
4042 , Hakyll.Web.Urls.Relativize.Tests.tests
4143 , Hakyll.Web.Urls.Tests.tests
tests/data/example.md.metadata+1
@@ -1 +1,2 @@
11external: External data
2+date: 2012-10-22 14:35:24
tests/data/posts/2010-08-26-birthday.mdnew file+1
@@ -0,0 +1 @@
1+It's my birthday today.
tests/data/template.html+1−1
@@ -1,5 +1,5 @@
11<div>
22 I'm so rich I have $$3.
3− $echo test$
3+ $echo test!$
44 $body$
55</div>
tests/data/template.html.out+1−1
@@ -1,5 +1,5 @@
11<div>
22 I'm so rich I have $3.
3− test
3+ test!
44 <p>This is an example.</p>
55</div>