diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 11:15:18 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 11:15:18 +0200 |
| commit | d532c3b2cf941d2fe0c3c84f2c4090f14e869ef0 (patch) | |
| tree | ba8f4bb56157989d5874ede8ae463a36812c0001 /test/test_date.ml | |
| parent | 1d6b9a540a50159221e0475bc1c1c2387d417622 (diff) | |
| download | colitur-d532c3b2cf941d2fe0c3c84f2c4090f14e869ef0.tar.gz colitur-d532c3b2cf941d2fe0c3c84f2c4090f14e869ef0.zip | |
kernel(date): ISO-8601 rendering, validating parse, sexp converters
Adds sexplib and ppx_sexp_conv to the project and wires the ppx into the
kernel library. Date's sexp form is an ISO-8601 atom rather than the opaque
rata die, so data files stay human-editable and parsing revalidates the
1583..9999 domain.
Diffstat (limited to 'test/test_date.ml')
| -rw-r--r-- | test/test_date.ml | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/test/test_date.ml b/test/test_date.ml index 2458659..e3c2dfb 100644 --- a/test/test_date.ml +++ b/test/test_date.ml @@ -52,11 +52,28 @@ let prop_weekday_cycle = QCheck.Test.make ~name:"weekday(add_days d 7) = weekday d" arb_date (fun d -> D.weekday (D.add_days d 7) = D.weekday d) +let test_iso8601 () = + Alcotest.(check string) "to_iso8601" "2026-04-05" (D.to_iso8601 (mk 2026 4 5)); + (match D.of_iso8601 "2026-04-05" with + | Ok d -> Alcotest.(check int) "of_iso8601 roundtrip" 0 (D.compare d (mk 2026 4 5)) + | Error e -> Alcotest.failf "of_iso8601: %s" e); + Alcotest.(check bool) "reject garbage" true (Result.is_error (D.of_iso8601 "nope")); + Alcotest.(check bool) "reject 2026-02-30" true (Result.is_error (D.of_iso8601 "2026-02-30")) + +let test_date_sexp () = + let d = mk 2026 4 5 in + Alcotest.(check string) "sexp_of_t" "2026-04-05" (Sexplib.Sexp.to_string (D.sexp_of_t d)); + Alcotest.(check int) "t_of_sexp roundtrip" 0 + (D.compare (D.t_of_sexp (D.sexp_of_t d)) d); + Alcotest.(check string) "weekday_to_string" "sunday" (D.weekday_to_string (D.weekday d)) + let suite = ( "Date", [ Alcotest.test_case "weekday" `Quick test_weekday; Alcotest.test_case "roundtrip" `Quick test_roundtrip; Alcotest.test_case "add_days boundaries" `Quick test_add_days; - Alcotest.test_case "make rejects invalid" `Quick test_make_reject ] + Alcotest.test_case "make rejects invalid" `Quick test_make_reject; + Alcotest.test_case "iso8601" `Quick test_iso8601; + Alcotest.test_case "sexp" `Quick test_date_sexp ] @ List.map QCheck_alcotest.to_alcotest [ prop_roundtrip; prop_add_inverse; prop_weekday_cycle ] ) |
