-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
63 lines (51 loc) · 1.42 KB
/
parser_test.go
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
59
60
61
62
63
package pamphlet
import (
"fmt"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
const (
path = "./fixture"
)
func TestParseNormalEpub(t *testing.T) {
parser, err := Open(fmt.Sprintf("%s/normal.epub", path))
assert.Nil(t, err)
assert.NotNil(t, parser)
testParseBookContent(t, parser.GetBook())
assert.Nil(t, parser.Close())
}
func TestParseNormalEpubByBytes(t *testing.T) {
filename := fmt.Sprintf("%s/normal.epub", path)
file, err := os.Open(filename)
assert.Nil(t, err)
parser, err := OpenFile(file)
assert.Nil(t, err)
assert.NotNil(t, parser)
testParseBookContent(t, parser.GetBook())
assert.Nil(t, parser.Close())
}
func TestParseWrongToCAttributeEpubFile(t *testing.T) {
parser, err := Open(fmt.Sprintf("%s/wrong_toc_attribute.epub", path))
assert.Nil(t, err)
assert.NotNil(t, parser)
testParseBookContent(t, parser.GetBook())
assert.Nil(t, parser.Close())
}
func TestParseMissingEpubFile(t *testing.T) {
_, err := Open(fmt.Sprintf("%s/not_existing.epub", path))
assert.NotNil(t, err)
assert.Equal(t, err, ErrOpenEpub)
}
func TestParseInvalidEpub(t *testing.T) {
_, err := Open(fmt.Sprintf("%s/wrong_mimetype.epub", path))
assert.NotNil(t, err)
assert.Equal(t, err, ErrNotEpub)
}
func testParseBookContent(t *testing.T, book *Book) {
assert.NotNil(t, book)
assert.Equal(t, "normal book", book.Title)
assert.Equal(t, "timsims", book.Author)
chapters := book.Chapters
assert.NotEmpty(t, chapters)
}