[squeak-dev] The Trunk: CollectionsTests-dtl.214.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Jan 20 17:00:56 UTC 2014


David T. Lewis uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-dtl.214.mcz

==================== Summary ====================

Name: CollectionsTests-dtl.214
Author: dtl
Time: 20 January 2014, 12:00:28.852 pm
UUID: cf157d3a-2d71-46f3-86ce-450ee24e8d27
Ancestors: CollectionsTests-dtl.213

Update comment for WriteStreamTest>>testStreamContentsPositioning and add check to ensure that the expected optimization occurs (to prevent future regressions).

=============== Diff against CollectionsTests-dtl.213 ===============

Item was changed:
  ----- Method: WriteStreamTest>>testStreamContentsPositioning (in category 'tests - positioning') -----
  testStreamContentsPositioning
  	"String class>>new:streamContents: optimizes performance by answering the
  	originalCollection in the case of a stream positioned to the size of the original
+ 	collection. Verify that the optimization is performed if and only if the result string
+ 	is the original stream colllection. In particular, ensure that positioning the stream
+ 	backwards to the original collection size prooduces the expected result."
- 	collection. This fails if the stream has been repositioned backwards to its original
- 	length."
  
  	"(OrderedCollectionTest selector: #testStreamContentsPositioning) debug"
  
+ 	| s s1 s2 |
- 	| s |
  	s := String new: 10 streamContents: [ :strm |
  			strm nextPutAll: 'XXXXX'.
  			self assert: 'XXXXX' equals: strm contents.
  			strm nextPut: $X.
  			self assert: 'XXXXXX' equals: strm contents.
  			strm position: strm position - 1.
  			self assert: 'XXXXX' equals: strm contents.
  			strm nextPutAll: 'XXXXX'.
  			self assert: 'XXXXXXXXXX' equals: strm contents.
  			strm nextPut: $X.
  			self assert: 'XXXXXXXXXXX' equals: strm contents.
  			strm position: strm position - 1.
  			self assert: 'XXXXXXXXXX' equals: strm contents.
  		].
  	self assert: 10 equals: s size.
  	self assert: 'XXXXXXXXXX' equals: s.
+ 
+ 	"Verify that the performance optimization in #new:streamContents: is happening"
+ 	s2 := String new: s size streamContents: [ :strm |
+ 		s1 := strm originalContents.
+ 		strm nextPutAll: s ].
+ 	self assert: s equals: s2.
+ 	self assert: s equals: s1.
+ 	self assert: s1 == s2. "answer the original collection in this case only"
+ 
+ 	s2 := String new: s size - 1 streamContents: [ :strm |
+ 		s1 := strm originalContents.
+ 		strm nextPutAll: s ].
+ 	self assert: s equals: s2.
+ 	self deny: s1 == s2. "normal case, contents not matching original stream collection"
+ 
+ 	s2 := String new: s size - 2 streamContents: [ :strm |
+ 		s1 := strm originalContents.
+ 		strm nextPutAll: s ].
+ 	self assert: s equals: s2.
+ 	self deny: s1 == s2. "normal case, contents not matching original stream collection"
- 	
  	!



More information about the Squeak-dev mailing list