aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2014-06-20 18:26:15 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2014-06-20 18:37:52 -0400
commita4508d7fcff0fc80af7b9d03177679860f4d00e6 (patch)
tree6973fadcd18cf902cf4ea690bb6985e1e93b6e7b /tests
parent12efffa85a257dbe81137f97334b2c6a7e072777 (diff)
downloadpandoc-a4508d7fcff0fc80af7b9d03177679860f4d00e6.tar.gz
Docx reader tests: Introduce NoNormPandoc type.
This is just a wrapper around Pandoc that doesn't normalize with `toString`. We want to make sure that our own normalization process works. If, in the future, we are able to hook into the builder's normalization, this will be removed.
Diffstat (limited to 'tests')
-rw-r--r--tests/Tests/Readers/Docx.hs29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs
index 3a13641a9..e8fa33241 100644
--- a/tests/Tests/Readers/Docx.hs
+++ b/tests/Tests/Readers/Docx.hs
@@ -7,12 +7,37 @@ import Tests.Helpers
import Test.Framework
import qualified Data.ByteString.Lazy as B
import Text.Pandoc.Readers.Docx
+import Text.Pandoc.Writers.Native (writeNative)
+import qualified Data.Map as M
-compareOutput :: ReaderOptions -> FilePath -> FilePath -> IO (Pandoc, Pandoc)
+-- We define a wrapper around pandoc that doesn't normalize in the
+-- tests. Since we do our own normalization, we want to make sure
+-- we're doing it right.
+
+data NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
+ deriving Show
+
+noNorm :: Pandoc -> NoNormPandoc
+noNorm = NoNormPandoc
+
+instance ToString NoNormPandoc where
+ toString d = writeNative def{ writerStandalone = s } $ toPandoc d
+ where s = case d of
+ NoNormPandoc (Pandoc (Meta m) _)
+ | M.null m -> False
+ | otherwise -> True
+
+instance ToPandoc NoNormPandoc where
+ toPandoc = unNoNorm
+
+compareOutput :: ReaderOptions
+ -> FilePath
+ -> FilePath
+ -> IO (NoNormPandoc, NoNormPandoc)
compareOutput opts docxFile nativeFile = do
df <- B.readFile docxFile
nf <- Prelude.readFile nativeFile
- return $ (readDocx opts df, readNative nf)
+ return $ (noNorm (readDocx opts df), noNorm (readNative nf))
testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO Test
testCompareWithOptsIO opts name docxFile nativeFile = do