diff options
| -rw-r--r-- | test/test_citation_coverage.ml | 43 | ||||
| -rw-r--r-- | test/test_colitur.ml | 1 |
2 files changed, 44 insertions, 0 deletions
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_<module>.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 ] ) diff --git a/test/test_colitur.ml b/test/test_colitur.ml index 6fe212d..fb2c20c 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_coverage.suite; Test_citation.suite; ("parse", Test_citation.parse_suite); Test_config.suite; |
