aboutsummaryrefslogtreecommitdiff
path: root/internal/bible
diff options
context:
space:
mode:
Diffstat (limited to 'internal/bible')
-rw-r--r--internal/bible/bible.go13
-rw-r--r--internal/bible/bible_test.go16
2 files changed, 29 insertions, 0 deletions
diff --git a/internal/bible/bible.go b/internal/bible/bible.go
index 0254ceb..312daeb 100644
--- a/internal/bible/bible.go
+++ b/internal/bible/bible.go
@@ -2,6 +2,7 @@ package bible
import (
"embed"
+ "sort"
"strconv"
"strings"
"sync"
@@ -58,3 +59,15 @@ func load(version string) *corpus {
func Verses(version, book string, chap int) []Verse {
return load(version).books[book][chap]
}
+
+// Chapters returns the chapter numbers present for a book in a version, sorted
+// ascending (empty if the version has no such book).
+func Chapters(version, book string) []int {
+ chapMap := load(version).books[book]
+ chaps := make([]int, 0, len(chapMap))
+ for ch := range chapMap {
+ chaps = append(chaps, ch)
+ }
+ sort.Ints(chaps)
+ return chaps
+}
diff --git a/internal/bible/bible_test.go b/internal/bible/bible_test.go
index efd22d6..36223a3 100644
--- a/internal/bible/bible_test.go
+++ b/internal/bible/bible_test.go
@@ -28,3 +28,19 @@ func TestVerses(t *testing.T) {
}
func hasPrefix(s, p string) bool { return len(s) >= len(p) && s[:len(p)] == p }
+
+func TestChapters(t *testing.T) {
+ ch := Chapters("wuj", "John")
+ if len(ch) == 0 || ch[0] != 1 {
+ t.Fatalf("John chapters = %v", ch)
+ }
+ for i := 1; i < len(ch); i++ {
+ if ch[i] <= ch[i-1] {
+ t.Errorf("chapters not sorted ascending: %v", ch)
+ break
+ }
+ }
+ if got := Chapters("wuj", "Nonesuch"); len(got) != 0 {
+ t.Errorf("missing book chapters = %v want empty", got)
+ }
+}