diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2011-11-23 15:24:20 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2011-11-23 15:24:20 +0100 |
commit | d61d7f19fc636f97e60f76b1ab0bd7a249cd96c3 (patch) | |
tree | cf2541ca23fd98852bd7d4d075eb53bef4dd95fe /tests/Hakyll/Web/Template | |
parent | e1687cbb300323e5975413caaf813e07939e89dc (diff) | |
download | hakyll-d61d7f19fc636f97e60f76b1ab0bd7a249cd96c3.tar.gz |
"Allow" missing keys in templates
Diffstat (limited to 'tests/Hakyll/Web/Template')
-rw-r--r-- | tests/Hakyll/Web/Template/Tests.hs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs index c772fa8..efbd392 100644 --- a/tests/Hakyll/Web/Template/Tests.hs +++ b/tests/Hakyll/Web/Template/Tests.hs @@ -16,29 +16,39 @@ import TestSuite.Util tests :: [Test] tests = fromAssertions "applyTemplate" -- Hakyll templates - [ applyTemplateAssertion readTemplate + [ applyTemplateAssertion readTemplate applyTemplate "bar" "$foo$" [("foo", "bar")] - , applyTemplateAssertion readTemplate + , applyTemplateAssertion readTemplate applyTemplate "$ barqux" "$$ $foo$$bar$" [("foo", "bar"), ("bar", "qux")] + , applyTemplateAssertion readTemplate applyTemplate + "$foo$" "$foo$" [] + -- Hamlet templates - , applyTemplateAssertion readHamletTemplate + , applyTemplateAssertion readHamletTemplate applyTemplate "<head><title>notice</title></head><body>A paragraph</body>" "<head\n\ \ <title>#{title}\n\ \<body\n\ \ A paragraph\n" [("title", "notice")] + + -- Missing keys + , let missing "foo" = "bar" + missing "bar" = "qux" + missing x = reverse x + in applyTemplateAssertion readTemplate (applyTemplateWith missing) + "bar foo ver" "$foo$ $bar$ $rev$" [("bar", "foo")] ] -- | Utility function to create quick template tests -- -applyTemplateAssertion :: (String -> Template) -- ^ Template parser - -> String -- ^ Expected - -> String -- ^ Template - -> [(String, String)] -- ^ Page - -> Assertion -- ^ Resulting assertion -applyTemplateAssertion parser expected template page = - expected @=? pageBody (applyTemplate (parser template) - (fromMap $ M.fromList page)) +applyTemplateAssertion :: (String -> Template) + -> (Template -> Page String -> Page String) + -> String + -> String + -> [(String, String)] + -> Assertion +applyTemplateAssertion parser apply expected template page = + expected @=? pageBody (apply (parser template) (fromMap $ M.fromList page)) |