summaryrefslogtreecommitdiff
path: root/internal/cli/cli_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/cli_test.go')
-rw-r--r--internal/cli/cli_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go
index bc7dfdb..47d8f55 100644
--- a/internal/cli/cli_test.go
+++ b/internal/cli/cli_test.go
@@ -352,3 +352,70 @@ func TestRefCompare(t *testing.T) {
t.Errorf("ref compare missing verse:\n%s", out.String())
}
}
+
+func TestGospelCitationHelpers(t *testing.T) {
+ secs := []liturgy.Section{
+ {Heading: "1. czytanie (Iz 1, 1)", PartID: "pierwsze_czytanie"},
+ {Heading: "Ewangelia (Mt 7, 1-5)", PartID: "ewangelia"},
+ }
+ sec, ok := gospelSection(secs)
+ if !ok || sec.PartID != "ewangelia" {
+ t.Fatalf("gospelSection=%+v ok=%v", sec, ok)
+ }
+ if c := gospelCitation(sec); c != "Mt 7, 1-5" {
+ t.Errorf("citation from heading = %q", c)
+ }
+ // Citation field is preferred over the heading.
+ s2 := liturgy.Section{Heading: "Ewangelia (Mt 7, 1-5)", Citation: "Mt 7, 1-5. 12", PartID: "ewangelia"}
+ if c := gospelCitation(s2); c != "Mt 7, 1-5. 12" {
+ t.Errorf("citation prefers Citation field, got %q", c)
+ }
+ // Empty -> ("", false).
+ if _, ok := gospelSection(nil); ok {
+ t.Error("gospelSection(nil) should be !ok")
+ }
+}
+
+func TestCitation(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())
+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
+
+ var out, errb bytes.Buffer
+ if code := Run([]string{"--citation", "2026-07-22"}, nil, &out, &errb); code != 0 {
+ t.Fatalf("citation code=%d stderr=%q", code, errb.String())
+ }
+ if s := strings.TrimSpace(out.String()); !strings.Contains(s, "J 20") {
+ t.Errorf("citation = %q, want a gospel ref containing 'J 20'", s)
+ }
+}
+
+func TestWeek(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())
+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
+
+ var out, errb bytes.Buffer
+ if code := Run([]string{"--week", "2026-07-22"}, nil, &out, &errb); code != 0 {
+ t.Fatalf("week code=%d stderr=%q", code, errb.String())
+ }
+ lines := strings.Split(strings.TrimSpace(out.String()), "\n")
+ if len(lines) != 7 {
+ t.Fatalf("week printed %d lines, want 7:\n%s", len(lines), out.String())
+ }
+ if !strings.HasPrefix(lines[0], "2026-07-22") || !strings.Contains(lines[0], "J 20") {
+ t.Errorf("week[0] = %q", lines[0])
+ }
+}