aboutsummaryrefslogtreecommitdiff
path: root/internal/bible/booktable_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 11:29:57 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 11:29:57 +0200
commita26fed000ad9f292618f9cecfd2b505dddfd004a (patch)
tree3b6001cc5a20c3451677773159553aa134d4a6c9 /internal/bible/booktable_test.go
parente50b003d84b091b60c8028468edc633f04e39731 (diff)
downloadlectio-a26fed000ad9f292618f9cecfd2b505dddfd004a.tar.gz
lectio-a26fed000ad9f292618f9cecfd2b505dddfd004a.zip
books: language-scoped --ref/--list via customizable books.toml + sigla_style config; v0.7.0
Diffstat (limited to 'internal/bible/booktable_test.go')
-rw-r--r--internal/bible/booktable_test.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/internal/bible/booktable_test.go b/internal/bible/booktable_test.go
new file mode 100644
index 0000000..ededad3
--- /dev/null
+++ b/internal/bible/booktable_test.go
@@ -0,0 +1,88 @@
+package bible
+
+import (
+ "testing"
+)
+
+func TestBookTableDefaults(t *testing.T) {
+ tbl, err := LoadBookTable(nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, d := range []string{"en", "pl"} {
+ if got := len(tbl.Books(d)); got != 73 {
+ t.Errorf("Books(%q) len=%d want 73", d, got)
+ }
+ }
+ en := tbl.Books("en")
+ if en[0].Canonical != "Genesis" || en[len(en)-1].Canonical != "Revelation" {
+ t.Errorf("en order: first=%q last=%q", en[0].Canonical, en[len(en)-1].Canonical)
+ }
+ // John display: en shortcut "Jn"/name "John"; pl shortcut "J"/name "Jana".
+ find := func(bs []BookInfo, canon string) BookInfo {
+ for _, b := range bs {
+ if b.Canonical == canon {
+ return b
+ }
+ }
+ return BookInfo{}
+ }
+ if b := find(en, "John"); b.Shortcut != "Jn" || b.Name != "John" {
+ t.Errorf("en John = %+v", b)
+ }
+ if b := find(tbl.Books("pl"), "John"); b.Shortcut != "J" || b.Name != "Jana" {
+ t.Errorf("pl John = %+v", b)
+ }
+}
+
+func TestParseRefDialects(t *testing.T) {
+ tbl, _ := LoadBookTable(nil)
+ cases := []struct {
+ dialect, in, want string
+ ok bool
+ }{
+ {"en", "Jn 3:16", "John 3:16", true},
+ {"en", "Jn 5:15-17.20-22", "John 5:15-17,20-22", true},
+ {"en", "1 Cor 13:4-7", "1 Corinthians 13:4-7", true},
+ {"pl", "J 3,16", "John 3:16", true},
+ {"pl", "J 3, 16", "John 3:16", true},
+ {"pl", "J 6,6", "John 6:6", true},
+ {"pl", "J 5,15-17. 20-22", "John 5:15-17,20-22", true},
+ {"pl", "1 Kor 13,4-7", "1 Corinthians 13:4-7", true},
+ {"pl", "Łk 1,46-55", "Luke 1:46-55", true},
+ // dialect scoping: Polish abbrev/sep must fail in en, English in pl.
+ {"en", "Łk 3:16", "", false},
+ {"pl", "Lk 3,16", "", false},
+ {"en", "Zzz 1:1", "", false},
+ {"en", "John", "", false}, // no chapter:verse
+ }
+ for _, c := range cases {
+ got, ok := tbl.ParseRef(c.dialect, c.in)
+ if ok != c.ok || got != c.want {
+ t.Errorf("ParseRef(%q,%q)=%q,%v want %q,%v", c.dialect, c.in, got, ok, c.want, c.ok)
+ }
+ }
+}
+
+func TestBookTableMergeAndMalformed(t *testing.T) {
+ // User adds an alias "Jhn" to English John; other books stay default.
+ user := []byte("[en]\nJohn = [\"Jn\", \"Jhn\", \"John\"]\n")
+ tbl, err := LoadBookTable(user)
+ if err != nil {
+ t.Fatalf("merge err: %v", err)
+ }
+ if got, ok := tbl.ParseRef("en", "Jhn 3:16"); !ok || got != "John 3:16" {
+ t.Errorf("merged alias: got %q,%v", got, ok)
+ }
+ if got, ok := tbl.ParseRef("en", "Gen 1:1"); !ok || got != "Genesis 1:1" {
+ t.Errorf("unlisted book lost after merge: %q,%v", got, ok)
+ }
+ // Malformed user TOML -> non-nil error but a usable defaults table.
+ tbl2, err := LoadBookTable([]byte("this is not [valid toml"))
+ if err == nil {
+ t.Error("expected error for malformed user toml")
+ }
+ if got, ok := tbl2.ParseRef("en", "Jn 3:16"); !ok || got != "John 3:16" {
+ t.Errorf("defaults unusable after malformed user toml: %q,%v", got, ok)
+ }
+}