diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-24 10:32:28 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-24 10:32:28 +0200 |
| commit | c9f3bf46f0de09edb796e35f3dcff349febf75c9 (patch) | |
| tree | c1a0b98b484e4da557c1ab205dfff0d92ce8ac36 /internal/liturgy/parse_test.go | |
| parent | a865374755480a4aef2a6156afccdf08a91422ea (diff) | |
| download | lectio-c9f3bf46f0de09edb796e35f3dcff349febf75c9.tar.gz lectio-c9f3bf46f0de09edb796e35f3dcff349febf75c9.zip | |
dayinfo: show feast/day name + colour (modern niedziela + traditional missalemeum) in cli/tui/web; v0.5.0
Diffstat (limited to 'internal/liturgy/parse_test.go')
| -rw-r--r-- | internal/liturgy/parse_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/liturgy/parse_test.go b/internal/liturgy/parse_test.go index 13732f9..8fe2eb0 100644 --- a/internal/liturgy/parse_test.go +++ b/internal/liturgy/parse_test.go @@ -56,6 +56,59 @@ func TestParse(t *testing.T) { } } +// TestParseDayInfo checks the modern (niedziela.pl) day-info extraction +// against the split-feast fixture: Name comes from the color-classed, +// fw-bold <p><em>...</em></p> near id="dzien" (not the earlier, plain +// fw-bold lookalike higher up the page), and Colour from "Kolor szat: +// biały" -> "white". Season is always "" for the modern lectionary. +func TestParseDayInfo(t *testing.T) { + html, err := os.ReadFile("testdata/2026-07-22.html") + if err != nil { + t.Fatal(err) + } + info := ParseDayInfo(string(html)) + if !strings.Contains(info.Name, "Marii Magdaleny") { + t.Errorf("Name = %q, want it to contain %q", info.Name, "Marii Magdaleny") + } + if info.Colour != "white" { + t.Errorf("Colour = %q, want %q", info.Colour, "white") + } + if info.Season != "" { + t.Errorf("Season = %q, want empty for the modern lectionary", info.Season) + } +} + +// TestParseDayInfoMultilineName checks the day name is cleanly joined when +// the source <em> body itself carries an embedded line break (a long +// commemoration name wrapped across lines in the page's own markup), and +// that a multi-option colour line ("zielony albo biały albo czerwony") +// maps by its first word. +func TestParseDayInfoMultilineName(t *testing.T) { + html, err := os.ReadFile("testdata/2026-06-22.html") + if err != nil { + t.Fatal(err) + } + info := ParseDayInfo(string(html)) + if !strings.Contains(info.Name, "Dzień Powszedni") || !strings.Contains(info.Name, "Jana Fishera") { + t.Errorf("Name = %q, want it to contain both wrapped-line fragments", info.Name) + } + if strings.Contains(info.Name, "\n") { + t.Errorf("Name = %q, should not contain a raw newline", info.Name) + } + if info.Colour != "green" { + t.Errorf("Colour = %q, want %q (first of \"zielony albo...\")", info.Colour, "green") + } +} + +// TestParseDayInfoNoMatch checks an unrecognised page shape yields a zero +// DayInfo rather than an error -- the header is simply omitted by callers. +func TestParseDayInfoNoMatch(t *testing.T) { + info := ParseDayInfo("<html><body>redesigned</body></html>") + if info != (DayInfo{}) { + t.Errorf("ParseDayInfo(unrecognised) = %+v, want zero value", info) + } +} + func TestParseLayoutChange(t *testing.T) { if _, err := Parse("<html><body>redesigned</body></html>"); err == nil { t.Error("expected error on missing reading tab") |
