From b74e6e51ae86c01f12fb414c8c15c55f170ebe98 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Shelton" Date: Wed, 14 Oct 2026 18:54:44 -0600 Subject: [PATCH] Tests cleanup (partial). Additional formatting tests have been added, especially for cases where SkipLineBreaks is enabled (for inline quotes). --- internal/bible/types_test.go | 57 +++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/internal/bible/types_test.go b/internal/bible/types_test.go index 463d538..b37238c 100644 --- a/internal/bible/types_test.go +++ b/internal/bible/types_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "strings" "testing" "code.destrealm.net/zancarius/justusbot/internal/bible" @@ -16,6 +17,7 @@ const ( Jude5 string = `Although you are fully aware of this, I want to remind you that after Jesus had delivered His people out of the land of Egypt, He destroyed those who did not believe.` Jude6 string = `And the angels who did not stay within their own domain but abandoned their proper dwelling—these He has kept in eternal chains under darkness, bound for judgment on that great day.` Obadiah5 string = `“If thieves came to you, if robbers by night—oh, how you will be ruined—would they not steal only what they wanted? If grape gatherers came to you, would they not leave some gleanings?` + Psa32_4 string = `For day and night Your hand was heavy upon me; my strength was drained as in the summer heat. Selah` ) func loadScripture(s string) (*bible.Chapter, error) { @@ -90,6 +92,22 @@ func Test_ChapterJSON(t *testing.T) { if vv.String() != Gen1_1_2 { t.Error("Genesis 1:1-2 did not match as expected:", vv.String()) } + + testJSON = &bytes.Buffer{} + testJSON.WriteString(`{"numberOfVerses": 11, "chapter": {"number": 32, "content": [{"type": "verse", "number": 4, "content": [{"text": "For day and night", "poem": 1}, {"text": "Your hand was heavy upon me;", "poem": 2}, {"text": "my strength was drained", "poem": 1}, {"noteId": 72}, {"text": "as in the summer heat.", "poem": 2}, "Selah"]}]}}`) + + c = &bible.Chapter{} + if err := json.Unmarshal(testJSON.Bytes(), c); err != nil { + t.Fatal(err) + } + + vv = c.FilterVerses(4, 4) + vv.SkipLineBreaks = true + if vv.String() != Psa32_4 { + t.Error("Psalm 32:4 did not match as expected:", vv.String()) + t.Error(" should be ->", Psa32_4) + } + } func Test_VerseFilter(t *testing.T) { @@ -117,9 +135,23 @@ func Test_Translations(t *testing.T) { if err != nil { t.Fatal(err) } + if tn.Default != "bsb" { + t.Errorf(`default "%s" but expected "bsb"`, tn.Default) + } bible, err := tn.OpenBible("bsb") - t.Error(bible, bible.Metadata, err) + if err != nil { + t.Fatal(err) + } + if !bible.Enabled { + t.Error(`"bsb" disabled state is "true"`) + } + if bible.ID != "bsb" { + t.Errorf(`Bible ID should be "bsb" but is "%s"`, bible.ID) + } + if bible.Title != "Berean Standard Bible" { + t.Errorf(`Bible title: unexpected: "%s"`, bible.Title) + } } func Test_Bible(t *testing.T) { @@ -143,18 +175,35 @@ func Test_Bible(t *testing.T) { t.Fatal(err) } - t.Error(book) + if book.Title != "Genesis" { + t.Errorf(`expected "Genesis" but received: %s"`, book.Title) + } + if book.ID != "GEN" { + t.Errorf(`expected ID "GEN" but received: %s"`, book.ID) + } ch, err := book.OpenChapter(1) if err != nil { t.Fatal(err) } - t.Error(ch) + if ch.Book.Title != "Genesis" { + t.Errorf(`chapter backreference Book.Title should be "Genesis" but received: %s`, ch.Book.Title) + } + if ch.ChapterDecl.Number != 1 { + t.Errorf(`chapter declaration (ChapterDecl.Number) should return 1, received: %d`, ch.ChapterDecl.Number) + } + verses := ch.FilterVerses(1, 2) verses.IncludeVerseNum = false verses.SkipLineBreaks = true - t.Error(verses.String()) + + if strings.Compare(verses.String(), Gen1_1_2) != 0 { + t.Error("Genesis 1:1-2 unexpected for translation BSB. Received:") + t.Error(" ", verses.String(), "<") + t.Error("Expected:") + t.Error(" ", Gen1_1_2, "<") + } } func Test_Bible_Reference(t *testing.T) {