summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Web
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Hakyll/Web')
-rw-r--r--tests/Hakyll/Web/Html/Tests.hs13
-rw-r--r--tests/Hakyll/Web/Pandoc/Biblio/Tests.hs66
2 files changed, 78 insertions, 1 deletions
diff --git a/tests/Hakyll/Web/Html/Tests.hs b/tests/Hakyll/Web/Html/Tests.hs
index cd362f4..9ab10bc 100644
--- a/tests/Hakyll/Web/Html/Tests.hs
+++ b/tests/Hakyll/Web/Html/Tests.hs
@@ -20,7 +20,18 @@ tests :: TestTree
tests = testGroup "Hakyll.Web.Html.Tests" $ concat
[ fromAssertions "demoteHeaders"
[ "<h2>A h1 title</h2>" @=?
- demoteHeaders "<h1>A h1 title</h1>"
+ demoteHeaders "<h1>A h1 title</h1>" -- Assert single-step demotion
+ , "<h6>A h6 title</h6>" @=?
+ demoteHeaders "<h6>A h6 title</h6>" -- Assert maximum demotion is h6
+ ]
+
+ , fromAssertions "demoteHeadersBy"
+ [ "<h3>A h1 title</h3>" @=?
+ demoteHeadersBy 2 "<h1>A h1 title</h1>"
+ , "<h6>A h5 title</h6>" @=?
+ demoteHeadersBy 2 "<h5>A h5 title</h5>" -- Assert that h6 is the lowest possible demoted header.
+ , "<h4>A h4 title</h4>" @=?
+ demoteHeadersBy 0 "<h4>A h4 title</h4>" -- Assert that a demotion of @N < 1@ is a no-op.
]
, fromAssertions "withUrls"
diff --git a/tests/Hakyll/Web/Pandoc/Biblio/Tests.hs b/tests/Hakyll/Web/Pandoc/Biblio/Tests.hs
new file mode 100644
index 0000000..fb98f08
--- /dev/null
+++ b/tests/Hakyll/Web/Pandoc/Biblio/Tests.hs
@@ -0,0 +1,66 @@
+--------------------------------------------------------------------------------
+{-# LANGUAGE OverloadedStrings #-}
+module Hakyll.Web.Pandoc.Biblio.Tests
+ ( tests
+ ) where
+
+
+--------------------------------------------------------------------------------
+import System.FilePath ((</>))
+import Test.Tasty (TestTree, testGroup)
+import Test.Tasty.Golden (goldenVsString)
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Lazy as LBS
+
+
+--------------------------------------------------------------------------------
+import Hakyll
+import Hakyll.Core.Runtime
+import Hakyll.Web.Pandoc.Biblio
+import qualified Hakyll.Core.Logger as Logger
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: TestTree
+tests = testGroup "Hakyll.Web.Pandoc.Biblio.Tests" $
+ [ goldenTest01
+ ]
+
+--------------------------------------------------------------------------------
+goldenTestsDataDir :: FilePath
+goldenTestsDataDir = "tests/data/biblio"
+
+--------------------------------------------------------------------------------
+goldenTest01 :: TestTree
+goldenTest01 =
+ goldenVsString
+ "biblio01"
+ (goldenTestsDataDir </> "biblio01.golden")
+ (do
+ -- Code lifted from https://github.com/jaspervdj/hakyll-citeproc-example.
+ logger <- Logger.new Logger.Error
+ let config = testConfiguration { providerDirectory = goldenTestsDataDir }
+ _ <- run config logger $ do
+ let myPandocBiblioCompiler = do
+ csl <- load "chicago.csl"
+ bib <- load "refs.bib"
+ getResourceBody >>=
+ readPandocBiblio defaultHakyllReaderOptions csl bib >>=
+ return . writePandoc
+
+ match "default.html" $ compile templateCompiler
+ match "chicago.csl" $ compile cslCompiler
+ match "refs.bib" $ compile biblioCompiler
+ match "page.markdown" $ do
+ route $ setExtension "html"
+ compile $
+ myPandocBiblioCompiler >>=
+ loadAndApplyTemplate "default.html" defaultContext
+
+ output <- fmap LBS.fromStrict $ B.readFile $
+ destinationDirectory testConfiguration </> "page.html"
+
+ cleanTestEnv
+
+ return output)