File: 100-sv.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 (32 lines) | stat: -rw-r--r-- 1,116 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
28
29
30
31
32
(* Thoroughly test SV-related functions.
 * $Id: 100-sv.ml,v 1.1 2005/01/28 23:09:33 rich Exp $
 *)

open Perl

let () =
  assert (42 = int_of_sv (sv_of_int 42));
  assert (42. = float_of_sv (sv_of_float 42.));
  assert (true = bool_of_sv (sv_of_bool true));
  assert (false = bool_of_sv (sv_of_bool false));
  assert ("42" = string_of_sv (sv_of_string "42"));
  assert ("42" = string_of_sv (sv_of_int 42));
  assert ("1" = string_of_sv (sv_of_bool true));
  (* assert ("" = string_of_sv (sv_of_bool false)); XXX fails XXX *)
  assert (sv_is_true (sv_of_bool true));
  assert (sv_is_true (sv_true ()));
  assert (not (sv_is_true (sv_false ())));
  assert (sv_is_undef (sv_undef ()));

  let sv = sv_undef () in assert (sv_type sv = SVt_NULL);
  let sv = sv_of_int 42 in assert (sv_type sv = SVt_IV);
  (* let sv = sv_of_float 42.1 in assert (sv_type sv = SVt_NV); XXX fails XXX*)
  let sv = sv_of_string "42" in assert (sv_type sv = SVt_PV);
  let sv = eval "\\\"foo\"" in assert (sv_type sv = SVt_RV);

  ignore (eval "$s = 'foo'");
  let sv = get_sv "s" in
  assert ("foo" = string_of_sv sv);
;;

Gc.full_major ()