From f8c746736fe269ef6e0c4377f58bbb6b1f2fc07a Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 20 Aug 2026 15:03:02 +0200 Subject: test(citation): assert every emitted citation parses Walks 1970-2070 and parses every citation the engine emits. Nothing validated citation spellings before this, which is why seven books carried two spellings unnoticed. Mutation-proved: removing the 'Isa.' spelling from the book table reddens this test naming that citation. --- test/test_citation_coverage.ml | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/test_citation_coverage.ml (limited to 'test/test_citation_coverage.ml') diff --git a/test/test_citation_coverage.ml b/test/test_citation_coverage.ml new file mode 100644 index 0000000..31d49eb --- /dev/null +++ b/test/test_citation_coverage.ml @@ -0,0 +1,43 @@ +(* SPDX-License-Identifier: AGPL-3.0-or-later *) + +(* Every citation the engine can emit must parse. This is the check that + would have caught the seven duplicate book spellings -- nothing validated + them before. + + Same shape as test_lang_coverage.ml, which this file deliberately mirrors: + a miss there is a slug with no name, a miss here is a citation the parser + cannot read. *) + +module P = Colitur_citation.Parse + +let test_every_citation_parses () = + let layer = + match Test_support.load_ef_layer () with + | Ok l -> l + | Error e -> Alcotest.failf "%s" e + in + let ctx = Test_support.ef_context () in + let bad = Hashtbl.create 64 in + for y = 1970 to 2070 do + Array.iter + (fun (d : (Rite_ef.Vocab_ef.season, Rite_ef.Vocab_ef.rank) Colitur_kernel.Liturgical_day.t) -> + List.iter + (fun (c : Colitur_kernel.Citation.t) -> + let r = c.Colitur_kernel.Citation.reference in + match P.parse r with + | Ok _ -> () + | Error e -> if not (Hashtbl.mem bad r) then Hashtbl.add bad r e) + d.Colitur_kernel.Liturgical_day.citations) + (Colitur_kernel.Calendar.year ctx layer y) + done; + if Hashtbl.length bad > 0 then begin + Hashtbl.iter (fun r e -> Printf.eprintf "UNPARSED %S: %s\n" r e) bad; + Alcotest.failf "%d citation(s) did not parse" (Hashtbl.length bad) + end + +(* This project has ONE test executable. Every test_.ml exposes a + [suite] value and test_colitur.ml aggregates them -- do NOT call + Alcotest.run here. Marked `Slow like test_lang_coverage's own year walk. *) +let suite = + ( "citation-coverage", + [ Alcotest.test_case "every citation parses" `Slow test_every_citation_parses ] ) -- cgit v1.3