aboutsummaryrefslogtreecommitdiff
path: root/test/test_mass_formulary.ml
blob: 1316e4720f051f287ca05d8f177a0a06a92995e8 (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
module MF = Colitur_kernel.Mass_formulary
module Slug = Colitur_kernel.Slug

let slug s = Slug.of_string_exn s

let test_round_trips_through_sexp () =
  let f = { MF.said = Some (slug "ef-time-after-pentecost-sunday-9"); via = MF.Preceding_sunday } in
  let f' = MF.t_of_sexp (MF.sexp_of_t f) in
  Alcotest.(check (option string)) "slug survives"
    (Option.map Slug.to_string f.MF.said) (Option.map Slug.to_string f'.MF.said);
  Alcotest.(check bool) "source survives" true (f.MF.via = f'.MF.via)

(* [said] is [None] exactly for {!MF.Votive} -- see the .mli's own citation.
   Round-tripped separately so the [None] case has its own witness, not only
   inferred from the [Some] case above. *)
let test_none_said_round_trips_through_sexp () =
  let f = { MF.said = None; via = MF.Votive } in
  let f' = MF.t_of_sexp (MF.sexp_of_t f) in
  Alcotest.(check bool) "said stays None" true (f'.MF.said = None);
  Alcotest.(check bool) "source survives" true (f.MF.via = f'.MF.via)

(* [to_string] is what an ordo line shows. It names the SOURCE, not the slug,
   because the slug is a key and the reader wants "of the preceding Sunday". *)
let test_to_string_names_the_source () =
  let cases =
    [ (MF.Proper, "proper"); (MF.Own_slug, "own"); (MF.Preceding_sunday, "preceding-sunday");
      (MF.Common, "common"); (MF.Votive, "votive") ]
  in
  List.iter
    (fun (via, expected) ->
      Alcotest.(check string) expected expected
        (MF.source_to_string via))
    cases

let suite =
  ( "Mass_formulary",
    [ Alcotest.test_case "sexp round-trips" `Quick test_round_trips_through_sexp;
      Alcotest.test_case "sexp round-trips, said = None (Votive)" `Quick
        test_none_said_round_trips_through_sexp;
      Alcotest.test_case "source_to_string names each source" `Quick
        test_to_string_names_the_source ] )