ezjsonm_test.ml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. let test_constructing () =
  2. `O
  3. [
  4. ("id", `String "398eb027");
  5. ("name", `String "John Doe");
  6. ( "pages",
  7. `O
  8. [
  9. ("id", Ezjsonm.int 1); ("title", `String "The Art of Flipping Coins");
  10. ] );
  11. ]
  12. |> Ezjsonm.to_string ~minify:true
  13. |> Assrt.equals_string __LOC__
  14. "{\"id\":\"398eb027\",\"name\":\"John \
  15. Doe\",\"pages\":{\"id\":1,\"title\":\"The Art of Flipping Coins\"}}"
  16. let test_load_peertube () =
  17. let extract3tries k0 k1 j =
  18. match Ezjsonm.find j [ k0 ] with
  19. | `String s -> Some s
  20. | `A (`String s :: _) -> Some s
  21. | `A ((`O _ as hd) :: _) -> (
  22. (* ignore 'type' *)
  23. match Ezjsonm.find hd [ k1 ] with `String s -> Some s | _ -> None)
  24. | _ -> None
  25. in
  26. let ic = open_in "data/peertube-video.json" in
  27. ic |> Ezjsonm.from_channel
  28. |> extract3tries "attributedTo" "id"
  29. |> Option.get |> Uri.of_string |> Uri.to_string
  30. |> Assrt.equals_string __LOC__
  31. "https://tube.network.europa.eu/accounts/edps";
  32. close_in ic;
  33. let ic = open_in "data/ap/actor/peertube.0.json" in
  34. let _a = Ezjsonm.from_channel ic in
  35. close_in ic;
  36. assert true
  37. let () =
  38. Unix.chdir "../../../test/";
  39. test_constructing ();
  40. test_load_peertube ();
  41. assert true