aboutsummaryrefslogtreecommitdiff
path: root/internal/caldata/caldata_test.go
blob: 12aa7651bcbabc924d9a07667b39edb11d4fca91 (plain) (blame)
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
package caldata

import (
	"strings"
	"testing"

	"github.com/lukaszkasprzak/lectio/internal/calendar"
)

func TestUniversalLoads(t *testing.T) {
	l := Universal()
	if l.ID != "universal" {
		t.Fatalf("layer id = %q", l.ID)
	}
	// the Assumption (08-15, solemnity) must be present under some slug.
	assumption := false
	for _, rc := range l.Cels {
		if rc.Fields["date"] == "08-15" && rc.Fields["rank"] == "solemnity" {
			assumption = true
		}
	}
	if !assumption {
		t.Fatal("no 08-15 solemnity (Assumption) in the universal calendar")
	}
	// every entry must build into a typed Celebration whose rank parsed.
	for slug, rc := range l.Cels {
		c := calendar.BuildCelebrationForTest(slug, rc)
		if c.Rank == calendar.RankFerial && rc.Fields["rank"] != "" {
			t.Errorf("%s: rank did not parse (%q)", slug, rc.Fields["rank"])
		}
	}
}

func TestUniversalSanctoralReadings(t *testing.T) {
	l := Universal()
	// A feast/solemnity or a PROPER-reading memorial carries its own inline Mass.
	// Partial-proper memorials keep ONLY the strictly-proper part (the resolver
	// fills the rest from the ferial): the Guardian Angels a proper gospel, St
	// Barnabas a proper first reading, Our Lady of Sorrows a proper gospel.
	want := map[string][2]string{ // slug -> {reading.first substr, reading.gospel substr; "" = absent}
		"assumption-of-the-blessed-virgin-mary": {"Revelation 11", "Luke 1:39-56"},
		"all-saints":                            {"Revelation 7", "Matthew 5:1-12"},
		"barnabas-the-apostle":                  {"Acts 11", ""},
		"guardian-angels":                       {"", "Matthew 18:1-5"},
		"our-lady-of-sorrows":                   {"", "John 19:25-27"},
	}
	for slug, w := range want {
		rc, ok := l.Cels[slug]
		if !ok {
			t.Errorf("missing %q", slug)
			continue
		}
		for i, part := range []string{"reading.first", "reading.gospel"} {
			got := rc.Fields[part]
			if w[i] == "" {
				if got != "" {
					t.Errorf("%s: %s = %q, want absent (ferial)", slug, part, got)
				}
			} else if !strings.Contains(got, w[i]) {
				t.Errorf("%s: %s = %q, want containing %q", slug, part, got, w[i])
			}
		}
	}
}

func TestTridentineLoads(t *testing.T) {
	l := Tridentine()
	if l.ID != "tridentine" {
		t.Fatalf("layer id = %q", l.ID)
	}
	// The full 1962 sanctoral is populated (generated from missalemeum), not the
	// 16-entry bootstrap.
	if len(l.Cels) < 250 {
		t.Fatalf("EF sanctoral has only %d entries; expected the full calendar", len(l.Cels))
	}
	// Landmark feasts must be present with the right rank/class: Sts Peter & Paul
	// (I class, 06-29), the Purification/Presentation (a II class feast of the
	// Lord, 02-02, which must displace a Sunday), the Immaculate Conception
	// (I class, 12-08).
	want := map[string]struct{ date, rank, class string }{
		"sts-peter-paul": {"06-29", "class-1", ""},
		"purification-of-the-blessed-virgin-mary":          {"02-02", "class-2", "lord"},
		"immaculate-conception-of-the-blessed-virgin-mary": {"12-08", "class-1", ""},
	}
	for slug, w := range want {
		rc, ok := l.Cels[slug]
		if !ok {
			t.Errorf("missing landmark feast %q", slug)
			continue
		}
		if rc.Fields["date"] != w.date || rc.Fields["rank"] != w.rank {
			t.Errorf("%s: date/rank = %q/%q, want %q/%q", slug, rc.Fields["date"], rc.Fields["rank"], w.date, w.rank)
		}
		if w.class != "" && rc.Fields["class"] != w.class {
			t.Errorf("%s: class = %q, want %q", slug, rc.Fields["class"], w.class)
		}
	}
	// every entry must build into a typed Celebration whose rank parsed.
	for slug, rc := range l.Cels {
		c := calendar.BuildCelebrationForTest(slug, rc)
		if c.Rank == calendar.RankFerial && rc.Fields["rank"] != "" {
			t.Errorf("%s: rank did not parse (%q)", slug, rc.Fields["rank"])
		}
	}
}