Fix svnignore in the examples subdirectory.
[ocaml-bitstring.git] / tests / 05_bits.ml
1 (* Extract bits.
2  * $Id: 05_bits.ml,v 1.3 2008-04-25 11:08:43 rjones Exp $
3  *)
4
5 let bits = Bitmatch.make_bitstring 24 '\x5a' (* makes the string 0x5a5a5a *)
6
7 let () =
8   bitmatch bits with
9   | { b0  : 1; b1  : 1; b2  : 1; b3  : 1; b4  : 1; b5  : 1; b6  : 1; b7  : 1;
10       b8  : 1; b9  : 1; b10 : 1; b11 : 1; b12 : 1; b13 : 1; b14 : 1; b15 : 1;
11       b16 : 1; b17 : 1; b18 : 1; b19 : 1; b20 : 1; b21 : 1; b22 : 1; b23 : 1;
12       rest : -1 : bitstring } ->
13       assert (not b0 && b1 && not b2 && b3 && (* 0x5 *)
14                 b4 && not b5 && b6 && not b7); (* 0xA *)
15       assert (not b8 && b9 && not b10 && b11 && (* 0x5 *)
16                 b12 && not b13 && b14 && not b15); (* 0xA *)
17       assert (not b16 && b17 && not b18 && b19 && (* 0x5 *)
18                 b20 && not b21 && b22 && not b23); (* 0xA *)
19       let _, off, len = rest in
20       assert (off = 24 && len = 0) (* no further data *)
21
22   | { _ } ->
23       failwith "error: did not match\n"