Library for parsing epub document metadata (Haskell)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| -- License: BSD3 (see LICENSE)
-- Author: Dino Morelli <dino@ui3.info>
module ParseSpine
( tests )
where
import Control.Monad.Except
import System.FilePath
import Test.HUnit
import Codec.Epub.Data.Spine
import Codec.Epub.Parse
tests :: Test
tests = TestList
[ testFull
, testMinimal
, testMissingAll
]
{- A test containing a couple of spine items
-}
testFull :: Test
testFull = TestCase $ do
xmlString <- readFile $ "testsuite" </> "epub2-full.opf"
actual <- runExceptT $ getSpine xmlString
let expected =
Right Spine
{ spineToc = "ncx"
, spineItemrefs =
[ SpineItemref {siIdRef = "titlePage", siLinear = Nothing}
, SpineItemref {siIdRef = "someContent", siLinear = Nothing}
]
}
assertEqual "some spine items" expected actual
{- Minimal spine, only the spineToc is required
-}
testMinimal :: Test
testMinimal = TestCase $ do
xmlString <- liftIO $ readFile $ "testsuite" </> "epub2-minimal.opf"
actual <- runExceptT $ getSpine xmlString
let expected = Right Spine {spineToc = "ncx", spineItemrefs = []}
assertEqual "minimal" expected actual
{- Missing any spine info at all
-}
testMissingAll :: Test
testMissingAll = TestCase $ do
xmlString <- readFile $ "testsuite" </> "epub2-missingAll.opf"
actual <- runExceptT $ getSpine xmlString
let expected = Right Spine {spineToc = "", spineItemrefs = []}
assertEqual "missing all" expected actual
|