From d620618ab8c5cf5217929eeff77dbb70e6fc9901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 25 Apr 2022 10:47:54 +0200 Subject: [PATCH] khepri_utils: Use standard Erlang formatting for node names in displayed tree The code used to use the same syntax as Unix-like paths. This syntax was modified, but anyway, it makes more sense in the context of `khepri:info/1` to present the actual Erlang types, not the Unix-like path representation. This tool is useful to developers and is not made for end-users. --- src/khepri_utils.erl | 6 ++---- test/db_info.erl | 6 +++--- test/display_tree.erl | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/khepri_utils.erl b/src/khepri_utils.erl index ada6da12..ff90e830 100644 --- a/src/khepri_utils.erl +++ b/src/khepri_utils.erl @@ -113,10 +113,8 @@ display_node_branch(Key, false, Prefix, _Options) -> display_node_branch(Key, true, Prefix, _Options) -> io:format("~ts╰── ~ts~n", [Prefix, format_key(Key)]). -format_key(Key) when is_atom(Key) -> - io_lib:format("~ts", [Key]); -format_key(Key) when is_binary(Key) -> - io_lib:format("<<~ts>>", [Key]). +format_key(Key) -> + io_lib:format("~0p", [Key]). display_data(Data, Prefix, Options) -> Formatted = format_data(Data, Options), diff --git a/test/db_info.erl b/test/db_info.erl index b72d715d..0f5bdaf1 100644 --- a/test/db_info.erl +++ b/test/db_info.erl @@ -78,8 +78,8 @@ get_store_info_on_running_store_test_() -> fun() -> test_ra_server_helpers:setup(?FUNCTION_NAME) end, fun(Priv) -> test_ra_server_helpers:cleanup(Priv) end, [?_assertEqual( - {ok, #{[foo, bar] => #{}}}, - khepri:create(?FUNCTION_NAME, [foo, bar], bar_value)), + {ok, #{[foo, <<"bar">>] => #{}}}, + khepri:create(?FUNCTION_NAME, [foo, <<"bar">>], bar_value)), ?_assertEqual( {ok, #{[baz] => #{}}}, khepri:create(?FUNCTION_NAME, [baz], baz_value)), @@ -96,7 +96,7 @@ get_store_info_on_running_store_test_() -> "│ \033[38;5;246mData: baz_value\033[0m\n" "│\n" "╰── foo\n" - " ╰── bar\n" + " ╰── <<\"bar\">>\n" " \033[38;5;246mData: bar_value\033[0m\n" "\n", begin diff --git a/test/display_tree.erl b/test/display_tree.erl index 53a1f22b..7189ad79 100644 --- a/test/display_tree.erl +++ b/test/display_tree.erl @@ -624,7 +624,7 @@ display_tree_with_binary_key_test() -> "├── bar\n" "│ \033[38;5;246mData: bar_value\033[0m\n" "│\n" - "╰── <>\n" + "╰── <<\"foo\">>\n" " \033[38;5;246mData: foo_value\033[0m\n" "\n", ?capturedOutput), @@ -649,7 +649,7 @@ display_tree_with_similar_atom_and_binary_keys_test() -> "├── foo\n" "│ \033[38;5;246mData: foo_atom\033[0m\n" "│\n" - "╰── <>\n" + "╰── <<\"foo\">>\n" " \033[38;5;246mData: foo_binary\033[0m\n" "\n", ?capturedOutput),