diff --git a/maigret/utils.py b/maigret/utils.py index aef05cb..e980a6c 100644 --- a/maigret/utils.py +++ b/maigret/utils.py @@ -84,14 +84,14 @@ def ascii_data_display(data: str) -> Any: def get_dict_ascii_tree(items, prepend="", new_line=True): new_result = b'\xe2\x94\x9c'.decode() - new_line = b'\xe2\x94\x80'.decode() + h_line = b'\xe2\x94\x80'.decode() last_result = b'\xe2\x94\x94'.decode() skip_result = b'\xe2\x94\x82'.decode() text = "" for num, item in enumerate(items): box_symbol = ( - new_result + new_line if num != len(items) - 1 else last_result + new_line + new_result + h_line if num != len(items) - 1 else last_result + h_line ) if isinstance(item, tuple): diff --git a/tests/test_utils.py b/tests/test_utils.py index 2a96c80..26ca1cd 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -233,3 +233,16 @@ def test_is_plausible_username_rejects_non_strings(): assert not is_plausible_username(None) assert not is_plausible_username(42) assert not is_plausible_username(["alice"]) + + +def test_get_dict_ascii_tree_new_line_false_strips_leading_newline(): + # new_line=False must drop the leading newline. It used to be a no-op + # because the parameter was shadowed by the horizontal box-drawing glyph. + items = [('a', '1'), ('b', '2')] + with_nl = get_dict_ascii_tree(items) + without_nl = get_dict_ascii_tree(items, new_line=False) + + assert with_nl.startswith('\n') + assert not without_nl.startswith('\n') + # Only the leading newline differs; the tree content is identical. + assert with_nl[1:] == without_nl