File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -318,7 +318,8 @@ def marshal_load(dumped_tree_array)
318318 #
319319 # @return [String] A string representation of the node.
320320 def to_s
321- "Node Name: #{ @name } Content: #{ @content . to_s || '<Empty>' } " \
321+ content_str = @content . nil? ? '<Empty>' : @content . to_s
322+ "Node Name: #{ @name } Content: #{ content_str } " \
322323 "Parent: #{ root? ? '<None>' : @parent . name . to_s } " \
323324 "Children: #{ @children . length } Total Nodes: #{ size } "
324325 end
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ def test_root_setup
9494 assert_not_nil ( @root . name , 'Name should not be nil' )
9595 assert_equal ( 'ROOT' , @root . name , "Name should be 'ROOT'" )
9696 assert_equal ( 'Root Node' , @root . content , "Content should be 'Root Node'" )
97+ assert ( @root . to_s . include? ( 'Content: Root Node' ) , 'to_s should include content value' )
9798 assert ( @root . root? , 'Should identify as root' )
9899 assert ( !@root . children? , 'Cannot have any children' )
99100 assert ( @root . content? , 'This root should have content' )
@@ -117,6 +118,11 @@ def test_root
117118 assert_equal ( 2 , @root . node_height , "Root's height after adding the children should be 2" )
118119 end
119120
121+ def test_to_s_empty_content
122+ empty = Tree ::TreeNode . new ( 'EMPTY' )
123+ assert_match ( /Content: <Empty>/ , empty . to_s )
124+ end
125+
120126 def test_from_hash
121127 # A
122128 # / | \
You can’t perform that action at this time.
0 commit comments