-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnavigation_test.go
101 lines (90 loc) · 2.54 KB
/
navigation_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
// 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"
const (
firstTitle = "A DOG'S TALE, By Mark Twain"
firstURL = "@public@vhost@g@gutenberg@html@files@3174@[email protected]#pgepubid00000"
childTitle = "Frontpiece"
)
func TestIterator(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, err := f.Navigation()
if err != nil {
t.Errorf("epub.Navigation() return an error: %v", err)
}
if it.HasChildren() {
t.Errorf("it.HasChildren() not behaving as expected")
}
if it.HasParents() {
t.Errorf("it.HasParents() not behaving as expected")
}
if !it.IsFirst() {
t.Errorf("it.IsFirst() not behaving as expected")
}
if it.IsLast() {
t.Errorf("it.IsLast() not behaving as expected")
}
}
func TestTitle(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Navigation()
if it.Title() != firstTitle {
t.Errorf("it.Title() return: %v when was expected: %v", it.Title(), firstTitle)
}
}
func TestURL(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Navigation()
if it.URL() != firstURL {
t.Errorf("it.URL() return: %v when was expected: %v", it.URL(), firstURL)
}
}
func TestDepth(t *testing.T) {
f, _ := Open(bookPath)
defer f.Close()
it, _ := f.Navigation()
if it.In() == nil {
t.Errorf("it.In() din't return an error whithout having children")
}
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() return an error: %v", err)
}
if !it.IsLast() {
t.Errorf("it.IsLast() not behaving as expected")
}
if err := it.In(); err != nil {
t.Errorf("it.In() return an error: %v", err)
}
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.Previous(); err != nil {
t.Errorf("it.Previous() return an error: %v", err)
}
if it.Title() != childTitle {
t.Errorf("it.Title() return: %v when was expected: %v", it.Title(), childTitle)
}
if err := it.Out(); err != nil {
t.Errorf("it.Out() return an error: %v", err)
}
if err := it.Previous(); err != nil {
t.Errorf("it.Next() return an error: %v", err)
}
if err := it.Previous(); err != nil {
t.Errorf("it.Next() return an error: %v", err)
}
if it.Title() != firstTitle {
t.Errorf("it.Title() return: %v when was expected: %v", it.Title(), firstTitle)
}
}