aboutsummaryrefslogtreecommitdiff
path: root/internal/bible/validate_test.go
blob: a3ed622b28cb1bd6e4a336ec6470bcda9a0c3d0a (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
package bible

import (
	"strings"
	"testing"
)

func TestCheckCorpus(t *testing.T) {
	SetUserCorporaDir("testdata/corpora")
	t.Cleanup(func() { SetUserCorporaDir("") })

	if r := CheckCorpus("good"); !r.OK() {
		t.Fatalf("good corpus flagged: %v", r.Errors)
	}
	if r := CheckCorpus("badbook"); r.OK() {
		t.Fatal("unknown book not caught")
	}
	if r := CheckCorpus("gap"); len(r.Warnings) == 0 {
		t.Fatal("verse gap not warned")
	}
	if r := CheckCorpus("nosidecar"); r.OK() {
		t.Fatal("missing sidecar not caught")
	}
	if r := CheckCorpus("badsystem"); r.OK() {
		t.Fatal("bad psalm_system not caught")
	}
	// A verse present but a stub next to the Vulgate's (Genesis 1:1 = "x") is a
	// warning, never an error -- the count-based checks can't see it.
	if r := CheckCorpus("stub"); !hasWarning(r.Warnings, "suspiciously short") {
		t.Fatalf("stub verse not warned; warnings: %v", r.Warnings)
	}
}

func hasWarning(ws []string, substr string) bool {
	for _, w := range ws {
		if strings.Contains(w, substr) {
			return true
		}
	}
	return false
}