File Tree: fix the manual test printing of nested structure
Rafael Uzarowski committed
Nov 9, 2025 at 22:08 UTC
44b6394792b6f246b44c1466f9769bb25f206fd2
1 file changed
+14
-3
tests/test_file_tree_visualize.py
+14
-3
@@ -92,9 +92,20 @@ def print_flat(items: List[Dict[str, Any]]) -> None:
92
93
def print_nested(items: List[Dict[str, Any]], root_label: str) -> None:
94
print(root_label)
95
- for item in items:
96
- text = item["text"]
97
- print(f"{text} [{item['type']}]")
95
+
96
+ def recurse(nodes: List[Dict[str, Any]], prefix: str) -> None:
97
+ total = len(nodes)
98
+ for index, node in enumerate(nodes):
99
+ is_last = index == total - 1
100
+ connector = "└── " if is_last else "├── "
101
+ label = node["name"] + ("/" if node["type"] == "folder" else "")
102
+ print(f"{prefix}{connector}{label} [{node['type']}]")
103
+ children = node.get("items") or []
104
+ if children:
105
+ child_prefix = prefix + (" " if is_last else "│ ")
106
+ recurse(children, child_prefix)
107
+
108
+ recurse(items, "")
109
110
111
@contextmanager