-
Notifications
You must be signed in to change notification settings - Fork 13
/
spine_test.go
127 lines (109 loc) · 2.62 KB
/
spine_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2012 Ruben Pollan <[email protected]>
// Use of this source code is governed by a LGPL licence
// version 3 or later that can be found in the LICENSE file.
package epubgo
import "testing"
import (
"bytes"
"io/ioutil"
)
const (
spineURL = "wrap0000.html"
)
func TestFirst(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, err := f.Spine()
if err != nil {
t.Errorf("epub.Spine() return an error: %v", err)
}
if !it.IsFirst() {
t.Errorf("it.IsFirst() not behaving as expected")
}
if it.IsLast() {
t.Errorf("it.IsLast() not behaving as expected")
}
}
func TestLast(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Spine()
if err := it.Next(); err != nil {
t.Errorf("it.Next() return an error: %v", err)
}
if it.IsFirst() {
t.Errorf("it.IsFirst() not behaving as expected")
}
if !it.IsLast() {
t.Errorf("it.IsLast() not behaving as expected")
}
}
func TestLastNext(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Spine()
if err := it.Next(); err != nil {
t.Errorf("it.Next() return an error: %v", err)
}
if err := it.Next(); err == nil {
t.Errorf("it.Next() didn't return an error being the last element")
}
}
func TestMove(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Spine()
if it.Previous() == nil {
t.Errorf("it.Previous() din't return an error being the first")
}
if err := it.Next(); err != nil {
t.Errorf("it.Next() return an error: %v", err)
}
if err := it.Next(); err == nil {
t.Errorf("it.Next() didn't return an error being the last")
}
if err := it.Previous(); err != nil {
t.Errorf("it.Next() return an error: %v", err)
}
if !it.IsFirst() {
t.Errorf("it.IsFirst() not behaving as expected")
}
if it.IsLast() {
t.Errorf("it.IsLast() not behaving as expected")
}
}
func TestSpineURL(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Spine()
if it.URL() != spineURL {
t.Errorf("it.URL() return: %v when was expected: %v", it.URL(), spineURL)
}
}
func TestSpineOpen(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Spine()
html1, err := it.Open()
if err != nil {
t.Errorf("it.Open() return an error: %v", err)
return
}
defer html1.Close()
html2, err := f.OpenFile(it.URL())
if err != nil {
t.Errorf("OpenFile(%v) return an error: %v", it.URL(), err)
return
}
defer html2.Close()
buff1, err := ioutil.ReadAll(html1)
if err != nil {
t.Errorf("Error reading the opened file: %v", err)
return
}
buff2, _ := ioutil.ReadAll(html2)
if !bytes.Equal(buff1, buff2) {
t.Errorf("The files on epub and spine iterator are not equal")
return
}
}