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
]
;;
|