Fix one hex printing bug

This commit is contained in:
Tom Jack 2019-12-19 13:02:45 -06:00
parent a59499e4bc
commit 71e2670572
3 changed files with 12 additions and 4 deletions

View File

@ -188,10 +188,14 @@ let literal ppf (l:literal) = match l with
| Literal_timestamp n -> fprintf ppf "+%d" n | Literal_timestamp n -> fprintf ppf "+%d" n
| Literal_mutez n -> fprintf ppf "%dmutez" n | Literal_mutez n -> fprintf ppf "%dmutez" n
| Literal_string s -> fprintf ppf "%S" s | Literal_string s -> fprintf ppf "%S" s
| Literal_bytes b -> fprintf ppf "0x%s" @@ Bytes.to_string @@ Bytes.escaped b | Literal_bytes b -> fprintf ppf "0x%a" Hex.pp (Hex.of_bytes b)
| Literal_address s -> fprintf ppf "@%S" s | Literal_address s -> fprintf ppf "@%S" s
| Literal_operation _ -> fprintf ppf "Operation(...bytes)" | Literal_operation _ -> fprintf ppf "Operation(...bytes)"
| Literal_key s -> fprintf ppf "key %s" s | Literal_key s -> fprintf ppf "key %s" s
| Literal_key_hash s -> fprintf ppf "key_hash %s" s | Literal_key_hash s -> fprintf ppf "key_hash %s" s
| Literal_signature s -> fprintf ppf "Signature %s" s | Literal_signature s -> fprintf ppf "Signature %s" s
| Literal_chain_id s -> fprintf ppf "Chain_id %s" s | Literal_chain_id s -> fprintf ppf "Chain_id %s" s
let%expect_test _ =
Format.printf "%a" literal (Literal_bytes (Bytes.of_string "foo")) ;
[%expect{| 0x666f6f |}]

View File

@ -5,8 +5,9 @@
simple-utils simple-utils
tezos-utils tezos-utils
) )
(inline_tests)
(preprocess (preprocess
(pps ppx_let) (pps ppx_let ppx_expect)
) )
(flags (:standard -open Simple_utils)) (flags (:standard -open Simple_utils))
) )

View File

@ -58,8 +58,7 @@ let rec value ppf : value -> unit = function
| D_unit -> fprintf ppf "unit" | D_unit -> fprintf ppf "unit"
| D_string s -> fprintf ppf "\"%s\"" s | D_string s -> fprintf ppf "\"%s\"" s
| D_bytes x -> | D_bytes x ->
let (`Hex hex) = Hex.of_bytes x in fprintf ppf "0x%a" Hex.pp @@ Hex.of_bytes x
fprintf ppf "0x%s" hex
| D_pair (a, b) -> fprintf ppf "(%a), (%a)" value a value b | D_pair (a, b) -> fprintf ppf "(%a), (%a)" value a value b
| D_left a -> fprintf ppf "L(%a)" value a | D_left a -> fprintf ppf "L(%a)" value a
| D_right b -> fprintf ppf "R(%a)" value b | D_right b -> fprintf ppf "R(%a)" value b
@ -124,6 +123,10 @@ let tl_statement ppf (ass, _) = assignment ppf ass
let program ppf (p:program) = let program ppf (p:program) =
fprintf ppf "Program:\n---\n%a" (pp_print_list ~pp_sep:pp_print_newline tl_statement) p fprintf ppf "Program:\n---\n%a" (pp_print_list ~pp_sep:pp_print_newline tl_statement) p
let%expect_test _ =
Format.printf "%a" value (D_bytes (Bytes.of_string "foo")) ;
[%expect{| 0x666f6f |}]
let%expect_test _ = let%expect_test _ =
let pp = expression' Format.std_formatter in let pp = expression' Format.std_formatter in
let dummy_type = T_base Base_unit in let dummy_type = T_base Base_unit in