Use newSVnv in sv_of_float to stop it truncating the float to an int.
[perl4caml.git] / test / 120-hv.ml
1 (* Thoroughly test HV-related functions.
2  * $Id: 120-hv.ml,v 1.1 2005-01-28 23:09:33 rich Exp $
3  *)
4
5 open Perl
6
7 let () =
8   let hv = hv_empty () in
9   hv_set hv "foo" (sv_of_int 1);
10   hv_set hv "bar" (sv_of_int 2);
11   hv_set hv "foo" (sv_of_int 42);
12   assert (42 = int_of_sv (hv_get hv "foo"));
13   assert (2 = int_of_sv (hv_get hv "bar"));
14   assert (hv_exists hv "foo");
15   assert (not (hv_exists hv "baz"));
16   hv_clear hv;
17   assert (not (hv_exists hv "foo"));
18   assert (not (hv_exists hv "bar"));
19
20   ignore (eval "%h = ( foo => 1, bar => 2 )");
21   let hv = get_hv "h" in
22   assert (1 = int_of_sv (hv_get hv "foo"));
23   assert (2 = int_of_sv (hv_get hv "bar"));
24   assert (not (hv_exists hv "baz"));
25
26 ;;
27 Gc.full_major ()