example.com -> example.org
[Seppo.git] / test / t_ezjsonm.ml
blob6a503354d5a8598c1d219a8b0ca5142c9850505c
2 let test_error () =
3 let j = {|not valid json|} |> Ezjsonm.from_string_result in
4 (match j with
5 | Error (`Error (((1,1),(1,3)),`Illegal_literal l)) ->
6 l |> Assrt.equals_string __LOC__ "not"
7 | _ -> failwith __LOC__);
8 (match j with
9 | Error e ->
11 |> Ezjsonm.read_error_description
12 |> Assrt.equals_string __LOC__ {|illegal literal (not)|}
13 | _ -> failwith __LOC__);
16 let test_constructing () =
19 ("id", `String "398eb027");
20 ("name", `String "John Doe");
21 ( "pages",
24 ("id", Ezjsonm.int 1); ("title", `String "The Art of Flipping Coins");
25 ] );
27 |> Ezjsonm.to_string ~minify:true
28 |> Assrt.equals_string __LOC__
29 "{\"id\":\"398eb027\",\"name\":\"John \
30 Doe\",\"pages\":{\"id\":1,\"title\":\"The Art of Flipping Coins\"}}"
32 let test_load_peertube () =
33 let extract3tries k0 k1 j =
34 match Ezjsonm.find j [ k0 ] with
35 | `String s -> Some s
36 | `A (`String s :: _) -> Some s
37 | `A ((`O _ as hd) :: _) -> (
38 (* ignore 'type' *)
39 match Ezjsonm.find hd [ k1 ] with `String s -> Some s | _ -> None)
40 | _ -> None
42 let ic = open_in "data/peertube-video.json" in
43 ic |> Ezjsonm.from_channel
44 |> extract3tries "attributedTo" "id"
45 |> Option.get |> Uri.of_string |> Uri.to_string
46 |> Assrt.equals_string __LOC__
47 "https://tube.network.europa.eu/accounts/edps";
48 close_in ic;
49 let ic = open_in "data/ap/actor/peertube.0.json" in
50 let _a = Ezjsonm.from_channel ic in
51 close_in ic;
52 assert true
54 let () =
55 Unix.chdir "../../../test/";
56 test_error ();
57 test_constructing ();
58 test_load_peertube ();
59 assert true