File: Tests.ml

package info (click to toggle)
ocaml 5.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,384 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,419; asm: 5,462; makefile: 3,684; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (37 lines) | stat: -rw-r--r-- 1,404 bytes parent folder | download | duplicates (4)
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
33
34
35
36
37
(* TEST *)

(* Marshaling (cf. PR#5436) *)

(* Note: this test must *not* be made a toplevel or expect-style test,
   because then the Obj.id counter of the compiler implementation
   (called by the bytecode read-eval-print loop) would be the same as
   the Obj.id counter of the test code below. In particular, any
   change to the compiler implementation to use more objects or
   exceptions would change the numbers below, making the test very
   fragile. *)

let r = ref 0;;
let id o = Oo.id o - !r;;
r := Oo.id (object end);;

assert (id (object end) = 1);;
assert (id (object end) = 2);;
let o = object end in
  let s = Marshal.to_string o [] in
  let o' : < > = Marshal.from_string s 0 in
  let o'' : < > = Marshal.from_string s 0 in
  assert ((id o, id o', id o'') = (3, 4, 5));

let o = object val x = 33 method m = x end in
  let s = Marshal.to_string o [Marshal.Closures] in
  let o' : <m:int> = Marshal.from_string s 0 in
  let o'' : <m:int> = Marshal.from_string s 0 in
  assert ((id o, id o', id o'', o#m, o'#m)
          = (6, 7, 8, 33, 33));;

let o = object val x = 33 val y = 44 method m = x end in
  let s = Marshal.to_string (o,o) [Marshal.Closures] in
  let (o1, o2) : (<m:int> * <m:int>) = Marshal.from_string s 0 in
  let (o3, o4) : (<m:int> * <m:int>) = Marshal.from_string s 0 in
  assert ((id o, id o1, id o2, id o3, id o4, o#m, o1#m)
          = (9, 10, 10, 11, 11, 33, 33));;