summaryrefslogtreecommitdiff
path: root/internal/tui/reader_test.go
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/tui/reader_test.go
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/tui/reader_test.go')
-rw-r--r--internal/tui/reader_test.go48
1 files changed, 42 insertions, 6 deletions
diff --git a/internal/tui/reader_test.go b/internal/tui/reader_test.go
index 9d324ba..7bce759 100644
--- a/internal/tui/reader_test.go
+++ b/internal/tui/reader_test.go
@@ -30,6 +30,18 @@ func key(m ReaderModel, k tea.KeyMsg) ReaderModel {
return nm.(ReaderModel)
}
+// requireCorpus skips the test when corpus `code` is not embedded in this
+// build. The optional corpora (wuj, drb, grb) compile in only with
+// `-tags fullbible` (or when dropped into the user corpora dir); mirrors the
+// helper in internal/bible so these tests run under fullbible and skip -- not
+// fail -- on the default vul-only build.
+func requireCorpus(t *testing.T, code string) {
+ t.Helper()
+ if _, ok := bible.Meta(code); !ok {
+ t.Skipf("corpus %q not embedded; build with -tags fullbible", code)
+ }
+}
+
func runes(s string) tea.KeyMsg { return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(s)} }
func win(m ReaderModel, w, h int) ReaderModel {
@@ -55,6 +67,8 @@ func TestReaderFilterAndOpen(t *testing.T) {
nm, _ := m.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
m = nm.(ReaderModel)
m = key(m, runes("jn"))
+ // Fuzzy filtering and entering read mode come from the book table and the
+ // model's state machine -- independent of any corpus being embedded.
if len(m.matches) == 0 || m.books[m.matches[0]].Canonical != "John" {
t.Fatalf("filter 'jn' top = %v", m.books[m.matches[m.pickSel]])
}
@@ -62,15 +76,25 @@ func TestReaderFilterAndOpen(t *testing.T) {
if m.mode != modeRead {
t.Fatalf("did not enter read mode")
}
- if m.books[m.bookIdx].Canonical != "John" || len(m.verses) == 0 {
- t.Errorf("opened book=%q verses=%d", m.books[m.bookIdx].Canonical, len(m.verses))
- }
- if !strings.Contains(m.View(), "1") { // chapter 1 header
- t.Errorf("read view missing chapter:\n%s", m.View())
- }
+ // The reader's first version is wuj (see enReader): its verses and chapter
+ // header need the optional wuj corpus embedded.
+ t.Run("wuj verses", func(t *testing.T) {
+ requireCorpus(t, "wuj")
+ if m.books[m.bookIdx].Canonical != "John" || len(m.verses) == 0 {
+ t.Errorf("opened book=%q verses=%d", m.books[m.bookIdx].Canonical, len(m.verses))
+ }
+ if !strings.Contains(m.View(), "1") { // chapter 1 header
+ t.Errorf("read view missing chapter:\n%s", m.View())
+ }
+ })
}
func TestReaderChapterAndVersion(t *testing.T) {
+ // Whole-test guard: the reader's first version is wuj (see enReader), so the
+ // very first read-mode step below indexes m.chapters[m.chapPos] -- which
+ // panics on an empty chapter list when wuj is not embedded. The chapter
+ // stepping and version cycling that follow are all a wuj reading session.
+ requireCorpus(t, "wuj")
m := enReader(t)
nm, _ := m.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
m = nm.(ReaderModel)
@@ -107,6 +131,10 @@ func TestReaderFuzzyScore(t *testing.T) {
}
func TestReaderBookmarkFlow(t *testing.T) {
+ // The whole flow reads and bookmarks verses of John from wuj (the reader's
+ // first version); "m" only opens the verse picker when len(verses)>0, so
+ // the optional wuj corpus must be embedded.
+ requireCorpus(t, "wuj")
m := enReader(t)
m = win(m, 80, 24)
m = key(m, runes("jn"))
@@ -166,6 +194,10 @@ func TestReaderBookmarkFlow(t *testing.T) {
}
func TestReaderChapterJump(t *testing.T) {
+ // Reads John from wuj (the reader's first version); "c" only opens the
+ // chapter-jump prompt when the book has >1 chapter loaded, so the optional
+ // wuj corpus must be embedded.
+ requireCorpus(t, "wuj")
m := enReader(t)
m = win(m, 80, 24)
m = key(m, runes("jn"))
@@ -224,6 +256,10 @@ func TestReaderChapterJump(t *testing.T) {
}
func TestReaderRemembersPlace(t *testing.T) {
+ // Persisting/restoring a reading position needs real verses (savePlace
+ // no-ops when len(verses)==0); the reader's first version is wuj, so the
+ // optional wuj corpus must be embedded.
+ requireCorpus(t, "wuj")
dir := t.TempDir()
t.Setenv("XDG_DATA_HOME", dir)
tbl, _ := bible.LoadBookTable(nil)