Added constructors.
[ocaml-bitstring.git] / tests / 10_constr1.ml
1 (* Test a simple constructor.
2  * $Id: 10_constr1.ml,v 1.1 2008-04-01 17:05:37 rjones Exp $
3  *)
4
5 let bits = BITSTRING 0xc : 4; 0xf : 4; 0xc : 4; 0xf : 4 ;;
6
7 assert (bits = Bitmatch.make_bitstring 16 '\xcf') ;;
8
9 let () =
10   bitmatch bits with
11   | n0 : 4; n1 : 4; n2 : 4; n3 : 4;
12     rest : -1 : bitstring ->
13       assert (n0 = 0xc);
14       assert (n1 = 0xf);
15       assert (n2 = 0xc);
16       assert (n3 = 0xf);
17
18       let _, off, len = rest in
19       assert (off = 16 && len = 0) (* no further data *)
20
21   | _ ->
22       failwith "error: did not match\n"