git.iko.soy/typeable/pandoc
on master help sign in
Docx tests: Added media test comparison function.
16f88edJesse Rosenthal
pandoc.cabal+1
@@ -385,6 +385,7 @@ Test-Suite test-pandoc
385 syb >= 0.1 && < 0.5,
385 syb >= 0.1 && < 0.5,
386 pandoc,
386 pandoc,
387 pandoc-types >= 1.12.3.3 && < 1.13,
387 pandoc-types >= 1.12.3.3 && < 1.13,
388+ base64-bytestring >= 0.1 && < 1.1,
388 bytestring >= 0.9 && < 0.11,
389 bytestring >= 0.9 && < 0.11,
389 text >= 0.11 && < 1.2,
390 text >= 0.11 && < 1.2,
390 directory >= 1 && < 1.3,
391 directory >= 1 && < 1.3,
tests/Tests/Readers/Docx.hs+19
@@ -5,7 +5,10 @@ import Text.Pandoc.Readers.Native
5import Text.Pandoc.Definition
5import Text.Pandoc.Definition
6import Tests.Helpers
6import Tests.Helpers
7import Test.Framework
7import Test.Framework
8+import qualified Data.ByteString as BS
8import qualified Data.ByteString.Lazy as B
9import qualified Data.ByteString.Lazy as B
10+import qualified Data.ByteString.Char8 as B8
11+import qualified Data.ByteString.Base64 as B64
9import Text.Pandoc.Readers.Docx
12import Text.Pandoc.Readers.Docx
10import Text.Pandoc.Writers.Native (writeNative)
13import Text.Pandoc.Writers.Native (writeNative)
11import qualified Data.Map as M
14import qualified Data.Map as M
@@ -52,6 +55,22 @@ testCompareWithOpts opts name docxFile nativeFile =
52testCompare :: String -> FilePath -> FilePath -> Test
55testCompare :: String -> FilePath -> FilePath -> Test
53testCompare = testCompareWithOpts def
56testCompare = testCompareWithOpts def
54
57
58+testCompareMediaIO :: String -> FilePath -> FilePath -> FilePath -> IO Test
59+testCompareMediaIO name docxFile mediaPath mediaFile = do
60+ df <- B.readFile docxFile
61+ mf <- B.readFile mediaFile
62+ let (_, mb) = readDocx def df
63+ dBytes = case M.lookup mediaPath mb of
64+ Just bs -> bs
65+ Nothing -> error "Media file not found"
66+ d64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks dBytes
67+ m64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks mf
68+ return $ test id name (d64, m64)
69+
70+testCompareMedia :: String -> FilePath -> FilePath -> FilePath -> Test
71+testCompareMedia name docxFile mediaPath mediaFile =
72+ buildTest $ testCompareMediaIO name docxFile mediaPath mediaFile
73+
55
74
56tests :: [Test]
75tests :: [Test]
57tests = [ testGroup "inlines"
76tests = [ testGroup "inlines"