summaryrefslogtreecommitdiff
path: root/test/test_lectionary_ef.ml
blob: a1a324fe4e180e8a884f2012dbba91512c9d9fc3 (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
open Colitur_kernel
open Rite_ef

(* Same pattern test_rite_ef.ml already uses: both [Calendar.year] and
   [Calendar.day] take the rite AND the sanctoral layer (Rite.t carries no
   layer of its own -- see rite_ef.mli's own note on why), so step 1's
   sanctoral-proper case needs the REAL data/ef/sanctoral.sexp +
   data/ef/adjustments.sexp loaded, not a bare [Rite_ef.context]. Relative
   to this test's own build directory (_build/default/test/); test/dune
   declares both as deps. *)
let sanctoral_path = "../data/ef/sanctoral.sexp"
let adjustments_path = "../data/ef/adjustments.sexp"

let real_layer () =
  let layer =
    match Layer.load Vocab_ef.rank_of_sexp sanctoral_path with
    | Ok l -> l
    | Error e -> Alcotest.failf "%s: failed to load: %s" sanctoral_path e
  in
  let overlay =
    match Overlay.load Vocab_ef.rank_of_sexp adjustments_path with
    | Ok o -> o
    | Error e -> Alcotest.failf "%s: failed to load: %s" adjustments_path e
  in
  let layer, diagnostics = Overlay.apply layer overlay in
  Alcotest.(check (list string)) "the committed overlay applies cleanly, no diagnostics" []
    (List.map Overlay.diagnostic_to_string diagnostics);
  layer

(* [Calendar.day] (not [year]): the liturgical year "opening in civil year y"
   is Advent-anchored (RG 61), so [Calendar.year _ _ 2030] covers Advent 2030
   through November 2031 -- it would never contain 13 January 2030, which
   belongs to the liturgical year that opened in Advent 2029. [Calendar.day]
   finds the containing liturgical year itself; see calendar.mli. *)
let day y m d =
  let date = match Date.make ~year:y ~month:m ~day:d with
    | Ok x -> x | Error e -> Alcotest.fail e in
  Calendar.day Rite_ef.context (real_layer ()) date

let refs (ld : _ Liturgical_day.t) =
  List.map (fun c -> c.Citation.reference) ld.citations

(* Chain step 1: the observed celebration's own proper wins.

   NOT 2030: that is the one pinned collision year (test_golden.ml,
   [test_holy_family_excludes_baptism_2030]) where 13 January is itself the
   Holy Family Sunday and RG 112(a) excludes the Baptism commemoration
   entirely -- [observed] there is [ef-time-after-epiphany-sunday-1], not
   this slug, so it is the wrong year to exercise step 1 against. 2026 is an
   ordinary year (13 January a Tuesday, no Sunday collision), where the
   fixed Commemoration of the Baptism of the Lord (Class2, subject Lord,
   data/ef/sanctoral.sexp) is observed outright. *)
let test_step1_sanctoral_proper () =
  Alcotest.(check (list string))
    "13 January 2026, Commemoration of the Baptism of the Lord"
    [ "Isa 60:1-6"; "John 1:29-34" ]
    (refs (day 2026 1 13))

(* Chain step 2: the day's own temporal slug has a proper (Lent has one daily). *)
let test_step2_lenten_feria_has_its_own () =
  Alcotest.(check (list string))
    "Monday of the 1st week of Lent is not the Sunday's Mass"
    [ "Ezech 34:11-16"; "Matt 25:31-46" ]
    (refs (day 2026 2 23))

let suite =
  [ ("step 1: sanctoral proper", `Quick, test_step1_sanctoral_proper);
    ("step 2: own temporal proper", `Quick, test_step2_lenten_feria_has_its_own) ]