summaryrefslogtreecommitdiff
path: root/internal/bible
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-29 11:46:17 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-29 11:46:17 +0200
commit8ddd910dd545c45a7227da87ca125758b4a0e2cb (patch)
treeb652bb239c622e2f8806a443db21a0b0bf8c8962 /internal/bible
parent79f9ae051c1e8f179e2e7c17f590c105eb18bef1 (diff)
downloadlectio-8ddd910dd545c45a7227da87ca125758b4a0e2cb.tar.gz
lectio-8ddd910dd545c45a7227da87ca125758b4a0e2cb.zip
test(bible): skip corpus-dependent tests when optional corpora aren't embedded
Since 51c0f4e split the corpora (only vul embedded by default; wuj/drb/grb behind -tags fullbible), `go test ./...` on the default build was red across six packages -- every failure was a test assuming an optional corpus is present. Guard those assertions with a skip keyed on bible.Meta(code), so they run under -tags fullbible and skip -- not fail -- on the default vul-only build. Mixed tests are split into subtests so the always-embedded vul assertions and pure logic (pl->vul fallback, explicit passthrough, bt-rejection, i18n labels) keep running on both builds. Test-only change; no product code or corpora touched. - internal/bible: TestVerses, TestLookup, TestCorpusBooks, TestChapters, TestGrbNoApparatusMarkers, TestCrossChapterRange* (requireCorpus helper). - internal/cli, config, render, tui, web: the same pattern for their corpus-dependent tests. - Fixes an index-out-of-range panic in internal/tui's reader tests that was aborting the package binary and masking 3 further corpus-absence failures (TestReaderBookmarkFlow, TestReaderChapterJump, TestReaderRemembersPlace). Verified: `go test ./...` and `go test -tags fullbible ./...` both green (0 FAIL); guards active only on the default build (29 skips vs 1 unrelated pre-existing); gofmt and go vet clean.
Diffstat (limited to 'internal/bible')
-rw-r--r--internal/bible/bible_test.go36
-rw-r--r--internal/bible/crosschapter_test.go2
-rw-r--r--internal/bible/ref_test.go37
3 files changed, 51 insertions, 24 deletions
diff --git a/internal/bible/bible_test.go b/internal/bible/bible_test.go
index 71a2c89..e3c18c8 100644
--- a/internal/bible/bible_test.go
+++ b/internal/bible/bible_test.go
@@ -14,24 +14,40 @@ func TestVerses(t *testing.T) {
{"wuj", "Wisdom", 3, 1, "A dusze sprawiedliwych"}, // deuterocanonical
}
for _, c := range cases {
- vs := Verses(c.version, c.book, c.chap)
- var got string
- for _, v := range vs {
- if v.Verse == c.verse {
- got = v.Text
+ t.Run(c.version+"/"+c.book, func(t *testing.T) {
+ requireCorpus(t, c.version)
+ vs := Verses(c.version, c.book, c.chap)
+ var got string
+ for _, v := range vs {
+ if v.Verse == c.verse {
+ got = v.Text
+ }
}
- }
- if !hasPrefix(got, c.wantPrefix) {
- t.Errorf("%s %s %d:%d = %q want prefix %q", c.version, c.book, c.chap, c.verse, got, c.wantPrefix)
- }
+ if !hasPrefix(got, c.wantPrefix) {
+ t.Errorf("%s %s %d:%d = %q want prefix %q", c.version, c.book, c.chap, c.verse, got, c.wantPrefix)
+ }
+ })
}
}
func hasPrefix(s, p string) bool { return len(s) >= len(p) && s[:len(p)] == p }
+// requireCorpus skips the test when corpus `code` is not available. The optional
+// corpora (wuj, drb, grb) are compiled in only with `-tags fullbible` (or dropped
+// into the user corpora dir); without that, only vul is embedded. Keying on
+// Meta() means these tests run fully under fullbible and skip -- not fail --
+// under the default build, so `go test ./...` stays honest either way.
+func requireCorpus(t *testing.T, code string) {
+ t.Helper()
+ if _, ok := Meta(code); !ok {
+ t.Skipf("corpus %q not embedded; build with -tags fullbible", code)
+ }
+}
+
// TestGrbNoApparatusMarkers guards the corpus fix: the SBLGNT apparatus sigla
// (U+2E00–U+2E0D) were stripped from the Greek text.
func TestGrbNoApparatusMarkers(t *testing.T) {
+ requireCorpus(t, "grb")
for _, v := range Verses("grb", "Luke", 16) {
for _, r := range v.Text {
if r >= 0x2E00 && r <= 0x2E0D {
@@ -53,6 +69,7 @@ func TestVul2Kings(t *testing.T) {
}
func TestCorpusBooks(t *testing.T) {
+ requireCorpus(t, "wuj")
books := CorpusBooks("wuj")
if len(books) == 0 {
t.Fatal("wuj corpus has no books")
@@ -72,6 +89,7 @@ func TestCorpusBooks(t *testing.T) {
}
func TestChapters(t *testing.T) {
+ requireCorpus(t, "wuj")
ch := Chapters("wuj", "John")
if len(ch) == 0 || ch[0] != 1 {
t.Fatalf("John chapters = %v", ch)
diff --git a/internal/bible/crosschapter_test.go b/internal/bible/crosschapter_test.go
index 7fb61eb..20074fb 100644
--- a/internal/bible/crosschapter_test.go
+++ b/internal/bible/crosschapter_test.go
@@ -8,6 +8,7 @@ import "testing"
// both chapters via Lookup, and format back to the clean "N:M-P:Q" form via
// FormatRef (no sentinel, no mangled chapter).
func TestCrossChapterRanges(t *testing.T) {
+ requireCorpus(t, "drb")
tbl, err := LoadBookTable(nil)
if err != nil {
t.Fatal(err)
@@ -90,6 +91,7 @@ func TestCrossChapterRanges(t *testing.T) {
// "Malachi 1:14-2:2,8-10" (Ordinary Sunday 31 A): a cross-chapter range
// followed by a plain verse group in the new (second) chapter.
func TestCrossChapterRangeWithTrailingGroup(t *testing.T) {
+ requireCorpus(t, "drb")
tbl, err := LoadBookTable(nil)
if err != nil {
t.Fatal(err)
diff --git a/internal/bible/ref_test.go b/internal/bible/ref_test.go
index 9473123..0c81a40 100644
--- a/internal/bible/ref_test.go
+++ b/internal/bible/ref_test.go
@@ -14,22 +14,29 @@ func TestSplitRef(t *testing.T) {
}
func TestLookup(t *testing.T) {
- vs, missing := Lookup("wuj", "John 20:1,11-18")
- if len(missing) != 0 {
- t.Fatalf("missing = %v", missing)
- }
- if len(vs) == 0 || vs[0].Verse != 1 {
- t.Fatalf("first verse = %+v", vs)
- }
- last := vs[len(vs)-1]
- if last.Verse != 18 {
- t.Errorf("last verse = %d want 18", last.Verse)
- }
- // Deuterocanon now present in vul + drb (Clementine Vulgate / Douay-Rheims).
+ t.Run("wuj", func(t *testing.T) {
+ requireCorpus(t, "wuj")
+ vs, missing := Lookup("wuj", "John 20:1,11-18")
+ if len(missing) != 0 {
+ t.Fatalf("missing = %v", missing)
+ }
+ if len(vs) == 0 || vs[0].Verse != 1 {
+ t.Fatalf("first verse = %+v", vs)
+ }
+ last := vs[len(vs)-1]
+ if last.Verse != 18 {
+ t.Errorf("last verse = %d want 18", last.Verse)
+ }
+ })
+ // Deuterocanon in the always-embedded Clementine Vulgate.
if vs, m := Lookup("vul", "Wisdom 3:1"); len(m) != 0 || len(vs) == 0 {
t.Errorf("vul Wisdom 3:1: missing=%v verses=%d (deuterocanon should resolve)", m, len(vs))
}
- if vs, m := Lookup("drb", "Judith 13:22"); len(m) != 0 || len(vs) == 0 {
- t.Errorf("drb Judith 13:22: missing=%v verses=%d (deuterocanon should resolve)", m, len(vs))
- }
+ // Deuterocanon in Douay-Rheims (optional corpus).
+ t.Run("drb", func(t *testing.T) {
+ requireCorpus(t, "drb")
+ if vs, m := Lookup("drb", "Judith 13:22"); len(m) != 0 || len(vs) == 0 {
+ t.Errorf("drb Judith 13:22: missing=%v verses=%d (deuterocanon should resolve)", m, len(vs))
+ }
+ })
}