From a675a983424f1f8d103fc12d55ef4f7129a92d62 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 24 Jul 2026 13:07:37 +0200 Subject: qol: tui jump-to-date (d) + lectio --citation/--week + hide bt for traditional web; v0.10.0 --- internal/cli/cli_test.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'internal/cli/cli_test.go') 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]) + } +} -- cgit v1.3