summaryrefslogtreecommitdiff
path: root/internal/bible/bible_test.go
blob: e3c18c8736186180122bb89fc0057d674bb1df8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package bible

import "testing"

func TestVerses(t *testing.T) {
	cases := []struct {
		version, book string
		chap, verse   int
		wantPrefix    string
	}{
		{"wuj", "Genesis", 1, 1, "Na początku stworzył Bóg"},
		{"vul", "Genesis", 1, 1, "In principio creavit Deus"},
		{"drb", "John", 20, 1, "AND on the first day of the week"},
		{"wuj", "Wisdom", 3, 1, "A dusze sprawiedliwych"}, // deuterocanonical
	}
	for _, c := range cases {
		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)
			}
		})
	}
}

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 {
				t.Fatalf("grb Luke 16:%d still has apparatus marker U+%04X: %q", v.Verse, r, v.Text)
			}
		}
	}
}

// TestVul2Kings guards the corpus fix: 2 Kings was mislabeled "2 King" in the
// Vulgate TSV, so bible.Verses("vul","2 Kings",...) returned nothing.
func TestVul2Kings(t *testing.T) {
	if got := Verses("vul", "2 Kings", 1); len(got) == 0 {
		t.Error("vul 2 Kings ch.1 has no verses (corpus mislabel regression)")
	}
	if got := Verses("vul", "2 King", 1); len(got) != 0 {
		t.Error(`vul should no longer key the book as "2 King"`)
	}
}

func TestCorpusBooks(t *testing.T) {
	requireCorpus(t, "wuj")
	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) {
	requireCorpus(t, "wuj")
	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)
	}
}