aboutsummaryrefslogtreecommitdiff
path: root/internal/readings/readings_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-28 11:57:45 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-28 11:57:45 +0200
commitfeede51697be870ae183a95b513ef64f031dbd0f (patch)
tree6700a80f996d2bba204c0452db2d2bbc16bff619 /internal/readings/readings_test.go
parent626f2275438a37e5cd2efb5964281b9bef5ce8cc (diff)
downloadlectio-feede51697be870ae183a95b513ef64f031dbd0f.tar.gz
lectio-feede51697be870ae183a95b513ef64f031dbd0f.zip
feat(readings): compute the daily view offline (OF + EF)
Route readings.Load through the embedded calendar engine and lectionary data instead of the niedziela/missalemeum scrapers. The daily view now computes each day (calendar.Compute + caldata.Readings) and renders text from the public-domain corpora, with citations resolved per corpus. - bible.OFRef: normalise an English-canonical OF citation (drop sub-verse letters, ";" -> ",") and renumber Psalms for the target Psalter (Hebrew->Vulgate chapter for vul/grb/wuj; DRB title-fold verses for drb). - liturgy.Section gains Ref (English-canonical lookup ref) alongside Citation (sigla-dialect display); the loader fills both, resolveRef uses Ref, headings/citation command show Citation. - EffectiveVersions always drops "bt" (no offline corpus); the single daily version defaults to vernacularVersion (reading corpus else Latin). Scraper packages remain in the tree, unreferenced, pending removal.
Diffstat (limited to 'internal/readings/readings_test.go')
-rw-r--r--internal/readings/readings_test.go80
1 files changed, 20 insertions, 60 deletions
diff --git a/internal/readings/readings_test.go b/internal/readings/readings_test.go
index c9e92cd..f3375f6 100644
--- a/internal/readings/readings_test.go
+++ b/internal/readings/readings_test.go
@@ -1,10 +1,6 @@
package readings
import (
- "net/http"
- "net/http/httptest"
- "os"
- "path/filepath"
"strings"
"testing"
@@ -79,18 +75,10 @@ func TestFilterPartsTraditionalAllReadingsOnly(t *testing.T) {
}
}
-func TestLoadModernRoutes(t *testing.T) {
- html, err := os.ReadFile("../liturgy/testdata/2026-07-22.html")
- if err != nil {
- t.Fatal(err)
- }
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write(html)
- }))
- defer srv.Close()
- liturgy.SetBaseURL(srv.URL + "/liturgia/%s/Ewangelia")
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
-
+// TestLoadModern computes the Ordinary Form day offline: the gospel section is
+// present and the header carries the celebration name (English by default,
+// since the universal sanctoral is authored in English).
+func TestLoadModern(t *testing.T) {
cfg := config.Config{Lectionary: "new"}
secs, info, err := Load(cfg, Options{Date: "2026-07-22", All: true})
if err != nil {
@@ -106,57 +94,29 @@ func TestLoadModernRoutes(t *testing.T) {
if !found {
t.Errorf("no gospel section (PartID=ewangelia) found in %+v", secs)
}
- if !strings.Contains(info.Name, "Marii Magdaleny") {
- t.Errorf("DayInfo.Name = %q, want it to contain %q", info.Name, "Marii Magdaleny")
- }
-}
-
-// TestLoadTraditionalOfflineErrorsWithoutCache exercises the (formerly
-// unsupported) traditional+offline path when nothing has been cached yet
-// for that date/lang: it must fail clearly rather than silently falling
-// back to the network or to the modern lectionary's sigla store.
-func TestLoadTraditionalOfflineErrorsWithoutCache(t *testing.T) {
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
-
- cfg := config.Config{Lectionary: "traditional", TraditionalLang: "pl"}
- _, _, err := Load(cfg, Options{Date: "2026-07-22", Offline: true})
- if err == nil {
- t.Fatal("expected error, got nil")
- }
- msg := strings.ToLower(err.Error())
- if !strings.Contains(msg, "no cached") {
- t.Errorf("error %q should mention no cached propers", err.Error())
+ if !strings.Contains(info.Name, "Mary Magdalene") {
+ t.Errorf("DayInfo.Name = %q, want it to contain %q", info.Name, "Mary Magdalene")
}
}
-// TestLoadTraditionalOfflineReadsCache is the positive counterpart: once a
-// prior online Load (or 'lectio update') has cached a date's traditional
-// propers, Load(offline=true) must serve them from disk, no network
-// involved.
-func TestLoadTraditionalOfflineReadsCache(t *testing.T) {
- dir := t.TempDir()
- t.Setenv("XDG_CACHE_HOME", dir)
- cacheDir := filepath.Join(dir, "lectio")
- if err := os.MkdirAll(cacheDir, 0o755); err != nil {
- t.Fatal(err)
- }
- body, err := os.ReadFile("../tradlit/testdata/2026-07-22.json")
- if err != nil {
- t.Fatal(err)
- }
- if err := os.WriteFile(filepath.Join(cacheDir, "2026-07-22.trad.pl.json"), body, 0o644); err != nil {
- t.Fatal(err)
- }
-
- cfg := config.Config{Lectionary: "traditional", TraditionalLang: "pl"}
+// TestLoadTraditional computes the Extraordinary Form day offline: it never
+// needs the network, and yields the EF epistle+gospel with a header name.
+func TestLoadTraditional(t *testing.T) {
+ cfg := config.Config{Lectionary: "traditional"}
secs, info, err := Load(cfg, Options{Date: "2026-07-22", Offline: true, All: true})
if err != nil {
t.Fatalf("Load: %v", err)
}
- if len(secs) == 0 {
- t.Error("expected traditional offline sections, got none")
+ found := false
+ for _, s := range secs {
+ if s.PartID == "evangelium" {
+ found = true
+ }
+ }
+ if !found {
+ t.Errorf("no EF gospel section (PartID=evangelium) found in %+v", secs)
}
- if info.Name != "St. Mary Magdalene" {
- t.Errorf("DayInfo.Name = %q, want %q", info.Name, "St. Mary Magdalene")
+ if info.Name == "" {
+ t.Error("DayInfo.Name empty for a traditional feast day")
}
}