aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-07-26 12:00:44 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-07-28 19:25:45 -0700
commitb35fae651145482f1218d32dbea5fffff60e0b0b (patch)
tree02175f056c40aee4329b8f944ada9c9cd6ac1284 /test
parent99e24cf18337b0b460005bf77e367783c34b75e7 (diff)
downloadpandoc-b35fae651145482f1218d32dbea5fffff60e0b0b.tar.gz
Use doctemplates 0.3, change type of writerTemplate.
* Require recent doctemplates. It is more flexible and supports partials. * Changed type of writerTemplate to Maybe Template instead of Maybe String. * Remove code from the LaTeX, Docbook, and JATS writers that looked in the template for strings to determine whether it is a book or an article, or whether csquotes is used. This was always kludgy and unreliable. To use csquotes for LaTeX, set `csquotes` in your variables or metadata. It is no longer sufficient to put `\usepackage{csquotes}` in your template or header includes. To specify a book style, use the `documentclass` variable or `--top-level-division`. * Change template code to use new API for doctemplates.
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Helpers.hs2
-rw-r--r--test/Tests/Readers/Docx.hs2
-rw-r--r--test/Tests/Readers/FB2.hs2
-rw-r--r--test/Tests/Readers/Odt.hs2
-rw-r--r--test/Tests/Writers/Native.hs2
-rw-r--r--test/Tests/Writers/RST.hs19
-rw-r--r--test/writer.muse2
7 files changed, 21 insertions, 10 deletions
diff --git a/test/Tests/Helpers.hs b/test/Tests/Helpers.hs
index c5dab8f23..5ad867065 100644
--- a/test/Tests/Helpers.hs
+++ b/test/Tests/Helpers.hs
@@ -136,7 +136,7 @@ instance ToString Pandoc where
where s = case d of
(Pandoc (Meta m) _)
| M.null m -> Nothing
- | otherwise -> Just "" -- need this to get meta output
+ | otherwise -> Just mempty -- need this to get meta output
instance ToString Blocks where
toString = unpack . purely (writeNative def) . toPandoc
diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs
index e5bbabadf..9d0913e55 100644
--- a/test/Tests/Readers/Docx.hs
+++ b/test/Tests/Readers/Docx.hs
@@ -46,7 +46,7 @@ instance ToString NoNormPandoc where
where s = case d of
NoNormPandoc (Pandoc (Meta m) _)
| M.null m -> Nothing
- | otherwise -> Just "" -- need this to get meta output
+ | otherwise -> Just mempty -- need this to get meta output
instance ToPandoc NoNormPandoc where
toPandoc = unNoNorm
diff --git a/test/Tests/Readers/FB2.hs b/test/Tests/Readers/FB2.hs
index e64e8a2ce..dd228aeae 100644
--- a/test/Tests/Readers/FB2.hs
+++ b/test/Tests/Readers/FB2.hs
@@ -24,7 +24,7 @@ import Data.Text.Lazy (fromStrict)
import System.FilePath (replaceExtension)
fb2ToNative :: Text -> Text
-fb2ToNative = purely (writeNative def{ writerTemplate = Just "" }) . purely (readFB2 def)
+fb2ToNative = purely (writeNative def{ writerTemplate = Just mempty }) . purely (readFB2 def)
fb2Test :: TestName -> FilePath -> TestTree
fb2Test name path = goldenVsString name native (fromTextLazy . fromStrict . fb2ToNative . toText <$> BS.readFile path)
diff --git a/test/Tests/Readers/Odt.hs b/test/Tests/Readers/Odt.hs
index d66a4e98b..9dc93c92e 100644
--- a/test/Tests/Readers/Odt.hs
+++ b/test/Tests/Readers/Odt.hs
@@ -61,7 +61,7 @@ instance ToString NoNormPandoc where
where s = case d of
NoNormPandoc (Pandoc (Meta m) _)
| M.null m -> Nothing
- | otherwise -> Just "" -- need this for Meta output
+ | otherwise -> Just mempty -- need this for Meta output
instance ToPandoc NoNormPandoc where
toPandoc = unNoNorm
diff --git a/test/Tests/Writers/Native.hs b/test/Tests/Writers/Native.hs
index 708b5069c..905e83b1e 100644
--- a/test/Tests/Writers/Native.hs
+++ b/test/Tests/Writers/Native.hs
@@ -11,7 +11,7 @@ import Text.Pandoc.Arbitrary ()
p_write_rt :: Pandoc -> Bool
p_write_rt d =
- read (unpack $ purely (writeNative def{ writerTemplate = Just "" }) d) == d
+ read (unpack $ purely (writeNative def{ writerTemplate = Just mempty }) d) == d
p_write_blocks_rt :: [Block] -> Bool
p_write_blocks_rt bs =
diff --git a/test/Tests/Writers/RST.hs b/test/Tests/Writers/RST.hs
index 0d5b7c38a..07eef1f60 100644
--- a/test/Tests/Writers/RST.hs
+++ b/test/Tests/Writers/RST.hs
@@ -3,6 +3,7 @@
module Tests.Writers.RST (tests) where
import Prelude
+import Control.Monad.Identity
import Test.Tasty
import Test.Tasty.HUnit
import Tests.Helpers
@@ -10,6 +11,8 @@ import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
import Text.Pandoc.Writers.RST
+import Text.Pandoc.Templates (compileTemplate)
+import qualified Data.Text as T
infix 4 =:
(=:) :: (ToString a, ToPandoc a)
@@ -18,8 +21,15 @@ infix 4 =:
testTemplate :: (ToString a, ToString c, ToPandoc a) =>
String -> String -> (a, c) -> TestTree
-testTemplate t =
- test (purely (writeRST def{ writerTemplate = Just t }) . toPandoc)
+testTemplate t = case runIdentity (compileTemplate [] (T.pack t)) of
+ Left e -> error $ "Could not compile RST template: " ++ e
+ Right templ -> test (purely (writeRST def{ writerTemplate = Just templ }) . toPandoc)
+
+bodyTemplate :: Template
+bodyTemplate = case runIdentity (compileTemplate [] "$body$\n") of
+ Left e -> error $
+ "Could not compile RST bodyTemplate" ++ e
+ Right templ -> templ
tests :: [TestTree]
tests = [ testGroup "rubrics"
@@ -104,7 +114,8 @@ tests = [ testGroup "rubrics"
[ "foo"
, "==="]
-- note: heading normalization is only done in standalone mode
- , test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
+ , test (purely (writeRST def{ writerTemplate = Just bodyTemplate })
+ . toPandoc)
"heading levels" $
header 1 (text "Header 1") <>
header 3 (text "Header 2") <>
@@ -134,7 +145,7 @@ tests = [ testGroup "rubrics"
, ""
, "Header 2"
, "--------"]
- , test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
+ , test (purely (writeRST def{ writerTemplate = Just bodyTemplate }) . toPandoc)
"minimal heading levels" $
header 2 (text "Header 1") <>
header 3 (text "Header 2") <>
diff --git a/test/writer.muse b/test/writer.muse
index 35d43a751..415882677 100644
--- a/test/writer.muse
+++ b/test/writer.muse
@@ -1,4 +1,4 @@
-#author John MacFarlane
+#author John MacFarlane, Anonymous
#title Pandoc Test Suite
#date July 17, 2006