aboutsummaryrefslogtreecommitdiff
path: root/test/test_citation.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_citation.ml')
-rw-r--r--test/test_citation.ml19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/test_citation.ml b/test/test_citation.ml
index 133553b..dae4610 100644
--- a/test/test_citation.ml
+++ b/test/test_citation.ml
@@ -283,6 +283,11 @@ let parses input expected () =
| Error e -> Alcotest.failf "%s did not parse: %s" input e
| Ok t -> Alcotest.(check s) input expected (show t)
+let rejects input () =
+ match P.parse input with
+ | Ok t -> Alcotest.failf "%s should not parse, got %s" input (show t)
+ | Error _ -> ()
+
let test_rejects_unknown_book () =
Alcotest.(check bool) "error" true (Result.is_error (P.parse "Nonesuch 1:1"))
@@ -321,6 +326,20 @@ let parse_suite =
("ordinal 3 parses", `Quick, parses "3 Kings 17:8-16" "kings_3|17:8-16");
("ordinal 3 dotted", `Quick, parses "3 Kgs. 19:3-8" "kings_3|19:3-8");
("ordinal 4 parses", `Quick, parses "4 Kings 5:1-15" "kings_4|5:1-15");
+ (* A citation number must be plain digits and positive. OCaml's
+ [int_of_string] also accepts its own literal syntax, so "1_1" parsed
+ as chapter ELEVEN and "+5" as 5 -- a typo silently becoming a
+ DIFFERENT chapter, which no amount of downstream care can catch.
+ Reachable through a user overlay, which supplies arbitrary strings. *)
+ ("rejects underscore in chapter", `Quick, rejects "Luke 1_1:5");
+ ("rejects underscore in verse", `Quick, rejects "Luke 1:5_0");
+ ("rejects plus in chapter", `Quick, rejects "Luke +1:5");
+ ("rejects plus in verse", `Quick, rejects "Luke 1:+5");
+ ("rejects chapter zero", `Quick, rejects "Luke 0:5");
+ ("rejects verse zero", `Quick, rejects "Luke 1:0");
+ (* A descending range is always a transcription error. *)
+ ("rejects descending range", `Quick, rejects "Luke 1:20-10");
+ ("allows a single-verse range", `Quick, parses "Luke 1:5-5" "luke|1:5-5");
("unknown book", `Quick, test_rejects_unknown_book);
("garbage", `Quick, test_rejects_garbage) ]