summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-20 14:40:12 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-20 14:40:12 +0200
commit405910d2fd245e7a11e09eecb8c6fffb68d2169c (patch)
tree7cb7e0011fee6c1c07ae81762640f0ab867e88b6 /test
parent1aeca948c2a2a82bffaaec65077140aa05f7b3f4 (diff)
downloadcolitur-405910d2fd245e7a11e09eecb8c6fffb68d2169c.tar.gz
colitur-405910d2fd245e7a11e09eecb8c6fffb68d2169c.zip
feat(citation): canonical book ids and tradition mapping
Seven books arrive in two spellings, inherited from lectio's ini and ultimately from Divinum Officium. Collapse them onto one id here rather than editing generated data. Naming and renumbering are kept apart: a tradition decides which book an id denotes, a language file decides what it is called.
Diffstat (limited to 'test')
-rw-r--r--test/dune2
-rw-r--r--test/test_citation.ml43
-rw-r--r--test/test_colitur.ml1
3 files changed, 45 insertions, 1 deletions
diff --git a/test/dune b/test/dune
index 84c5ec7..a90b715 100644
--- a/test/dune
+++ b/test/dune
@@ -1,6 +1,6 @@
(test
(name test_colitur)
- (libraries colitur_kernel colitur_naming colitur_render rite_ef alcotest qcheck qcheck-alcotest sexplib)
+ (libraries colitur_kernel colitur_naming colitur_render colitur_citation rite_ef alcotest qcheck qcheck-alcotest sexplib)
(deps
../data/ef/sanctoral.sexp
../data/ef/adjustments.sexp
diff --git a/test/test_citation.ml b/test/test_citation.ml
new file mode 100644
index 0000000..0694d8b
--- /dev/null
+++ b/test/test_citation.ml
@@ -0,0 +1,43 @@
+module B = Colitur_citation.Book
+
+let s = Alcotest.string
+
+let test_both_spellings_are_one_book () =
+ (* The seven inherited duplicate spellings must collapse. This is the
+ whole reason the parser exists rather than a regex. *)
+ let same a b =
+ match B.of_token a, B.of_token b with
+ | Some x, Some y ->
+ Alcotest.(check s) (a ^ " = " ^ b) (B.to_string x) (B.to_string y)
+ | _ -> Alcotest.failf "%s or %s did not resolve" a b
+ in
+ same "Isa" "Isa.";
+ same "Matt" "Matt.";
+ same "1 Cor" "1 Cor.";
+ same "1 Pet" "1 Pet.";
+ same "1 Thess" "1 Thess.";
+ same "Eph" "Eph.";
+ same "3 Kgs." "3 Kings"
+
+let test_unknown_token_is_none () =
+ Alcotest.(check bool) "not a book" true (B.of_token "Nonesuch" = None)
+
+let test_vulgate_is_identity () =
+ match B.of_token "3 Kings" with
+ | None -> Alcotest.fail "3 Kings did not resolve"
+ | Some k ->
+ Alcotest.(check s) "unmapped" "kings_3" (B.to_string (B.map B.vulgate k))
+
+let test_modern_renumbers () =
+ let modern = B.tradition_of_fields [ ("kings_3", "kings_1") ] in
+ match B.of_token "3 Kings" with
+ | None -> Alcotest.fail "3 Kings did not resolve"
+ | Some k ->
+ Alcotest.(check s) "renumbered" "kings_1" (B.to_string (B.map modern k))
+
+let suite =
+ ( "book",
+ [ Alcotest.test_case "both spellings one book" `Quick test_both_spellings_are_one_book;
+ Alcotest.test_case "unknown token" `Quick test_unknown_token_is_none;
+ Alcotest.test_case "vulgate identity" `Quick test_vulgate_is_identity;
+ Alcotest.test_case "modern renumbers" `Quick test_modern_renumbers ] )
diff --git a/test/test_colitur.ml b/test/test_colitur.ml
index 1bdd220..46a31aa 100644
--- a/test/test_colitur.ml
+++ b/test/test_colitur.ml
@@ -4,6 +4,7 @@ let () =
[ Test_date.suite; Test_computus.suite; Test_colour.suite; Test_slug.suite; Test_names.suite;
Test_lang.suite;
Test_lang_coverage.suite;
+ Test_citation.suite;
Test_config.suite;
Test_overlay.suite; Test_overlay_ini.suite; Test_temporal_ef.suite; Test_validate.suite; Test_precedence.suite;
Test_calendar.suite; Test_precedence_ef.suite; Test_sanctoral_ef.suite; Test_rite_ef.suite;