diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Hakyll/Web/Template/Tests.hs | 68 | ||||
-rw-r--r-- | tests/data/strip.html | 34 | ||||
-rw-r--r-- | tests/data/strip.html.out | 18 |
3 files changed, 103 insertions, 17 deletions
diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs index a975901..994d9ca 100644 --- a/tests/Hakyll/Web/Template/Tests.hs +++ b/tests/Hakyll/Web/Template/Tests.hs @@ -6,7 +6,6 @@ module Hakyll.Web.Template.Tests -------------------------------------------------------------------------------- -import Data.Monoid (mconcat) import Test.Framework (Test, testGroup) import Test.Framework.Providers.HUnit (testCase) import Test.HUnit (Assertion, (@=?), (@?=)) @@ -14,6 +13,7 @@ import Test.HUnit (Assertion, (@=?), (@?=)) -------------------------------------------------------------------------------- import Hakyll.Core.Compiler +import Hakyll.Core.Identifier import Hakyll.Core.Item import Hakyll.Core.Provider import Hakyll.Web.Pandoc @@ -27,32 +27,67 @@ import TestSuite.Util -------------------------------------------------------------------------------- tests :: Test tests = testGroup "Hakyll.Core.Template.Tests" $ concat - [ [ testCase "case01" case01 + [ [ testCase "case01" $ test ("template.html.out", "template.html", "example.md") + , testCase "case02" $ test ("strip.html.out", "strip.html", "example.md") , testCase "applyJoinTemplateList" testApplyJoinTemplateList ] , fromAssertions "readTemplate" - [ Template [Chunk "Hello ", Expr (Call "guest" [])] - @=? readTemplate "Hello $guest()$" - , Template - [If (Call "a" [StringLiteral "bar"]) - (Template [Chunk "foo"]) - Nothing] - @=? readTemplate "$if(a(\"bar\"))$foo$endif$" + [ [Chunk "Hello ", Expr (Call "guest" [])] + @=? readTemplateElems "Hello $guest()$" + , [If (Call "a" [StringLiteral "bar"]) [Chunk "foo"] Nothing] + @=? readTemplateElems "$if(a(\"bar\"))$foo$endif$" + -- 'If' trim check. + , [ TrimL + , If (Ident (TemplateKey "body")) + [ TrimR + , Chunk "\n" + , Expr (Ident (TemplateKey "body")) + , Chunk "\n" + , TrimL + ] + (Just [ TrimR + , Chunk "\n" + , Expr (Ident (TemplateKey "body")) + , Chunk "\n" + , TrimL + ]) + , TrimR + ] + @=? readTemplateElems "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$" + -- 'For' trim check. + , [ TrimL + , For (Ident (TemplateKey "authors")) + [TrimR, Chunk "\n body \n", TrimL] + Nothing + , TrimR + ] + @=? readTemplateElems "$-for(authors)-$\n body \n$-endfor-$" + -- 'Partial' trim check. + , [ TrimL + , Partial (StringLiteral "path") + , TrimR + ] + @=? readTemplateElems "$-partial(\"path\")-$" + -- 'Expr' trim check. + , [ TrimL + , Expr (Ident (TemplateKey "foo")) + , TrimR + ] + @=? readTemplateElems "$-foo-$" ] ] -------------------------------------------------------------------------------- -case01 :: Assertion -case01 = do +test :: (Identifier, Identifier, Identifier) -> Assertion +test (outf, tplf, itemf) = do store <- newTestStore provider <- newTestProvider store - out <- resourceString provider "template.html.out" - tpl <- testCompilerDone store provider "template.html" $ - templateBodyCompiler - item <- testCompilerDone store provider "example.md" $ + out <- resourceString provider outf + tpl <- testCompilerDone store provider tplf templateBodyCompiler + item <- testCompilerDone store provider itemf $ pandocCompiler >>= applyTemplate (itemBody tpl) testContext out @=? itemBody item @@ -69,7 +104,6 @@ testContext = mconcat return [n1, n2] , functionField "rev" $ \args _ -> return $ unwords $ map reverse args ] - where -------------------------------------------------------------------------------- @@ -85,4 +119,4 @@ testApplyJoinTemplateList = do where i1 = Item "item1" "Hello" i2 = Item "item2" "World" - tpl = Template [Chunk "<b>", Expr (Ident "body"), Chunk "</b>"] + tpl = readTemplate "<b>$body$</b>" diff --git a/tests/data/strip.html b/tests/data/strip.html new file mode 100644 index 0000000..d28571e --- /dev/null +++ b/tests/data/strip.html @@ -0,0 +1,34 @@ +<div> + I'm so rich I have $$3. + + $rev("foo")$ + $-rev(rev("foo"))$ + + $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/strip.html.out b/tests/data/strip.html.out new file mode 100644 index 0000000..9b37e69 --- /dev/null +++ b/tests/data/strip.html.out @@ -0,0 +1,18 @@ +<div> + I'm so rich I have $3. + + ooffoo + + I have body + should be printed + + <ul> + <li>Jan</li> + <li>Piet</li> + </ul> + + Jan,Piet + + <p>This is an example.</p> +</div> + |