From 478a2e8590c160d0ca657bfbd8e5c852034f651f Mon Sep 17 00:00:00 2001 From: Alexander Batischev Date: Mon, 7 Dec 2020 09:21:41 +0300 Subject: Add golden test for Pandoc.Biblio (#827) --- tests/Hakyll/Web/Pandoc/Biblio/Tests.hs | 66 ++++ tests/TestSuite.hs | 2 + tests/data/biblio/biblio01.golden | 16 + tests/data/biblio/chicago.csl | 648 ++++++++++++++++++++++++++++++++ tests/data/biblio/default.html | 11 + tests/data/biblio/page.markdown | 5 + tests/data/biblio/refs.bib | 8 + 7 files changed, 756 insertions(+) create mode 100644 tests/Hakyll/Web/Pandoc/Biblio/Tests.hs create mode 100644 tests/data/biblio/biblio01.golden create mode 100644 tests/data/biblio/chicago.csl create mode 100644 tests/data/biblio/default.html create mode 100644 tests/data/biblio/page.markdown create mode 100644 tests/data/biblio/refs.bib (limited to 'tests') 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) diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs index c3e32f8..7c18470 100644 --- a/tests/TestSuite.hs +++ b/tests/TestSuite.hs @@ -24,6 +24,7 @@ import qualified Hakyll.Web.CompressCss.Tests import qualified Hakyll.Web.Html.RelativizeUrls.Tests import qualified Hakyll.Web.Html.Tests #ifdef USE_PANDOC +import qualified Hakyll.Web.Pandoc.Biblio.Tests import qualified Hakyll.Web.Pandoc.FileType.Tests #endif import qualified Hakyll.Web.Template.Context.Tests @@ -48,6 +49,7 @@ main = defaultMain $ testGroup "Hakyll" , Hakyll.Web.Html.RelativizeUrls.Tests.tests , Hakyll.Web.Html.Tests.tests #ifdef USE_PANDOC + , Hakyll.Web.Pandoc.Biblio.Tests.tests , Hakyll.Web.Pandoc.FileType.Tests.tests #endif , Hakyll.Web.Tags.Tests.tests diff --git a/tests/data/biblio/biblio01.golden b/tests/data/biblio/biblio01.golden new file mode 100644 index 0000000..ace1e76 --- /dev/null +++ b/tests/data/biblio/biblio01.golden @@ -0,0 +1,16 @@ + + + + + This page cites a paper. + + +

This page cites a paper.

+

I would like to cite one of my favourite papers (Meijer, Fokkinga, and Paterson 1991) here.

+
+
+Meijer, Erik, Maarten Fokkinga, and Ross Paterson. 1991. “Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire.” In Conference on Functional Programming Languages and Computer Architecture, 124–44. Springer. +
+
+ + diff --git a/tests/data/biblio/chicago.csl b/tests/data/biblio/chicago.csl new file mode 100644 index 0000000..47d9eb8 --- /dev/null +++ b/tests/data/biblio/chicago.csl @@ -0,0 +1,648 @@ + + diff --git a/tests/data/biblio/default.html b/tests/data/biblio/default.html new file mode 100644 index 0000000..42197e0 --- /dev/null +++ b/tests/data/biblio/default.html @@ -0,0 +1,11 @@ + + + + + $title$ + + +

$title$

+ $body$ + + diff --git a/tests/data/biblio/page.markdown b/tests/data/biblio/page.markdown new file mode 100644 index 0000000..5a99ac0 --- /dev/null +++ b/tests/data/biblio/page.markdown @@ -0,0 +1,5 @@ +--- +title: This page cites a paper. +--- + +I would like to cite one of my favourite papers [@meijer1991functional] here. diff --git a/tests/data/biblio/refs.bib b/tests/data/biblio/refs.bib new file mode 100644 index 0000000..e4cd89f --- /dev/null +++ b/tests/data/biblio/refs.bib @@ -0,0 +1,8 @@ +@inproceedings{meijer1991functional, + title={Functional programming with bananas, lenses, envelopes and barbed wire}, + author={Meijer, Erik and Fokkinga, Maarten and Paterson, Ross}, + booktitle={Conference on Functional Programming Languages and Computer Architecture}, + pages={124--144}, + year={1991}, + organization={Springer} +} -- cgit v1.2.3