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 }