diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2014-07-30 22:31:38 -0400 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2014-07-30 22:31:38 -0400 |
commit | 16f88edb3bca8afbaba5de13b74ab74fcb5abf57 (patch) | |
tree | 712bd041b5cdb9939ed2e0a06c095b71841d2f58 /tests/Tests/Readers | |
parent | 71e76175be8a5fabb807a8462a1ab315868c8914 (diff) | |
download | pandoc-16f88edb3bca8afbaba5de13b74ab74fcb5abf57.tar.gz |
Docx tests: Added media test comparison function.
Also tell pandoc.cabal that we'll be needing base64, since we want to
compare strings here.
Diffstat (limited to 'tests/Tests/Readers')
-rw-r--r-- | tests/Tests/Readers/Docx.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs index e8dd6b72e..e57376063 100644 --- a/tests/Tests/Readers/Docx.hs +++ b/tests/Tests/Readers/Docx.hs @@ -5,7 +5,10 @@ import Text.Pandoc.Readers.Native import Text.Pandoc.Definition import Tests.Helpers import Test.Framework +import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as B +import qualified Data.ByteString.Char8 as B8 +import qualified Data.ByteString.Base64 as B64 import Text.Pandoc.Readers.Docx import Text.Pandoc.Writers.Native (writeNative) import qualified Data.Map as M @@ -52,6 +55,22 @@ testCompareWithOpts opts name docxFile nativeFile = testCompare :: String -> FilePath -> FilePath -> Test testCompare = testCompareWithOpts def +testCompareMediaIO :: String -> FilePath -> FilePath -> FilePath -> IO Test +testCompareMediaIO name docxFile mediaPath mediaFile = do + df <- B.readFile docxFile + mf <- B.readFile mediaFile + let (_, mb) = readDocx def df + dBytes = case M.lookup mediaPath mb of + Just bs -> bs + Nothing -> error "Media file not found" + d64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks dBytes + m64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks mf + return $ test id name (d64, m64) + +testCompareMedia :: String -> FilePath -> FilePath -> FilePath -> Test +testCompareMedia name docxFile mediaPath mediaFile = + buildTest $ testCompareMediaIO name docxFile mediaPath mediaFile + tests :: [Test] tests = [ testGroup "inlines" |