diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-24 12:26:23 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-24 12:26:23 +0200 |
| commit | ed34fd574b4fc2e0a52c655ececddd1be29b271e (patch) | |
| tree | 8980a2b86ec279289abcabe3a691fa8a2a925765 /internal/bible | |
| parent | a26fed000ad9f292618f9cecfd2b505dddfd004a (diff) | |
| download | lectio-ed34fd574b4fc2e0a52c655ececddd1be29b271e.tar.gz lectio-ed34fd574b4fc2e0a52c655ececddd1be29b271e.zip | |
reader: lectio-ui --reader fuzzy book picker + chapter reader over the corpora; v0.8.0
Diffstat (limited to 'internal/bible')
| -rw-r--r-- | internal/bible/bible.go | 13 | ||||
| -rw-r--r-- | internal/bible/bible_test.go | 16 |
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) + } +} |
