3587b4ad8c8b98eda725a522274b944bebe8c5dc
[ocaml-bitstring.git] / tests / 06_ints2.ml
1 (* Extract some simple integers.
2  * $Id: 06_ints2.ml,v 1.2 2008-04-25 11:08:43 rjones Exp $
3  *)
4
5 let bits = Bitmatch.make_bitstring 16 '\xcf' (* makes the string 0xcfcf *)
6
7 let () =
8   bitmatch bits with
9   | { n0 : 2; n1 : 2; n2 : 2; n3 : 2; n4 : 2; n5 : 2; n6 : 2; n7 : 2;
10       rest : -1 : bitstring } ->
11       assert (n0 = 0x3); (* 0xc *)
12       assert (n1 = 0x0);
13       assert (n2 = 0x3); (* 0xf *)
14       assert (n3 = 0x3);
15       assert (n4 = 0x3); (* 0xc *)
16       assert (n5 = 0x0);
17       assert (n6 = 0x3); (* 0xf *)
18       assert (n7 = 0x3);
19
20       let _, off, len = rest in
21       assert (off = 16 && len = 0) (* no further data *)
22
23   | { _ } ->
24       failwith "error: did not match\n"