Skip to content

Commit

Permalink
khepri_utils: Use standard Erlang formatting for node names in displa…
Browse files Browse the repository at this point in the history
…yed 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.
  • Loading branch information
dumbbell committed Apr 25, 2022
1 parent 0af0732 commit d620618
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/khepri_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions test/db_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/display_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ display_tree_with_binary_key_test() ->
"├── bar\n"
"\033[38;5;246mData: bar_value\033[0m\n"
"\n"
"╰── <<foo>>\n"
"╰── <<\"foo\">>\n"
" \033[38;5;246mData: foo_value\033[0m\n"
"\n",
?capturedOutput),
Expand All @@ -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"
"╰── <<foo>>\n"
"╰── <<\"foo\">>\n"
" \033[38;5;246mData: foo_binary\033[0m\n"
"\n",
?capturedOutput),
Expand Down

0 comments on commit d620618

Please sign in to comment.