aboutsummaryrefslogtreecommitdiff
path: root/test/test_slug.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_slug.ml')
-rw-r--r--test/test_slug.ml15
1 files changed, 14 insertions, 1 deletions
diff --git a/test/test_slug.ml b/test/test_slug.ml
index af70e9a..3c17e4a 100644
--- a/test/test_slug.ml
+++ b/test/test_slug.ml
@@ -31,9 +31,22 @@ let test_lang () =
Alcotest.(check bool) (Printf.sprintf "reject %S" bad) true (Result.is_error (L.of_string bad)))
[ ""; "e"; "eng"; "EN"; "e1" ]
+let test_lang_sexp () =
+ let l = match L.of_string "la" with Ok t -> t | Error e -> Alcotest.failf "%s" e in
+ Alcotest.(check bool) "roundtrip" true (L.equal (L.t_of_sexp (L.sexp_of_t l)) l);
+ (* A malformed lang code in a data file must be rejected, not silently
+ accepted. "e1" is shaped like a lang code (2 chars) but fails the
+ lowercase-a-z rule, so this pins the actual validation, not just the
+ sexp shape. *)
+ Alcotest.check_raises "bad lang in sexp"
+ (Sexplib0.Sexp_conv_error.Of_sexp_error
+ (Failure "lang \"e1\": must be lowercase a-z", Sexplib0.Sexp.Atom "e1"))
+ (fun () -> ignore (L.t_of_sexp (Sexplib0.Sexp.Atom "e1")))
+
let suite =
( "Slug/Lang",
[ Alcotest.test_case "slug accepts" `Quick test_slug_accepts;
Alcotest.test_case "slug rejects" `Quick test_slug_rejects;
Alcotest.test_case "slug sexp validates" `Quick test_slug_sexp;
- Alcotest.test_case "lang" `Quick test_lang ] )
+ Alcotest.test_case "lang" `Quick test_lang;
+ Alcotest.test_case "lang sexp validates" `Quick test_lang_sexp ] )