-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference_test.go
135 lines (112 loc) · 3.58 KB
/
reference_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
128
129
130
131
132
133
134
135
package gobible
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseReference(t *testing.T) {
b := NewGoBible()
b.LoadFormat("data/WEB.xml", "osis")
// Test a valid reference
r, err := b.ParseReference("Genesis 1:1-3")
assert.Nil(t, err)
assert.Equal(t, 3, len(r))
assert.Equal(t, "Genesis", r[2].Book)
assert.Equal(t, 1, r[2].Chapter)
assert.Equal(t, 3, r[2].Verse)
// Test a valid reference
r, err = b.ParseReference("Genesis 1:1-2:3")
assert.Nil(t, err)
assert.Equal(t, 34, len(r))
assert.Equal(t, "Genesis", r[33].Book)
assert.Equal(t, 2, r[33].Chapter)
assert.Equal(t, 3, r[33].Verse)
assert.Equal(t, 1, r[4].Chapter)
assert.Equal(t, 5, r[4].Verse)
// Test a valid reference
r, err = b.ParseReference("1 Corinthians 1:2")
assert.Nil(t, err)
assert.Equal(t, 1, len(r))
assert.Equal(t, "1 Corinthians", r[0].Book)
assert.Equal(t, 1, r[0].Chapter)
assert.Equal(t, 2, r[0].Verse)
}
func TestParseReferenceVersion(t *testing.T) {
b := NewGoBible()
_, err := b.ParseReference("Genesis 1:1")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "no bibles loaded")
}
err = b.LoadFormat("data/WEB.xml", "osis")
assert.Nil(t, err)
err = b.Load("data/KJV.json")
assert.Nil(t, err)
// Test a valid reference
r, err := b.ParseReference("Genesis 1:1")
assert.Nil(t, err)
assert.Equal(t, 1, len(r))
assert.Equal(t, "Genesis", r[0].Book)
assert.Equal(t, 1, r[0].Chapter)
assert.Equal(t, 1, r[0].Verse)
assert.Equal(t, "WEB", r[0].Translation)
assert.Equal(t, "In the beginning God created the heavens and the earth.", r[0].VerseRef.Text)
// Test a valid reference with a translation
r, err = b.ParseReference("Genesis 1:1 KJV")
assert.Nil(t, err)
assert.Equal(t, 1, len(r))
assert.Equal(t, "Genesis", r[0].Book)
assert.Equal(t, 1, r[0].Chapter)
assert.Equal(t, 1, r[0].Verse)
assert.Equal(t, "KJV", r[0].Translation)
assert.Equal(t, "In the beginning God created the heaven and the earth.", r[0].VerseRef.Text)
// Test a reference with an invalid translation
// This should just return the WEB
r, err = b.ParseReference("Genesis 1:1 ASV")
assert.Nil(t, err)
assert.Equal(t, 1, len(r))
assert.Equal(t, "Genesis", r[0].Book)
assert.Equal(t, 1, r[0].Chapter)
assert.Equal(t, 1, r[0].Verse)
assert.Equal(t, "WEB", r[0].Translation)
s := r[0].String()
assert.Equal(t, "In the beginning God created the heavens and the earth. - Genesis 1:1 WEB", s)
}
func TestParseReferenceBad(t *testing.T) {
b := NewGoBible()
err := b.Load("data/KJV.json")
assert.Nil(t, err)
// Test a bad reference
_, err = b.ParseReference("Genesis 1:1:1")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid chapter format")
}
// Test a bad reference
_, err = b.ParseReference("Genesis")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid reference format")
}
// Test a bad reference
_, err = b.ParseReference("Genesis 1:B")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid syntax")
}
// Test a bad reference
_, err = b.ParseReference("Genesis A:2")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid chapter format")
}
// Test a bad reference
_, err = b.ParseReference("Genesis 1:2-")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid syntax")
}
// Test a bad reference
_, err = b.ParseReference("Genesis 3.5-2.3")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid chapter format")
}
// Test a bad reference
_, err = b.ParseReference("Genesis B:B")
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid chapter format")
}
}