@@ -115,4 +115,62 @@ class SpecializedTreeNode < Tree::TreeNode; end
115115 expect ( Marshal . load ( serialized_node2 ) ) . to be_a ( Tree ::TreeNode )
116116 end
117117 end
118+
119+ shared_examples_for "any cloned node" do
120+ it "is equal to the original" do
121+ expect ( @clone ) . to eq @tree
122+ end
123+ it "is not identical to the original" do
124+ expect ( clone ) . not_to be @tree
125+ end
126+ end
127+
128+ context "#detached_copy" , "without content" do
129+ before ( :each ) do
130+ @tree = Tree ::TreeNode . new ( "A" , nil )
131+ @clone = @tree . detached_copy
132+ end
133+
134+ it_behaves_like "any cloned node"
135+ end
136+
137+ context "#detached_copy" , "with clonable content" do
138+ before ( :each ) do
139+ @tree = Tree ::TreeNode . new ( "A" , "clonable content" )
140+ @clone = @tree . detached_copy
141+ end
142+
143+ it "makes a clone of the content" do
144+ expect ( @clone . content ) . to eq @tree . content
145+ expect ( @clone . content ) . not_to be @tree . content
146+ end
147+
148+ it_behaves_like "any cloned node"
149+ end
150+
151+ context "#detached_copy" , "with unclonable content" do
152+ before ( :each ) do
153+ @tree = Tree ::TreeNode . new ( "A" , :unclonable_content )
154+ @clone = @tree . detached_copy
155+ end
156+
157+ it "keeps the content" do
158+ expect ( @clone . content ) . to be @tree . content
159+ end
160+
161+ it_behaves_like "any cloned node"
162+ end
163+
164+ context "#detached_copy" , "with false as content" do
165+ before ( :each ) do
166+ @tree = Tree ::TreeNode . new ( "A" , false )
167+ @clone = @tree . detached_copy
168+ end
169+
170+ it "keeps the content" do
171+ expect ( @clone . content ) . to be @tree . content
172+ end
173+
174+ it_behaves_like "any cloned node"
175+ end
118176end
0 commit comments