summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-11 11:37:32 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-11 11:37:32 +0200
commit57322e766a0ece579dafcddcfe2572676a98fca8 (patch)
tree0e6ca11d29000b956a2c4bb65e436b0eb9251809 /test
parent270be2561ae440cea814566b74712750352e56e4 (diff)
downloadcolitur-57322e766a0ece579dafcddcfe2572676a98fca8.tar.gz
colitur-57322e766a0ece579dafcddcfe2572676a98fca8.zip
kernel: Names, Citation and Date_spec
Names is an open language-keyed assoc kept in canonical order so equal name sets serialise identically. Citation carries references only, never text. Date_spec ships the one form the EF sanctoral needs; 29 February is constructible and resolves to None in common years.
Diffstat (limited to 'test')
-rw-r--r--test/test_colitur.ml2
-rw-r--r--test/test_names.ml56
2 files changed, 57 insertions, 1 deletions
diff --git a/test/test_colitur.ml b/test/test_colitur.ml
index 3341c36..af642d6 100644
--- a/test/test_colitur.ml
+++ b/test/test_colitur.ml
@@ -1,4 +1,4 @@
(* Aggregating test runner. Per-module suites live in test_<module>.ml. *)
let () =
Alcotest.run "colitur"
- [ Test_date.suite; Test_computus.suite; Test_colour.suite; Test_slug.suite ]
+ [ Test_date.suite; Test_computus.suite; Test_colour.suite; Test_slug.suite; Test_names.suite ]
diff --git a/test/test_names.ml b/test/test_names.ml
new file mode 100644
index 0000000..6089b5f
--- /dev/null
+++ b/test/test_names.ml
@@ -0,0 +1,56 @@
+module N = Colitur_kernel.Names
+module L = Colitur_kernel.Lang
+module C = Colitur_kernel.Citation
+module DS = Colitur_kernel.Date_spec
+module D = Colitur_kernel.Date
+
+let lang s = L.of_string_exn s
+
+let test_names_basics () =
+ let n = N.of_list [ (lang "pl", "Wielkanoc"); (lang "la", "Pascha") ] in
+ Alcotest.(check (option string)) "find la" (Some "Pascha") (N.find n (lang "la"));
+ Alcotest.(check (option string)) "find en" None (N.find n (lang "en"));
+ Alcotest.(check (option string)) "fallback la then en"
+ (Some "Pascha") (N.find_first n [ lang "en"; lang "la" ]);
+ (* canonical order is by language code, so sexp output is byte-stable *)
+ Alcotest.(check (list string)) "canonical order" [ "la"; "pl" ]
+ (List.map (fun (l, _) -> L.to_string l) (N.to_list n))
+
+let test_names_set_remove () =
+ let n = N.of_list [ (lang "la", "Pascha") ] in
+ let n = N.set n (lang "en") "Easter" in
+ Alcotest.(check (option string)) "set en" (Some "Easter") (N.find n (lang "en"));
+ let n = N.set n (lang "en") "Easter Sunday" in
+ Alcotest.(check (option string)) "last writer wins" (Some "Easter Sunday") (N.find n (lang "en"));
+ let n = N.remove n (lang "en") in
+ Alcotest.(check (option string)) "removed" None (N.find n (lang "en"))
+
+let test_citation () =
+ let c = { C.part = C.Gospel; reference = "Jn 3:16" } in
+ Alcotest.(check bool) "sexp roundtrip" true (C.t_of_sexp (C.sexp_of_t c) = c);
+ Alcotest.(check string) "part string" "gospel" (C.part_to_string C.Gospel);
+ Alcotest.(check bool) "part of_string" true (C.part_of_string "first" = Some C.First)
+
+let test_date_spec () =
+ (match DS.fixed ~month:3 ~day:25 with
+ | Ok ds -> (
+ match DS.resolve ds ~year:2026 with
+ | Some d -> Alcotest.(check string) "resolve" "2026-03-25" (D.to_iso8601 d)
+ | None -> Alcotest.fail "resolve returned None")
+ | Error e -> Alcotest.failf "fixed: %s" e);
+ (* Feb 29 is a legitimate fixed date that simply does not occur every year. *)
+ (match DS.fixed ~month:2 ~day:29 with
+ | Ok ds ->
+ Alcotest.(check bool) "Feb 29 resolves in 2024" true (DS.resolve ds ~year:2024 <> None);
+ Alcotest.(check bool) "Feb 29 absent in 2026" true (DS.resolve ds ~year:2026 = None)
+ | Error e -> Alcotest.failf "Feb 29 must be constructible: %s" e);
+ Alcotest.(check bool) "reject Feb 30" true (Result.is_error (DS.fixed ~month:2 ~day:30));
+ Alcotest.(check bool) "reject Apr 31" true (Result.is_error (DS.fixed ~month:4 ~day:31));
+ Alcotest.(check bool) "reject month 13" true (Result.is_error (DS.fixed ~month:13 ~day:1))
+
+let suite =
+ ( "Names/Citation/DateSpec",
+ [ Alcotest.test_case "names basics" `Quick test_names_basics;
+ Alcotest.test_case "names set/remove" `Quick test_names_set_remove;
+ Alcotest.test_case "citation" `Quick test_citation;
+ Alcotest.test_case "date_spec" `Quick test_date_spec ] )