-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgobible_test.go
102 lines (83 loc) · 2.44 KB
/
gobible_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
package gobible
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoad(t *testing.T) {
g := NewGoBible()
err := g.Load("data/KJV.json")
assert.Nil(t, err)
}
func TestLoadFormat(t *testing.T) {
g := NewGoBible()
err := g.LoadFormat("data/WEB.xml", "osis")
assert.Nil(t, err)
// Load a fake format
err = g.LoadFormat("data/WEB.xml", "random")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid format")
}
// Try loading OSIS as gobible
err = g.LoadFormat("data/WEB.xml", "gobible")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid character")
}
}
func TestLoadString(t *testing.T) {
g := NewGoBible()
err := g.LoadString(`{"version": {"name": "Legacy Standard Bible", "abbrev": "LSB"}, "books": []}`)
assert.Nil(t, err)
}
func TestGetBibleJSON(t *testing.T) {
g := NewGoBible()
err := g.LoadFormat("data/WEB.xml", "osis")
assert.Nil(t, err)
// Convert WEB to a string
bJSON, err := g.GetBibleJSON("WEB")
assert.Nil(t, err)
assert.NotEmpty(t, bJSON)
// Load the string back into gobible
// This should generate an "already loaded" error
err = g.LoadString(bJSON)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "already loaded")
}
// Unload WEB so we can try again
err = g.Unload("WEB")
assert.Nil(t, err)
// Unload WEB against to cover the error case
err = g.Unload("WEB")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "not found")
}
// Load the string back into gobible
err = g.LoadString(bJSON)
assert.Nil(t, err)
}
func TestDoubleLoad(t *testing.T) {
b := NewGoBible()
err := b.Load("data/KJV.json")
assert.Nil(t, err)
// load it again for the error case
err = b.Load("data/KJV.json")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "already loaded")
}
}
func TestJSONErrors(t *testing.T) {
b := NewGoBible()
err := b.LoadString(`{"version": {"name": "Legacy Standard Bible", "abbrev": "LSB"}, "books": []`)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "unexpected end of JSON input")
}
err = b.LoadString(`{"version": {"name": "Legacy Standard Bible"}, "books": []}`)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "bible abbreviation not found in JSON")
}
err = b.LoadString(`{"version": {"name": "Legacy Standard Bible", "abbrev": "LSB"}, "books": []}`)
assert.Nil(t, err)
_, err = b.GetBibleJSON("WEB")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "bible not found")
}
}