From ed7717fef53db3b3aa5593fbb2649313e75a0f31 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 24 Jul 2026 15:25:50 +0200 Subject: cli: --rand/--rand-v (random verse) + --rand-ch (random chapter) from the corpus, using the config default version; v0.16.0 --- internal/bible/bible.go | 12 ++++++++++++ internal/bible/bible_test.go | 19 +++++++++++++++++++ internal/bible/booktable.go | 9 +++++++++ 3 files changed, 40 insertions(+) (limited to 'internal/bible') diff --git a/internal/bible/bible.go b/internal/bible/bible.go index 312daeb..1603188 100644 --- a/internal/bible/bible.go +++ b/internal/bible/bible.go @@ -71,3 +71,15 @@ func Chapters(version, book string) []int { sort.Ints(chaps) return chaps } + +// CorpusBooks returns the book names present in a version's corpus, sorted +// (empty for a version with no embedded corpus, e.g. "bt"). +func CorpusBooks(version string) []string { + c := load(version) + books := make([]string, 0, len(c.books)) + for b := range c.books { + books = append(books, b) + } + sort.Strings(books) + return books +} diff --git a/internal/bible/bible_test.go b/internal/bible/bible_test.go index 804b8c4..71a2c89 100644 --- a/internal/bible/bible_test.go +++ b/internal/bible/bible_test.go @@ -52,6 +52,25 @@ func TestVul2Kings(t *testing.T) { } } +func TestCorpusBooks(t *testing.T) { + books := CorpusBooks("wuj") + if len(books) == 0 { + t.Fatal("wuj corpus has no books") + } + found := false + for _, b := range books { + if b == "John" { + found = true + } + } + if !found { + t.Errorf("wuj CorpusBooks missing John") + } + if got := CorpusBooks("bt"); len(got) != 0 { + t.Errorf("bt has no corpus, got %d books", len(got)) + } +} + func TestChapters(t *testing.T) { ch := Chapters("wuj", "John") if len(ch) == 0 || ch[0] != 1 { diff --git a/internal/bible/booktable.go b/internal/bible/booktable.go index 9ec95be..ac7ea95 100644 --- a/internal/bible/booktable.go +++ b/internal/bible/booktable.go @@ -154,6 +154,15 @@ func (t *BookTable) shortcut(dialect, canonical string) string { return "" } +// Abbrev returns the dialect's primary abbreviation for a canonical book, +// falling back to the canonical name when the dialect has no entry. +func (t *BookTable) Abbrev(dialect, canonical string) string { + if a := t.shortcut(dialect, canonical); a != "" { + return a + } + return canonical +} + // FormatRef renders a canonical English reference ("John 20:1,11-18") in the // dialect's sigla: the dialect's book shortcut plus its number style -- English // "Jn 20:1,11-18" (colon chapter:verse, comma groups); Polish "J 20, 1. 11-18" -- cgit v1.3