Skip to content

Commit b11d3be

Browse files
committed
Add print_tree IO support docs/tests (#69)
Capture print_tree IO support in History and add a print_tree_to_s test coverage entry alongside the IO-based print_tree test.
1 parent cb3e5a2 commit b11d3be

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

History.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
* Add `cmp` for traversal/relationship-based comparison without changing the
1717
name-based `<=>` semantics.
1818

19+
* Allow `print_tree` to write to a custom IO and add `print_tree_to_s` for
20+
string output.
21+
1922
### 2.2.1pre / 2026-02-07
2023

2124
* Simplified development dependency constraints while maintaining Ruby 2.7+

test/test_tree_traversal.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,14 @@ def test_collect
243243
def test_print_tree
244244
setup_test_tree
245245
buffer = StringIO.new
246-
@root.print_tree(0, nil, ->(node, prefix) { buffer.puts "#{prefix} #{node.name}" })
246+
@root.print_tree(0, nil, nil, io: buffer)
247247
assert(buffer.string.include?('ROOT'))
248248
end
249+
250+
def test_print_tree_to_s
251+
setup_test_tree
252+
output = @root.print_tree_to_s
253+
assert(output.include?('ROOT'))
254+
end
249255
end
250256
end

0 commit comments

Comments
 (0)