summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-05-06 23:32:25 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2013-05-06 23:32:25 +0200
commitcf138a415b0fbfa5153deec693f1310547f359b2 (patch)
tree106de43225a4ac3ea4c3b71b7dbf8d99fdd5b2c7 /tests
parent738fd3d1ad36c7d799d2f47ed31022bfd86b88f4 (diff)
downloadhakyll-cf138a415b0fbfa5153deec693f1310547f359b2.tar.gz
Implement foreach structure
Diffstat (limited to 'tests')
-rw-r--r--tests/Hakyll/Web/Template/Context/Tests.hs7
-rw-r--r--tests/Hakyll/Web/Template/Tests.hs11
-rw-r--r--tests/data/template.html13
-rw-r--r--tests/data/template.html.out15
4 files changed, 41 insertions, 5 deletions
diff --git a/tests/Hakyll/Web/Template/Context/Tests.hs b/tests/Hakyll/Web/Template/Context/Tests.hs
index 5533c71..627624f 100644
--- a/tests/Hakyll/Web/Template/Context/Tests.hs
+++ b/tests/Hakyll/Web/Template/Context/Tests.hs
@@ -51,4 +51,9 @@ testContextDone :: Store -> Provider -> Identifier -> String
testContextDone store provider identifier key context =
testCompilerDone store provider identifier $ do
item <- getResourceBody
- unContext context key item
+ cf <- unContext context key item
+ case cf of
+ StringField str -> return str
+ ListField _ _ -> error $
+ "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
+ "Didn't expect ListField"
diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs
index b96cfa5..1d80a06 100644
--- a/tests/Hakyll/Web/Template/Tests.hs
+++ b/tests/Hakyll/Web/Template/Tests.hs
@@ -13,6 +13,7 @@ import Test.HUnit (Assertion, (@=?), (@?=))
--------------------------------------------------------------------------------
+import Hakyll.Core.Compiler
import Hakyll.Core.Item
import Hakyll.Core.Provider
import Hakyll.Web.Pandoc
@@ -43,6 +44,8 @@ case01 = do
item <- testCompilerDone store provider "example.md" $
pandocCompiler >>= applyTemplate (itemBody tpl) testContext
+ writeFile "foo" (itemBody item)
+
out @=? itemBody item
cleanTestEnv
@@ -50,9 +53,13 @@ case01 = do
--------------------------------------------------------------------------------
testContext :: Context String
testContext = mconcat
- [ functionField "echo" (\args _ -> return $ unwords args)
- , defaultContext
+ [ defaultContext
+ , listField "authors" (bodyField "name") $ do
+ n1 <- makeItem "Jan"
+ n2 <- makeItem "Piet"
+ return [n1, n2]
]
+ where
--------------------------------------------------------------------------------
diff --git a/tests/data/template.html b/tests/data/template.html
index 6f668ee..22e5ddd 100644
--- a/tests/data/template.html
+++ b/tests/data/template.html
@@ -1,16 +1,27 @@
<div>
I'm so rich I have $$3.
- $echo test$
+
$if(body)$
I have body
$else$
or no
$endif$
+
$if(unbound)$
should not be printed
$endif$
+
$if(body)$
should be printed
$endif$
+
+ <ul>
+ $for(authors)$
+ <li>$name$</li>
+ $endfor$
+ </ul>
+
+ $for(authors)$$name$$sep$, $endfor$
+
$body$
</div>
diff --git a/tests/data/template.html.out b/tests/data/template.html.out
index 5c201e2..8047b0d 100644
--- a/tests/data/template.html.out
+++ b/tests/data/template.html.out
@@ -1,12 +1,25 @@
<div>
I'm so rich I have $3.
- test
+
I have body
+
+
should be printed
+
+ <ul>
+
+ <li>Jan</li>
+
+ <li>Piet</li>
+
+ </ul>
+
+ Jan, Piet
+
<p>This is an example.</p>
</div>