Stop using allocation trick in fastpath functions (OCaml 4.02).
[ocaml-bitstring.git] / tests / test_91_concat.ml
1 (* Regression test for bug in concatenation found by Phil Tomson.
2  * $Id$
3  *)
4
5 open Printf
6 open Bitstring
7
8 let errors = ref 0
9
10 let () =
11   let bs_256 = ones_bitstring 256 in
12   assert (bitstring_length bs_256 = 256);
13
14   let bs2 =
15     BITSTRING {
16       false : 1;
17       (subbitstring bs_256 0 66) : 66 : bitstring
18     } in
19   let len = bitstring_length bs2 in
20   if len <> 67 then (
21     eprintf "invalid length of bs2: len = %d, expected 67\n" len;
22     hexdump_bitstring stderr bs2;
23     incr errors
24   );
25
26   let bs3 =
27     BITSTRING {
28       false : 1;
29       (subbitstring bs_256 0 66) : 66 : bitstring;
30       (subbitstring bs_256 66 67) : 67 : bitstring
31     } in
32   let len = bitstring_length bs3 in
33   if len <> 134 then (
34     eprintf "invalid length of bs3: len = %d, expected 134\n" len;
35     hexdump_bitstring stderr bs3;
36     incr errors
37   );
38
39   let bs4 =
40     BITSTRING {
41       (subbitstring bs_256 66 67) : 67 : bitstring
42     } in
43   let len = bitstring_length bs4 in
44   if len <> 67 then (
45     eprintf "invalid length of bs4: len = %d, expected 67\n" len;
46     hexdump_bitstring stderr bs4;
47     incr errors
48   );
49
50   let bs5 = concat [subbitstring bs_256 0 66; subbitstring bs_256 66 67] in
51   let len = bitstring_length bs5 in
52   if len <> 133 then (
53     eprintf "invalid length of bs5: len = %d, expected 133\n" len;
54     hexdump_bitstring stderr bs5;
55     incr errors
56   );
57
58   let bs6 = concat [ subbitstring bs_256 0 64; subbitstring bs_256 64 64] in
59   let len = bitstring_length bs6 in
60   if len <> 128 then (
61     eprintf "invalid length of bs6: len = %d, expected 128\n" len;
62     hexdump_bitstring stderr bs6;
63     incr errors
64   );
65
66   let bs7 = concat [ subbitstring bs_256 0 65; subbitstring bs_256 65 64] in
67   let len = bitstring_length bs7 in
68   if len <> 129 then (
69     eprintf "invalid length of bs7: len = %d, expected 129\n" len;
70     hexdump_bitstring stderr bs7;
71     incr errors
72   );
73
74   if !errors <> 0 then exit 1