diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 11:33:12 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 11:33:12 +0200 |
| commit | 270be2561ae440cea814566b74712750352e56e4 (patch) | |
| tree | c8bad4daef33d1e2eaad7f90a4a03506b843e187 | |
| parent | ca289b2f43a5b097c4ec20308c1661a0c404399c (diff) | |
| download | colitur-270be2561ae440cea814566b74712750352e56e4.tar.gz colitur-270be2561ae440cea814566b74712750352e56e4.zip | |
test(kernel): cover Lang's sexp validation path
test_lang exercised only of_string. Add a sexp round-trip plus a
check_raises proving a malformed-but-plausible code ("e1": right length,
fails the lowercase rule) is rejected by t_of_sexp rather than silently
accepted -- mirrors test_slug_sexp's guard against a future regression to
[@@deriving sexp].
| -rw-r--r-- | test/test_slug.ml | 15 |
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 ] ) |
