readme
[Seppo.git] / test / t_sexp.ml
bloba2643b5a1de0cb289d104a42faeed938f66c8015
2 open Lib
4 type entry = {
5 name : string;
6 country : string option;
7 email : string option
9 (* [@@deriving sexp] *)
11 (* https://gitlab.inria.fr/bmontagu/sexp_decode
12 via https://discuss.ocaml.org/t/combinator-library-for-extracting-data-for-s-exps/10153/5 *)
13 let test_sexp_a () =
14 let open Sexp_decode in
15 Logr.info (fun m -> m "test_sexp_a");
16 let entry_decoder : entry decoder =
17 field "entry"
18 @@ let* name = field "name" atom in
19 let* country = maybe @@ field "country" atom in
20 let+ email = maybe @@ field "email" atom in
21 { name; country; email } in
22 let address_book_decoder (* : address_book decoder *) = list entry_decoder in
23 let _r = run address_book_decoder (Atom "a") in
24 Assrt.equals_string __LOC__ "a" "a";
25 assert true
27 module D = Decoders_ezjsonm.Decode
29 (* https://discuss.ocaml.org/t/combinator-library-for-extracting-data-for-s-exps/10153 *)
30 let test_decoders () =
31 let open D in
32 let _announce : entry decoder =
33 let* _ = field "type" string
34 and* name = field "actor" string in
35 succeed ({name; country = None; email = None;})
37 let r = (D.decode_string (_announce ) "((type "") (actor uhu))")
38 |> Result.get_ok in
39 r.name
40 |> Assrt.equals_string __LOC__ "u"
42 let () =
43 Unix.chdir "../../../test/";
44 test_sexp_a ();
45 test_decoders ();
46 assert true