1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package liturgy
import (
"os"
"strings"
"testing"
)
func TestParse(t *testing.T) {
html, _ := os.ReadFile("testdata/2026-07-22.html")
secs, err := Parse(string(html))
if err != nil {
t.Fatal(err)
}
var gospel *Section
var firstCzytanie *Section
var secondCzytanie *Section
for i := range secs {
if strings.HasPrefix(secs[i].Heading, "Ewangelia") {
gospel = &secs[i]
}
if strings.HasPrefix(secs[i].Heading, "1. czytanie") {
if firstCzytanie == nil {
firstCzytanie = &secs[i]
} else if secondCzytanie == nil {
secondCzytanie = &secs[i]
}
}
}
if gospel == nil {
t.Fatal("no gospel section")
}
if gospel.Citation != "J 20, 1. 11-18" {
t.Errorf("gospel citation = %q", gospel.Citation)
}
if len(gospel.Paragraphs) == 0 {
t.Error("gospel has no paragraphs")
}
if gospel.PartID != "ewangelia" {
t.Errorf("gospel PartID = %q, want %q", gospel.PartID, "ewangelia")
}
if firstCzytanie == nil {
t.Fatal("no '1. czytanie' section")
}
if firstCzytanie.PartID != "pierwsze_czytanie" {
t.Errorf("first '1. czytanie' PartID = %q, want %q", firstCzytanie.PartID, "pierwsze_czytanie")
}
// 2026-07-22 is a split-feast day with two "1. czytanie" sections in the
// same tab; the second one must not collide with the first.
if secondCzytanie == nil {
t.Fatal("expected a second '1. czytanie' section (split feast fixture)")
}
if secondCzytanie.PartID != "drugie_czytanie" {
t.Errorf("second '1. czytanie' PartID = %q, want %q", secondCzytanie.PartID, "drugie_czytanie")
}
}
func TestParseLayoutChange(t *testing.T) {
if _, err := Parse("<html><body>redesigned</body></html>"); err == nil {
t.Error("expected error on missing reading tab")
}
}
func TestParseNormalDay(t *testing.T) {
html, err := os.ReadFile("testdata/2026-06-22.html")
if err != nil {
t.Fatal(err)
}
secs, err := Parse(string(html))
if err != nil {
t.Fatal(err)
}
if len(secs) != 4 {
t.Fatalf("len(secs) = %d, want 4", len(secs))
}
want := map[string]string{
"1. czytanie": "pierwsze_czytanie",
"Psalm": "psalm",
"Aklamacja": "aklamacja",
"Ewangelia": "ewangelia",
}
for _, s := range secs {
for prefix, partID := range want {
if strings.HasPrefix(s.Heading, prefix) {
if s.PartID != partID {
t.Errorf("heading %q: PartID = %q, want %q", s.Heading, s.PartID, partID)
}
}
}
if s.Subtitle == "" {
t.Errorf("heading %q: empty subtitle", s.Heading)
}
if len(s.Paragraphs) == 0 {
t.Errorf("heading %q: no paragraphs", s.Heading)
}
}
}
func TestExtractCitation(t *testing.T) {
cases := []struct {
heading string
want string
}{
{"Ewangelia (Mt 7, 1-5)", "Mt 7, 1-5"},
{"1. czytanie (Pnp 8, 6-7)", "Pnp 8, 6-7"},
{"Psalm (Ps 63 (62), 2. 3-4. 5-6. 8-9 (R.: por. 2ab))", "Ps 63 (62), 2. 3-4. 5-6. 8-9 (R.: por. 2ab)"},
}
for _, c := range cases {
got, err := ExtractCitation(c.heading)
if err != nil {
t.Errorf("ExtractCitation(%q) error: %v", c.heading, err)
continue
}
if got != c.want {
t.Errorf("ExtractCitation(%q) = %q, want %q", c.heading, got, c.want)
}
}
if _, err := ExtractCitation("no parens here"); err == nil {
t.Error("expected error for heading with no parenthetical")
}
}
|