File tree Expand file tree Collapse file tree
Containers-KeyedTree-Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -215,6 +215,29 @@ CTKeyedTreeTest >> testCopy [
215215 self assert: (c includesKey: #new )
216216]
217217
218+ { #category : ' tests' }
219+ CTKeyedTreeTest >> testDeepCopyStateNotShared [
220+ | original clone |
221+ original := CTKeyedTree new
222+ at: #config put: (CTKeyedTree new
223+ at: #color put: ' red' ;
224+ yourself );
225+ yourself .
226+
227+ clone := original copy.
228+
229+ " Verify they have equal values but are different objects in memory before mutation"
230+ self assert: original equals: clone.
231+ self deny: original == clone.
232+
233+ (clone at: #config ) at: #color put: ' blue' .
234+
235+ self assert: (original atPath: #(config color) ) equals: ' red' .
236+ self assert: (clone atPath: #(config color) ) equals: ' blue' .
237+
238+ self deny: (original at: #config ) == (clone at: #config ).
239+ ]
240+
218241{ #category : ' tests' }
219242CTKeyedTreeTest >> testDepth [
220243
Original file line number Diff line number Diff line change @@ -268,21 +268,6 @@ CTKeyedTree >> collect: aBlock [
268268 ^ result
269269]
270270
271- { #category : ' copying' }
272- CTKeyedTree >> copy [
273-
274- " Answer a deep copy of the receiver including all subtrees."
275-
276- | result |
277- result := self species new .
278- self keysAndValuesDo: [ :key :value |
279- result at: key put: (
280- (value isKindOf: self class )
281- ifTrue: [ value copy ]
282- ifFalse: [ value ] ) ].
283- ^ result
284- ]
285-
286271{ #category : ' accessing' }
287272CTKeyedTree >> depth [
288273
@@ -496,16 +481,10 @@ CTKeyedTree >> pathsAndValuesDo: aBlock currentPath: pathArray [
496481
497482{ #category : ' copying' }
498483CTKeyedTree >> postCopy [
499-
500- " Ensure proper deep copying of associations and subtrees."
501484
502- array := array collect: [ :assoc |
503- assoc ifNotNil: [
504- Association
505- key: assoc key
506- value: ((assoc value isKindOf: self class )
507- ifTrue: [ assoc value copy ]
508- ifFalse: [ assoc value ]) ] ]
485+ super postCopy.
486+ self keysAndValuesDo: [ :key :value |
487+ self at: key put: value copy ]
509488]
510489
511490{ #category : ' printing' }
You can’t perform that action at this time.
0 commit comments