Fix documentation for how to compile using camlp4 directly.
[ocaml-bitstring.git] / tests / 61_offset_string.ml
1 (* Offset string.  The rotation functions used for strings are
2  * very complicated so this is worth testing separately.
3  * $Id: 50_named_pattern.ml 86 2008-06-13 15:56:04Z richard.wm.jones $
4  *)
5
6 open Printf
7 open Bitmatch
8
9 let make_bits si n sj m sk = (
10   let pad1 = ones_bitstring (n-64) in
11   let pad2 = ones_bitstring (m-n-8) in
12   BITSTRING {
13     si : 64 : string;
14     pad1 : n-64 : bitstring;
15     sj : 8 : string;                 (* this should be at offset(n) *)
16     pad2 : m-n-8 : bitstring;
17     sk : 64 : string                 (* this should be at offset(m) *)
18   }
19 )
20
21 let test_bits bits si n sj m sk =
22   bitmatch bits with
23   | { si' : 64 : string;
24       sj' : 8 : string, offset(n);
25       sk' : 64 : string, offset(m) }
26       when si = si' && sj = sj' && sk = sk' -> () (* ok *)
27   | { _ } ->
28       failwith (sprintf "61_offset_string: test_bits: failed %S %d %S %d %S"
29                   si n sj m sk)
30
31 let () =
32   for n = 64 to 128 do
33     for m = n+8 to 256 do
34       List.iter (fun (si,sj,sk) ->
35                    test_bits (make_bits si n sj m sk) si n sj m sk)
36         ["ABCDEFGH", "x", "HGFEDCBA";
37          "01234567", "0", "76543210";
38          "abcdefgh", "\x55", "poiuytre"]
39     done;
40   done