A CLI and OCaml library for managing contacts
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** Schema-only tests (no I/O dependencies) *)
7
8let test_temporal () =
9 (* Parse dates from strings *)
10 let from_date = Sortal_schema.Temporal.parse_date_string "2020-01" |> Option.get in
11 let until_date = Sortal_schema.Temporal.parse_date_string "2023-12" |> Option.get in
12 let test_date_1 = Sortal_schema.Temporal.parse_date_string "2021-06" |> Option.get in
13 let test_date_2 = Sortal_schema.Temporal.parse_date_string "2024-01" |> Option.get in
14
15 let r = Sortal_schema.Temporal.make ~from:from_date ~until:until_date () in
16 assert (Sortal_schema.Temporal.valid_at (Some r) ~date:test_date_1);
17 assert (not (Sortal_schema.Temporal.valid_at (Some r) ~date:test_date_2));
18 print_endline "✓ Temporal ranges work"
19
20let test_feed_types () =
21 let feed = Sortal_schema.Feed.make ~feed_type:Atom ~url:"https://example.com/feed" () in
22 assert (Sortal_schema.Feed.url feed = "https://example.com/feed");
23 print_endline "✓ Feed types work"
24
25let test_contact_construction () =
26 let c = Sortal_schema.Contact.make
27 ~handle:"test"
28 ~names:["Test User"]
29 ~emails:[Sortal_schema.Contact.email_of_string "test@example.com"]
30 () in
31 assert (Sortal_schema.Contact.handle c = "test");
32 assert (Sortal_schema.Contact.name c = "Test User");
33 print_endline "✓ Contact construction works"
34
35let test_json_roundtrip () =
36 let c = Sortal_schema.Contact.make ~handle:"json" ~names:["JSON Test"] () in
37 match Jsont_bytesrw.encode_string Sortal_schema.Contact.json_t c with
38 | Ok json ->
39 (match Jsont_bytesrw.decode_string Sortal_schema.Contact.json_t json with
40 | Ok decoded ->
41 assert (Sortal_schema.Contact.handle decoded = "json");
42 assert (Sortal_schema.Contact.name decoded = "JSON Test");
43 print_endline "✓ JSON roundtrip works"
44 | Error e -> failwith ("Decode failed: " ^ e))
45 | Error e -> failwith ("Encode failed: " ^ e)
46
47let () =
48 print_endline "\n=== Schema Tests ===\n";
49 test_temporal ();
50 test_feed_types ();
51 test_contact_construction ();
52 test_json_roundtrip ();
53 print_endline "\n=== All Schema Tests Passed ===\n"