File: BitstringLetStarSyntaxTest.ml

package info (click to toggle)
ocaml-bitstring 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 908 kB
  • sloc: ml: 3,817; ansic: 136; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,641 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
open OUnit2

let ( let* ) = Option.bind
let ( let+ ) x f = Option.map f x

let ( and* ) a b =
  let* a = a in
  let+ b = b in
  a, b
;;

let ( and+ ) = ( and* )

let match_bits_with_let_star_syntax _ =
  (let* bits = Some (Bitstring.bitstring_of_string "U") in
   Some
     (match%bitstring bits with
     | {| hi: 4; lo: 4 |} -> assert_equal hi lo
     | {| _ |} -> assert_failure "Something wen't terribly wrong!"))
  |> ignore
;;

let match_bits_with_let_plus_syntax _ =
  (let+ bits = Some (Bitstring.bitstring_of_string "U") in
   match%bitstring bits with
   | {| hi: 4; lo: 4 |} -> assert_equal hi lo
   | {| _ |} -> assert_failure "Something wen't terribly wrong!")
  |> ignore
;;

let match_bits_with_and_star_syntax _ =
  (let* s = Some 5
   and* bits = Some (Bitstring.bitstring_of_string "U") in
   Some
     (match%bitstring bits with
     | {| hi: 4; lo: 4 |} -> assert_equal lo s
     | {| _ |} -> assert_failure "Something wen't terribly wrong!"))
  |> ignore
;;

let match_bits_with_and_plus_syntax _ =
  (let* s = Some 5
   and+ bits = Some (Bitstring.bitstring_of_string "U") in
   Some
     (match%bitstring bits with
     | {| hi: 4; lo: 4 |} -> assert_equal lo s
     | {| _ |} -> assert_failure "Something wen't terribly wrong!"))
  |> ignore
;;

let suite =
  "BitstringLetStarSyntaxTest"
  >::: [ "match_bits_with_let_star_syntax" >:: match_bits_with_let_star_syntax
       ; "match_bits_with_let_plus_syntax" >:: match_bits_with_let_plus_syntax
       ; "match_bits_with_and_star_syntax" >:: match_bits_with_and_star_syntax
       ; "match_bits_with_and_plus_syntax" >:: match_bits_with_and_plus_syntax
       ]
;;