From 22bfec8fc13a20a8d95a4609b4a02bb48acede5a Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 24 Jul 2026 13:35:24 +0200 Subject: citation: render --citation/--week gospel ref in the configured sigla dialect (bible.FormatRef); v0.11.0 --- internal/bible/booktable_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'internal/bible/booktable_test.go') diff --git a/internal/bible/booktable_test.go b/internal/bible/booktable_test.go index ededad3..2a57d80 100644 --- a/internal/bible/booktable_test.go +++ b/internal/bible/booktable_test.go @@ -64,6 +64,37 @@ func TestParseRefDialects(t *testing.T) { } } +func TestFormatRef(t *testing.T) { + tbl, _ := LoadBookTable(nil) + cases := []struct { + dialect, canonical, want string + }{ + {"en", "John 20:1,11-18", "Jn 20:1,11-18"}, + {"pl", "John 20:1,11-18", "J 20, 1. 11-18"}, + {"en", "Matthew 13:18-23", "Matt 13:18-23"}, + {"pl", "Matthew 13:18-23", "Mt 13, 18-23"}, + {"en", "Luke 16:1-9", "Lk 16:1-9"}, + // Round-trip: ParseRef then FormatRef in the same dialect is stable. + } + for _, c := range cases { + if got := tbl.FormatRef(c.dialect, c.canonical); got != c.want { + t.Errorf("FormatRef(%q,%q)=%q want %q", c.dialect, c.canonical, got, c.want) + } + } + // Unparseable / unknown book -> unchanged (safe fallback). + if got := tbl.FormatRef("en", "not a ref"); got != "not a ref" { + t.Errorf("unparseable ref should be unchanged, got %q", got) + } + // Round-trip through both dialects. + canon, ok := tbl.ParseRef("pl", "J 20, 1. 11-18") + if !ok || canon != "John 20:1,11-18" { + t.Fatalf("ParseRef round-trip canon=%q ok=%v", canon, ok) + } + if got := tbl.FormatRef("pl", canon); got != "J 20, 1. 11-18" { + t.Errorf("pl round-trip = %q", got) + } +} + 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") -- cgit v1.3