diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 12:15:44 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 12:15:44 +0200 |
| commit | 2e3697b5ce7338568a67531d07a5528f0de1da22 (patch) | |
| tree | 8ebe75d9fc975590fb7dc92a9a6a91220a3ed632 /test/test_overlay.ml | |
| parent | 1512df6514f0e656d734f2bf03d050355d0dd0b7 (diff) | |
| download | colitur-2e3697b5ce7338568a67531d07a5528f0de1da22.tar.gz colitur-2e3697b5ce7338568a67531d07a5528f0de1da22.zip | |
kernel(layer): sanctoral layer with canonical order and date index
Entries sort by slug so equal layers serialise identically. The by-date index
is built once per layer rather than per year, since fixed dates are
year-independent; a full-domain sweep would otherwise rescan every entry for
every day. load turns parse and validation failures into result.
Diffstat (limited to 'test/test_overlay.ml')
| -rw-r--r-- | test/test_overlay.ml | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/test_overlay.ml b/test/test_overlay.ml new file mode 100644 index 0000000..ece4069 --- /dev/null +++ b/test/test_overlay.ml @@ -0,0 +1,45 @@ +module L = Colitur_kernel.Layer +module Cel = Colitur_kernel.Celebration +module S = Colitur_kernel.Slug +module DS = Colitur_kernel.Date_spec +module Col = Colitur_kernel.Colour + +type rank = Class1 | Class3 [@@deriving sexp] + +let slug = S.of_string_exn + +let cel ?(rank = Class3) ?(colour = Col.White) s = + Cel.make ~slug:(slug s) ~rank ~colour ~layer:"base" () + +let entry ?(month = 1) ?(day = 1) ?rank ?colour s = + { L.date = (match DS.fixed ~month ~day with Ok d -> d | Error e -> failwith e); + cel = cel ?rank ?colour s } + +let base () = + L.of_entries ~id:"base" ~name:"Test base" + [ entry ~month:1 ~day:5 "telesphorus"; entry ~month:1 ~day:14 "hilary" ] + +let test_layer_basics () = + let l = base () in + Alcotest.(check bool) "find present" true (L.find l (slug "hilary") <> None); + Alcotest.(check bool) "find absent" true (L.find l (slug "nobody") = None); + Alcotest.(check bool) "mem" true (L.mem l (slug "telesphorus")); + (* canonical order is by slug, so sexp output is byte-stable *) + Alcotest.(check (list string)) "canonical order" [ "hilary"; "telesphorus" ] + (List.map (fun e -> S.to_string e.L.cel.Cel.slug) l.L.entries) + +let test_layer_index () = + let idx = L.index_by_date (base ()) in + Alcotest.(check int) "Jan 14 has one" 1 (List.length (L.on_date idx ~month:1 ~day:14)); + Alcotest.(check int) "Jan 20 has none" 0 (List.length (L.on_date idx ~month:1 ~day:20)) + +let test_layer_sexp () = + let l = base () in + let sexp = L.sexp_of_t sexp_of_rank l in + Alcotest.(check bool) "roundtrip" true (L.t_of_sexp rank_of_sexp sexp = l) + +let suite = + ( "Layer/Overlay", + [ Alcotest.test_case "layer basics" `Quick test_layer_basics; + Alcotest.test_case "layer by-date index" `Quick test_layer_index; + Alcotest.test_case "layer sexp" `Quick test_layer_sexp ] ) |
