aboutsummaryrefslogtreecommitdiff
path: root/internal/calendar/calendar_test.go
blob: 28dba9e5a694879e54c25c3a607015f0ff7be0ad (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
package calendar

import (
	"testing"
)

func universalTest() Layer {
	return Layer{ID: "universal", Type: "universal", Cels: map[string]RawCelebration{
		"assumption": {Fields: map[string]string{
			"date": "08-15", "rank": "solemnity", "class": "bvm", "colour": "white",
			"name.en": "Assumption of the BVM", "reading.gospel": "Lk 1:39-56",
		}, Variants: map[string]map[string]string{}},
		" st-monday-optional ": {Fields: map[string]string{}, Variants: map[string]map[string]string{}},
	}}
}

func TestComputeSolemnityBeatsFeria(t *testing.T) {
	got := Compute(d("2025-08-15"), DefaultSelection(), []Layer{universalTest()})
	if got.Observed.Slug != "assumption" {
		t.Fatalf("2025-08-15 observed = %q want assumption", got.Observed.Slug)
	}
	if got.Colour != White || got.Observed.Rank != RankSolemnity {
		t.Errorf("assumption colour/rank wrong: %s / %v", got.Colour, got.Observed.Rank)
	}
	if len(got.Observed.Masses) == 0 || got.Observed.Masses[0].Readings[0].Part != "gospel" {
		t.Errorf("proper reading not surfaced: %+v", got.Observed.Masses)
	}
}

func TestComputeCycles(t *testing.T) {
	// Advent 2024 opens liturgical year 2025 → Sunday cycle C, weekday cycle I.
	got := Compute(d("2025-01-15"), DefaultSelection(), []Layer{universalTest()})
	if got.SundayCycle != "C" {
		t.Errorf("2024-25 Sunday cycle = %s want C", got.SundayCycle)
	}
	if got.WeekdayCycle != "I" {
		t.Errorf("2025 weekday cycle = %s want I", got.WeekdayCycle)
	}
}

func TestComputeEF(t *testing.T) {
	sel := DefaultSelection()
	sel.Form = "old"
	// an EF layer with a I-class feast on 2025-08-15 (Assumption)
	layer := Layer{ID: "tridentine", Type: "universal", Cels: map[string]RawCelebration{
		"assumption": {Fields: map[string]string{
			"date": "08-15", "rank": "class-1", "colour": "white", "name.en": "Assumption BVM",
		}, Variants: map[string]map[string]string{}},
	}}
	got := Compute(d("2025-08-15"), sel, []Layer{layer})
	if got.Observed.Slug != "assumption" || got.Observed.Rank != RankClass1 {
		t.Fatalf("EF 2025-08-15 observed = %q/%v want assumption/class-1", got.Observed.Slug, got.Observed.Rank)
	}
	// the EF season on 2025-08-15 is Time after Pentecost (not OF's "ordinary")
	if got.Season != TimeAfterPentecost {
		t.Errorf("EF season = %s want time-after-pentecost", got.Season)
	}
	// OF path unchanged for the same date
	ofDay := Compute(d("2025-08-15"), DefaultSelection(), []Layer{layer})
	if ofDay.Season != Ordinary {
		t.Errorf("OF season = %s want ordinary", ofDay.Season)
	}
}