| 1 |
-------------------------------------------------------------------------------- |
| 2 |
{-# LANGUAGE OverloadedStrings #-} |
| 3 |
{-# LANGUAGE CPP #-} |
| 4 |
module Hakyll.Web.Pandoc.Biblio.Tests |
| 5 |
( tests |
| 6 |
) where |
| 7 |
|
| 8 |
|
| 9 |
-------------------------------------------------------------------------------- |
| 10 |
import System.FilePath ((</>)) |
| 11 |
import Test.Tasty (TestTree, testGroup) |
| 12 |
import Test.Tasty.Golden (goldenVsString) |
| 13 |
import qualified Data.ByteString as B |
| 14 |
import qualified Data.ByteString.Lazy as LBS |
| 15 |
|
| 16 |
|
| 17 |
-------------------------------------------------------------------------------- |
| 18 |
import Hakyll |
| 19 |
import Hakyll.Core.Runtime |
| 20 |
import qualified Hakyll.Core.Logger as Logger |
| 21 |
import TestSuite.Util |
| 22 |
|
| 23 |
|
| 24 |
-------------------------------------------------------------------------------- |
| 25 |
tests :: TestTree |
| 26 |
tests = testGroup "Hakyll.Web.Pandoc.Biblio.Tests" $ |
| 27 |
[ goldenTest01 |
| 28 |
, goldenTest02 |
| 29 |
, goldenTest03 |
| 30 |
] |
| 31 |
|
| 32 |
-------------------------------------------------------------------------------- |
| 33 |
goldenTestsDataDir :: FilePath |
| 34 |
goldenTestsDataDir = "tests/data/biblio" |
| 35 |
|
| 36 |
-------------------------------------------------------------------------------- |
| 37 |
goldenTest01 :: TestTree |
| 38 |
goldenTest01 = |
| 39 |
goldenVsString |
| 40 |
"biblio01" |
| 41 |
(goldenTestsDataDir </> goldenTest) |
| 42 |
(do |
| 43 |
-- Code lifted from https://github.com/jaspervdj/hakyll-citeproc-example. |
| 44 |
logger <- Logger.new Logger.Error |
| 45 |
let config = testConfiguration { providerDirectory = goldenTestsDataDir } |
| 46 |
_ <- run RunModeNormal config logger $ do |
| 47 |
let myPandocBiblioCompiler = do |
| 48 |
csl <- load "chicago.csl" |
| 49 |
bib <- load "refs.bib" |
| 50 |
getResourceBody >>= |
| 51 |
readPandocBiblio defaultHakyllReaderOptions csl bib >>= |
| 52 |
return . writePandoc |
| 53 |
|
| 54 |
match "default.html" $ compile templateCompiler |
| 55 |
match "chicago.csl" $ compile cslCompiler |
| 56 |
match "refs.bib" $ compile biblioCompiler |
| 57 |
match "page.markdown" $ do |
| 58 |
route $ setExtension "html" |
| 59 |
compile $ |
| 60 |
myPandocBiblioCompiler >>= |
| 61 |
loadAndApplyTemplate "default.html" defaultContext |
| 62 |
|
| 63 |
output <- fmap LBS.fromStrict $ B.readFile $ |
| 64 |
destinationDirectory testConfiguration </> "page.html" |
| 65 |
|
| 66 |
cleanTestEnv |
| 67 |
|
| 68 |
return output) |
| 69 |
|
| 70 |
where |
| 71 |
goldenTest = |
| 72 |
#if MIN_VERSION_pandoc(3,1,8) |
| 73 |
"cites-meijer-pandoc-3.1.8plus.golden" |
| 74 |
#elif MIN_VERSION_pandoc(3,0,0) |
| 75 |
"cites-meijer-pandoc-3.0.0plus.golden" |
| 76 |
#else |
| 77 |
"cites-meijer-pandoc-2.0.0plus.golden" |
| 78 |
#endif |
| 79 |
|
| 80 |
goldenTest02 :: TestTree |
| 81 |
goldenTest02 = |
| 82 |
goldenVsString |
| 83 |
"biblio02" |
| 84 |
(goldenTestsDataDir </> goldenTest) |
| 85 |
(do |
| 86 |
-- Code lifted from https://github.com/jaspervdj/hakyll-citeproc-example. |
| 87 |
logger <- Logger.new Logger.Error |
| 88 |
let config = testConfiguration { providerDirectory = goldenTestsDataDir } |
| 89 |
_ <- run RunModeNormal config logger $ do |
| 90 |
let myPandocBiblioCompiler = do |
| 91 |
csl <- load "chicago.csl" |
| 92 |
bib <- load "refs.yaml" |
| 93 |
getResourceBody >>= |
| 94 |
readPandocBiblio defaultHakyllReaderOptions csl bib >>= |
| 95 |
return . writePandoc |
| 96 |
|
| 97 |
match "default.html" $ compile templateCompiler |
| 98 |
match "chicago.csl" $ compile cslCompiler |
| 99 |
match "refs.yaml" $ compile biblioCompiler |
| 100 |
match "page.markdown" $ do |
| 101 |
route $ setExtension "html" |
| 102 |
compile $ |
| 103 |
myPandocBiblioCompiler >>= |
| 104 |
loadAndApplyTemplate "default.html" defaultContext |
| 105 |
|
| 106 |
output <- fmap LBS.fromStrict $ B.readFile $ |
| 107 |
destinationDirectory testConfiguration </> "page.html" |
| 108 |
|
| 109 |
cleanTestEnv |
| 110 |
|
| 111 |
return output) |
| 112 |
where |
| 113 |
goldenTest = |
| 114 |
#if MIN_VERSION_pandoc(3,1,8) |
| 115 |
"cites-meijer-pandoc-3.1.8plus.golden" |
| 116 |
#elif MIN_VERSION_pandoc(3,0,0) |
| 117 |
"cites-meijer-pandoc-3.0.0plus.golden" |
| 118 |
#else |
| 119 |
"cites-meijer-pandoc-2.0.0plus.golden" |
| 120 |
#endif |
| 121 |
|
| 122 |
goldenTest03 :: TestTree |
| 123 |
goldenTest03 = |
| 124 |
goldenVsString |
| 125 |
"biblio03" |
| 126 |
(goldenTestsDataDir </> goldenTest) |
| 127 |
(do |
| 128 |
-- Code lifted from https://github.com/jaspervdj/hakyll-citeproc-example. |
| 129 |
logger <- Logger.new Logger.Error |
| 130 |
let config = testConfiguration { providerDirectory = goldenTestsDataDir } |
| 131 |
_ <- run RunModeNormal config logger $ do |
| 132 |
let myPandocBiblioCompiler = do |
| 133 |
csl <- load "chicago.csl" |
| 134 |
bib1 <- load "refs.bib" |
| 135 |
bib2 <- load "refs2.yaml" |
| 136 |
getResourceBody >>= |
| 137 |
readPandocBiblios defaultHakyllReaderOptions csl [bib1, bib2] >>= |
| 138 |
return . writePandoc |
| 139 |
|
| 140 |
match "default.html" $ compile templateCompiler |
| 141 |
match "chicago.csl" $ compile cslCompiler |
| 142 |
match "refs.bib" $ compile biblioCompiler |
| 143 |
match "refs2.yaml" $ compile biblioCompiler |
| 144 |
match "cites-multiple.markdown" $ do |
| 145 |
route $ setExtension "html" |
| 146 |
compile $ |
| 147 |
myPandocBiblioCompiler >>= |
| 148 |
loadAndApplyTemplate "default.html" defaultContext |
| 149 |
|
| 150 |
output <- fmap LBS.fromStrict $ B.readFile $ |
| 151 |
destinationDirectory testConfiguration </> "cites-multiple.html" |
| 152 |
|
| 153 |
cleanTestEnv |
| 154 |
|
| 155 |
return output) |
| 156 |
where |
| 157 |
goldenTest = |
| 158 |
#if MIN_VERSION_pandoc(3,1,8) |
| 159 |
"cites-multiple-pandoc-3.1.8plus.golden" |
| 160 |
#elif MIN_VERSION_pandoc(3,0,0) |
| 161 |
"cites-multiple-pandoc-3.0.0plus.golden" |
| 162 |
#else |
| 163 |
"cites-multiple-pandoc-2.0.0plus.golden" |
| 164 |
#endif |