Debian Codegraph @

testsuite/tests/lib-hashtbl/compatibility.ml

raw
1 (* TEST *)
2
3 let check_contents (h: (string, int) Hashtbl.t)
4 (expected: (string * int) list) =
5 List.iter
6 (fun (k, v) -> assert (Hashtbl.find_opt h k = Some v))
7 expected;
8 List.iter
9 (fun k -> assert (Hashtbl.find_opt h k = None))
10 [""; "n"; "no"; "non"; "none"];
11 Hashtbl.iter
12 (fun k v -> assert (List.assoc_opt k expected = Some v))
13 h
14
15 let check_failure (h: (string, int) Hashtbl.t) =
16 try
17 ignore (Hashtbl.find_opt h ""); assert false
18 with Invalid_argument _ ->
19 ()
20
21 let check_table supported h expected =
22 if supported
23 then check_contents h expected
24 else check_failure h;
25 check_contents (Hashtbl.rebuild h) expected
26
27 (* Hash table version 1, produced with OCaml 3.12.1 *)
28 let h1 : (string, int) Hashtbl.t =
29 Marshal.from_string
30 "\132\149\166\190\000\000\000/\000\000\000\n\000\000\000+\000\000\000)\
31 \160D\b\000\0004\000@@@@@\176%threeC@@@@\176#twoB@@@\176$fourD\176#oneA@"
32 0
33
34 (* Hash table version 2, produced with OCaml 4.09.0 *)
35 let h2 : (string, int) Hashtbl.t =
36 Marshal.from_string
37 "\132\149\166\190\000\000\000;\000\000\000\012\000\000\0008\000\000\0004\
38 \192E\b\000\000@\000@@@@@@@@@\176$septG\176#sixF@\176$cinqE@\176$neufI\
39 \176$huitH@@@@@@P"
40 0
41
42 let _ =
43 check_table false h1 ["one", 1; "two", 2; "three", 3; "four", 4];
44 check_table true h2 ["cinq", 5; "six", 6; "sept", 7; "huit", 8; "neuf", 9]