git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1361 from jkr/testNormalize

Docx reader tests: Introduce NoNormPandoc type.

commit793bfc81fe5cb35efa4e0a718d3a82a67a99aeeb authorJohn MacFarlane <jgm@berkeley.edu> dateFri 20 Jun 2014, 16:23 (12 years ago) parent5d01036a4508d7
1 file changed+27−2
tests/Tests/Readers/Docx.hs+27−2
tests/Tests/Readers/Docx.hs+27−2
@@ -7,12 +7,37 @@ import Tests.Helpers
77import Test.Framework
88import qualified Data.ByteString.Lazy as B
99import Text.Pandoc.Readers.Docx
10+import Text.Pandoc.Writers.Native (writeNative)
11+import qualified Data.Map as M
1012
11−compareOutput :: ReaderOptions -> FilePath -> FilePath -> IO (Pandoc, Pandoc)
13+-- We define a wrapper around pandoc that doesn't normalize in the
14+-- tests. Since we do our own normalization, we want to make sure
15+-- we're doing it right.
16+
17+data NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
18+ deriving Show
19+
20+noNorm :: Pandoc -> NoNormPandoc
21+noNorm = NoNormPandoc
22+
23+instance ToString NoNormPandoc where
24+ toString d = writeNative def{ writerStandalone = s } $ toPandoc d
25+ where s = case d of
26+ NoNormPandoc (Pandoc (Meta m) _)
27+ | M.null m -> False
28+ | otherwise -> True
29+
30+instance ToPandoc NoNormPandoc where
31+ toPandoc = unNoNorm
32+
33+compareOutput :: ReaderOptions
34+ -> FilePath
35+ -> FilePath
36+ -> IO (NoNormPandoc, NoNormPandoc)
1237compareOutput opts docxFile nativeFile = do
1338 df <- B.readFile docxFile
1439 nf <- Prelude.readFile nativeFile
15− return $ (readDocx opts df, readNative nf)
40+ return $ (noNorm (readDocx opts df), noNorm (readNative nf))
1641
1742testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO Test
1843testCompareWithOptsIO opts name docxFile nativeFile = do