File: 120-hv.ml

package info (click to toggle)
perl4caml 0.9.5-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 512 kB
  • ctags: 788
  • sloc: ml: 1,572; ansic: 957; makefile: 186; perl: 45
file content (27 lines) | stat: -rw-r--r-- 712 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(* Thoroughly test HV-related functions.
 * $Id: 120-hv.ml,v 1.1 2005/01/28 23:09:33 rich Exp $
 *)

open Perl

let () =
  let hv = hv_empty () in
  hv_set hv "foo" (sv_of_int 1);
  hv_set hv "bar" (sv_of_int 2);
  hv_set hv "foo" (sv_of_int 42);
  assert (42 = int_of_sv (hv_get hv "foo"));
  assert (2 = int_of_sv (hv_get hv "bar"));
  assert (hv_exists hv "foo");
  assert (not (hv_exists hv "baz"));
  hv_clear hv;
  assert (not (hv_exists hv "foo"));
  assert (not (hv_exists hv "bar"));

  ignore (eval "%h = ( foo => 1, bar => 2 )");
  let hv = get_hv "h" in
  assert (1 = int_of_sv (hv_get hv "foo"));
  assert (2 = int_of_sv (hv_get hv "bar"));
  assert (not (hv_exists hv "baz"));

;;
Gc.full_major ()