(* JSONB values (jsonb.html, section 3): one constructor per element type,
so equality tells the types apart and the printer shows each payload. *)
module V = Sql.Jsonb.Value
let test_equal () =
Alcotest.(check bool) "INT and INT5" false (V.equal (Int "1") (Int5 "0x1"));
Alcotest.(check bool)
"the same text" true
(V.equal (Float "1.50") (Float "1.50"));
Alcotest.(check bool)
"TEXT and TEXTRAW" false
(V.equal (Text "a") (Textraw "a"));
Alcotest.(check bool)
"member order" false
(V.equal
(Object [ (Text "a", Null); (Text "b", True) ])
(Object [ (Text "b", True); (Text "a", Null) ]))
let test_sort () =
Alcotest.(check string)
"Float5" "float5"
(Sql.Jsonb.Sort.to_string (V.sort (Float5 ".5")));
Alcotest.(check string)
"Object" "object"
(Sql.Jsonb.Sort.to_string (V.sort (Object [])))
let test_pp () =
Alcotest.(check string)
"pp" {|[1, "a", {"b": null}, 0x1F, "q\"x"]|}
(Fmt.str "%a" V.pp
(Array
[
Int "1";
Text "a";
Object [ (Text "b", Null) ];
Int5 "0x1F";
Textraw "q\"x";
]))
let suite =
( "jsonb_value",
[
Alcotest.test_case "equal" `Quick test_equal;
Alcotest.test_case "sort" `Quick test_sort;
Alcotest.test_case "pp" `Quick test_pp;
] )