diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index 411681a2a..05d192911 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -188,10 +188,14 @@ let literal ppf (l:literal) = match l with | Literal_timestamp n -> fprintf ppf "+%d" n | Literal_mutez n -> fprintf ppf "%dmutez" n | 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_operation _ -> fprintf ppf "Operation(...bytes)" | Literal_key s -> fprintf ppf "key %s" s | Literal_key_hash s -> fprintf ppf "key_hash %s" s | Literal_signature s -> fprintf ppf "Signature %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 |}] diff --git a/src/stages/common/dune b/src/stages/common/dune index 35a886824..c607b6041 100644 --- a/src/stages/common/dune +++ b/src/stages/common/dune @@ -5,8 +5,9 @@ simple-utils tezos-utils ) + (inline_tests) (preprocess - (pps ppx_let) + (pps ppx_let ppx_expect) ) (flags (:standard -open Simple_utils)) ) diff --git a/src/stages/mini_c/PP.ml b/src/stages/mini_c/PP.ml index 9e6ee6049..054d88cb9 100644 --- a/src/stages/mini_c/PP.ml +++ b/src/stages/mini_c/PP.ml @@ -58,8 +58,7 @@ let rec value ppf : value -> unit = function | D_unit -> fprintf ppf "unit" | D_string s -> fprintf ppf "\"%s\"" s | D_bytes x -> - let (`Hex hex) = Hex.of_bytes x in - fprintf ppf "0x%s" hex + fprintf ppf "0x%a" Hex.pp @@ Hex.of_bytes x | D_pair (a, b) -> fprintf ppf "(%a), (%a)" value a value b | D_left a -> fprintf ppf "L(%a)" value a | 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) = 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 pp = expression' Format.std_formatter in let dummy_type = T_base Base_unit in