--- /dev/null
+
+type base_type =
+ | B_int of int
+ | B_int64 of int64
+ | B_bool of bool
+ | B_string of string
+
+type simple_type =
+ | S_int_option of int option
+ | S_int64_option of int64 option
+ | S_bool_option of bool option
+ | S_string_option of string option
+
+ | S_int_list of int list
+ | S_bool_list of bool list
+ | S_int64_list of int64 list
+ | S_string_list of string list
+
+ | S_int_array of int array
+ | S_bool_array of bool array
+ | S_int64_array of int64 array
+ | S_string_array of string array
+
+type record_type =
+{
+ int: int;
+ int64: int64;
+ bool: bool;
+ string: string;
+
+ int_list: int list;
+ int64_option_array: (int64 option) array;
+ bool_array: bool array;
+
+ prod_list: ((int * bool) list) * string;
+}
+
+
+type complex_type1 = ((int list) * bool) array
+
+type complex_type2 =
+{
+ record: record_type;
+ complex_type1: complex_type1;
+}
--- /dev/null
+open Test_types
+open Test_types_json_conv
+
+
+let test_list to_j of_j o_list =
+ List.iter (fun t ->
+ let j = to_j t in
+ let o = of_j j in
+ (* Printf.printf "testing of_j(to_j(.) == . for %s\n" (Json.json_to_string j); *)
+ assert (o = t)
+ ) o_list;
+ let j_list = List.map to_j o_list in
+ List.iter (fun t ->
+ let o = of_j t in
+ let j = to_j o in
+ (* Printf.printf "testing to_j(of_j(.) == . for %s\n" (Json.json_to_string j); *)
+ assert (j = t)
+ ) j_list
+
+
+let check_base_type () =
+ let bs = [ B_int 3;
+ B_int64 1L;
+ B_bool false;
+ B_string "test"
+ ] in
+ test_list base_type_to_json base_type_of_json bs
+
+let check_simple_type () =
+ let ss = [ S_int_option None;
+ S_int_option (Some 2);
+ S_int64_option (Some 0L);
+ S_bool_option (Some true);
+ S_string_option (Some "tset");
+
+ S_int_list [ ];
+ S_int_list [ 3; 2; -1 ];
+ S_bool_list [ true; false; false; true; false ];
+ S_int64_list [ 1L; -3L; 2L; 5L];
+ S_string_list [ "iggy"; "franti"; "zappa" ];
+
+ S_int_array [| |];
+ S_int_array [| 1; 3; 2 |];
+ S_bool_array [| false; true; false; false; true |];
+ S_int64_array [| 1L; 3L; -2L; 5L |];
+ S_string_array [| "iggy"; "franti"; "zappa" |]
+ ] in
+ test_list simple_type_to_json simple_type_of_json ss
+
+let check_record_type () =
+ let rs = [ { int = 32;
+ int64 = 32L;
+ bool = false;
+ string = "record";
+
+ int_list = [ 0; 1; 2; -6; 4; 5];
+ int64_option_array = [| Some 0L; Some (-3L); None; Some (-1L); Some 5L |];
+ bool_array = [| false; true; false; false; true |];
+
+ prod_list = [ (1,false); (-23, true); (-1000, true) ], "prod"
+ } ] in
+ test_list record_type_to_json record_type_of_json rs
+
+let check_complex_type1 () =
+ let cs = [ [| |];
+ [| ([], true) |];
+ [| ([4; 3; 1], false); ([1; 3; 4], true) |];
+ ] in
+ test_list complex_type1_to_json complex_type1_of_json cs
+
+let check_complex_type2 () =
+ let cs = [ { record = { int = 32;
+ int64 = 32L;
+ bool = false;
+ string = "record";
+
+ int_list = [ 0; 1; 2; -6; 4; 5];
+ int64_option_array = [| Some 0L; Some (-3L); None; Some (-1L); Some 5L |];
+ bool_array = [| false; true; false; false; true |];
+
+ prod_list = [ (1,false); (-23, true); (-1000, true) ], "prod"
+ };
+ complex_type1 = [| ([4; 3; 1], false); ([1; 3; 4], true) |];
+ }
+ ] in
+ test_list complex_type2_to_json complex_type2_of_json cs
+
+let _ =
+ check_base_type ();
+ check_simple_type ();
+ check_record_type ();
+ check_complex_type1 ();
+ check_complex_type2 ()
+