aboutsummaryrefslogtreecommitdiff
path: root/internal/bible/bible_test.go
blob: 36223a3c98e9dcdf323d26090685dc5d35ee9fe8 (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
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 {
		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 }

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)
	}
}