aboutsummaryrefslogtreecommitdiff
path: root/internal/liturgy/parse_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/liturgy/parse_test.go')
-rw-r--r--internal/liturgy/parse_test.go123
1 files changed, 123 insertions, 0 deletions
diff --git a/internal/liturgy/parse_test.go b/internal/liturgy/parse_test.go
new file mode 100644
index 0000000..13732f9
--- /dev/null
+++ b/internal/liturgy/parse_test.go
@@ -0,0 +1,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")
+ }
+}