2019-02-04 22:52:31 +01:00
|
|
|
{- |
|
|
|
|
Module : Tests.Readers.EPUB
|
2022-01-01 20:02:31 +01:00
|
|
|
Copyright : © 2006-2022 John MacFarlane
|
2019-02-04 22:52:31 +01:00
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.eu>
|
|
|
|
Stability : alpha
|
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Tests for the EPUB mediabag.
|
|
|
|
-}
|
2014-08-10 15:33:18 +02:00
|
|
|
module Tests.Readers.EPUB (tests) where
|
|
|
|
|
2017-03-04 13:03:41 +01:00
|
|
|
import qualified Data.ByteString.Lazy as BL
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
import qualified Data.Text as T
|
2017-03-14 17:05:36 +01:00
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.HUnit
|
2016-12-01 18:47:05 +01:00
|
|
|
import qualified Text.Pandoc.Class as P
|
2017-03-04 13:03:41 +01:00
|
|
|
import Text.Pandoc.MediaBag (MediaBag, mediaDirectory)
|
|
|
|
import Text.Pandoc.Options
|
|
|
|
import Text.Pandoc.Readers.EPUB
|
2014-08-10 15:33:18 +02:00
|
|
|
|
|
|
|
getMediaBag :: FilePath -> IO MediaBag
|
2016-12-01 18:47:05 +01:00
|
|
|
getMediaBag fp = do
|
|
|
|
bs <- BL.readFile fp
|
2017-07-29 20:54:25 +02:00
|
|
|
P.runIOorExplode $ do
|
|
|
|
readEPUB def bs
|
|
|
|
P.getMediaBag
|
2014-08-10 15:33:18 +02:00
|
|
|
|
|
|
|
testMediaBag :: FilePath -> [(String, String, Int)] -> IO ()
|
|
|
|
testMediaBag fp bag = do
|
2018-01-20 06:25:24 +01:00
|
|
|
actBag <- mediaDirectory <$> getMediaBag fp
|
2014-08-10 15:33:18 +02:00
|
|
|
assertBool (show "MediaBag did not match:\nExpected: "
|
|
|
|
++ show bag
|
|
|
|
++ "\nActual: "
|
|
|
|
++ show actBag)
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
(actBag == packBag bag)
|
|
|
|
where
|
|
|
|
packBag = map $ \(x, y, z) -> (x, T.pack y, z)
|
2014-08-10 15:33:18 +02:00
|
|
|
|
|
|
|
featuresBag :: [(String, String, Int)]
|
2015-04-23 02:38:59 +02:00
|
|
|
featuresBag = [("img/check.gif","image/gif",1340)
|
|
|
|
,("img/check.jpg","image/jpeg",2661)
|
|
|
|
,("img/check.png","image/png",2815)
|
|
|
|
,("img/multiscripts_and_greek_alphabet.png","image/png",10060)
|
|
|
|
]
|
2014-08-10 15:33:18 +02:00
|
|
|
|
2019-06-22 22:07:26 +02:00
|
|
|
-- with additional meta tag for cover in EPUB2 format
|
|
|
|
epub3CoverBag :: [(String, String, Int)]
|
2021-05-29 20:48:52 +02:00
|
|
|
epub3CoverBag = [("wasteland-cover.jpg","image/jpeg", 16586)]
|
2019-06-22 22:07:26 +02:00
|
|
|
|
|
|
|
epub3NoCoverBag :: [(String, String, Int)]
|
|
|
|
epub3NoCoverBag = [("img/check.gif","image/gif",1340)
|
|
|
|
,("img/check.jpg","image/jpeg",2661)
|
|
|
|
,("img/check.png","image/png",2815)
|
|
|
|
]
|
|
|
|
|
|
|
|
-- content.opf uses the word `picture` to refer to the cover as much as validly possible
|
|
|
|
-- to check if references are resolved correctly
|
|
|
|
epub2PictureBag :: [(String, String, Int)]
|
|
|
|
epub2PictureBag = [("image/image.jpg","image/jpeg",9713)]
|
|
|
|
|
|
|
|
-- content.opf contains the word `cover` as much as possible, to check if possible multiple matches cause errors
|
|
|
|
epub2CoverBag :: [(String, String, Int)]
|
|
|
|
epub2CoverBag = [("image/cover.jpg","image/jpeg",9713)]
|
|
|
|
|
|
|
|
epub2NoCoverBag :: [(String, String, Int)]
|
|
|
|
epub2NoCoverBag = []
|
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2014-08-10 15:33:18 +02:00
|
|
|
tests =
|
|
|
|
[ testGroup "EPUB Mediabag"
|
|
|
|
[ testCase "features bag"
|
2019-06-22 22:07:26 +02:00
|
|
|
(testMediaBag "epub/img.epub" featuresBag),
|
|
|
|
testCase "EPUB3 cover bag"
|
|
|
|
(testMediaBag "epub/wasteland.epub" epub3CoverBag),
|
|
|
|
testCase "EPUB3 no cover bag"
|
|
|
|
(testMediaBag "epub/img_no_cover.epub" epub3NoCoverBag),
|
|
|
|
testCase "EPUB2 picture bag"
|
|
|
|
(testMediaBag "epub/epub2_picture.epub" epub2PictureBag),
|
|
|
|
testCase "EPUB2 cover bag"
|
|
|
|
(testMediaBag "epub/epub2_cover.epub" epub2CoverBag),
|
|
|
|
testCase "EPUB2 no cover bag"
|
|
|
|
(testMediaBag "epub/epub2_no_cover.epub" epub2NoCoverBag)
|
2014-08-10 15:33:18 +02:00
|
|
|
]
|
|
|
|
]
|