@@ -83,6 +83,28 @@ final class DequeTests: XCTestCase {
8383 buf. reserveCapacity ( 5 )
8484 buf. prepend ( 0 )
8585 XCTAssertEqual ( Array ( buf) , [ 0 , 1 , 2 , 3 ] )
86+
87+ // also an empty one
88+ buf = [ ]
89+ XCTAssertEqual ( Array ( buf) , [ ] )
90+ // and an empty one with capacity
91+ buf. reserveCapacity ( 10 )
92+ XCTAssertEqual ( Array ( buf) , [ ] )
93+
94+ // Normally, Array(buf) will invoke our _copyContents. It doesn't do this if we're empty
95+ // though, but we'd like to validate that _copyContents works when empty. We'll do that by
96+ // using the other public API for invoking it, which is
97+ // UnsafeMutableBufferPointer.initialize(from:).
98+ let heapBuffer = UnsafeMutableBufferPointer< IntClass> . allocate( capacity: 5 )
99+ defer { heapBuffer. deallocate ( ) }
100+ buf = [ ] // test using shared empty storage
101+ var ( iter, idx) = heapBuffer. initialize ( from: buf)
102+ XCTAssertNil ( iter. next ( ) , " iter.next() " )
103+ XCTAssertEqual ( idx, heapBuffer. startIndex)
104+ buf. reserveCapacity ( 10 ) // test again with some capacity
105+ ( iter, idx) = heapBuffer. initialize ( from: buf)
106+ XCTAssertNil ( iter. next ( ) , " iter.next() " )
107+ XCTAssertEqual ( idx, heapBuffer. startIndex)
86108 }
87109
88110 func testReserveCapacity( ) {
0 commit comments