10
10
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11
11
//
12
12
//===----------------------------------------------------------------------===//
13
- // RUN-DISABLED: %target-run-simple-swift | %FileCheck %s
14
13
// RUN: %empty-directory(%t)
15
14
// RUN: %gyb %s -o %t/NewArray.swift
16
15
// RUN: %line-directive %t/NewArray.swift -- %target-build-swift %t/NewArray.swift -o %t/a.out -Xfrontend -disable-access-control
17
16
// RUN: %target-run %t/a.out 2>&1 | %line-directive %t/NewArray.swift -- %FileCheck %t/NewArray.swift --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
18
17
// REQUIRES: executable_test
19
- // XFAIL: *
20
18
21
19
import StdlibUnittest
22
20
import StdlibCollectionUnittest
@@ -40,15 +38,14 @@ protocol MyArrayProtocol
40
38
: RandomAccessCollection ,
41
39
RangeReplaceableCollection ,
42
40
MutableCollection ,
43
- ArrayLiteralConvertible {
44
-
45
- associatedtype Iterator : IteratorProtocol
46
-
41
+ ExpressibleByArrayLiteral
42
+ where ArrayLiteralElement == Element
43
+ {
47
44
var _owner : AnyObject ? { get }
48
45
49
46
var capacity : Int { get }
50
47
51
- func += <
48
+ static func += <
52
49
S : Sequence
53
50
> ( lhs: inout Self , rhs: S )
54
51
where S. Iterator. Element == Iterator . Element
@@ -89,8 +86,7 @@ func test<
89
86
T : MyArrayProtocol
90
87
> ( _: T . Type , _ label: String )
91
88
where
92
- T. Iterator. Element == LifetimeTracked ,
93
- T. Iterator. Element == T . Element ,
89
+ T. Element == LifetimeTracked ,
94
90
T. Index == Int {
95
91
print ( " test: \( label) ... " , terminator: " " )
96
92
@@ -113,15 +109,15 @@ T.Index == Int {
113
109
x += LifetimeTracked ( 0 ) ..< LifetimeTracked ( 2 )
114
110
let bufferId1 = checkReallocation ( x, bufferId0, false )
115
111
116
- for i in x. count..< ( x. capacity + 1 ) {
117
- let bufferId1a = checkReallocation ( x, bufferId1, false )
112
+ for _ in x. count..< ( x. capacity + 1 ) {
113
+ _ = checkReallocation ( x, bufferId1, false )
118
114
x. append ( LifetimeTracked ( 13 ) )
119
115
}
120
116
let bufferId2 = checkReallocation ( x, bufferId1, true )
121
117
122
118
let y = x
123
119
x [ x. index ( before: x. endIndex) ] = LifetimeTracked ( 17 )
124
- let bufferId3 = checkReallocation ( x, bufferId2, true )
120
+ _ = checkReallocation ( x, bufferId2, true )
125
121
checkEqual ( x, y, false )
126
122
127
123
func checkReallocations(
@@ -200,39 +196,42 @@ func testAsArray() {
200
196
// CHECK-NEXT: true
201
197
202
198
let zz = y [ 0 ..< 2 ]
203
- print ( zz. _bufferID)
199
+ print ( zz. _bufferID! )
204
200
// CHECK-NEXT: 0x
205
201
}
206
202
testAsArray ( )
207
203
208
204
#if _runtime(_ObjC)
209
205
import Foundation
210
206
211
- func nsArrayOfStrings( ) -> Array < NSString > {
207
+ func nsArrayOfStrings( ) -> NSArray {
212
208
let src : ContiguousArray < NSString > = [ " foo " , " bar " , " baz " ]
213
209
214
210
return src. withUnsafeBufferPointer {
215
- let ns = NSArray (
211
+ return NSArray (
216
212
objects: unsafeBitCast ( $0. baseAddress!,
217
213
to: UnsafeMutablePointer< AnyObject> . self ) ,
218
214
count: $0. count)
219
- return ns as! [ NSString ]
220
215
}
221
216
}
222
217
218
+ func swiftArrayWithNSArrayOfStrings( ) -> Array < NSString > {
219
+ return nsArrayOfStrings ( ) as! [ NSString ]
220
+ }
221
+
223
222
func testCocoa( ) {
224
223
print ( " == Cocoa == " )
225
224
// CHECK-objc: == Cocoa ==
226
225
227
- var a = nsArrayOfStrings ( )
226
+ var a = swiftArrayWithNSArrayOfStrings ( )
228
227
printSequence ( a)
229
228
// CHECK-objc-NEXT: [foo, bar, baz]
230
229
231
230
a. append ( " qux " )
232
231
printSequence ( a)
233
232
// CHECK-objc-NEXT: [foo, bar, baz, qux]
234
233
235
- a = nsArrayOfStrings ( )
234
+ a = swiftArrayWithNSArrayOfStrings ( )
236
235
printSequence ( a)
237
236
// CHECK-objc-NEXT: [foo, bar, baz]
238
237
@@ -246,12 +245,12 @@ func testCocoa() {
246
245
printSequence ( b)
247
246
// CHECK-objc-NEXT: [foo, bar, baz]
248
247
249
- a = nsArrayOfStrings ( )
248
+ a = swiftArrayWithNSArrayOfStrings ( )
250
249
a. insert ( " bag " , at: 2 )
251
250
printSequence ( a)
252
251
// CHECK-objc-NEXT: [foo, bar, bag, baz]
253
252
254
- a = nsArrayOfStrings ( )
253
+ a = swiftArrayWithNSArrayOfStrings ( )
255
254
a. reserveCapacity ( 30 )
256
255
printSequence ( a)
257
256
// CHECK-objc-NEXT: [foo, bar, baz]
@@ -269,12 +268,6 @@ func testCocoa() {
269
268
testCocoa ( )
270
269
#endif // _runtime(_ObjC)
271
270
272
- extension ArraySlice {
273
- mutating func qsort( _ compare: @escaping ( Element , Element ) -> Bool ) {
274
- _introSort ( & self , subRange: Range ( self . indices) , by: compare)
275
- }
276
- }
277
-
278
271
func testSlice( ) {
279
272
print ( " == ArraySlice == " )
280
273
// CHECK: == ArraySlice ==
@@ -301,14 +294,13 @@ func testSlice() {
301
294
printSequence ( b) // CHECK-NEXT: [0, 1, 2, 3, 41, 5, 6, 7, 8, 9]
302
295
303
296
let c = b
304
- b [ b. startIndex..< b. endIndex] . qsort ( < )
297
+ b [ b. startIndex..< b. endIndex] . sort ( by : < )
305
298
printSequence ( b) // CHECK-NEXT: [0, 1, 2, 3, 5, 6, 7, 8, 9, 41]
306
299
printSequence ( c) // CHECK-NEXT: [0, 1, 2, 3, 41, 5, 6, 7, 8, 9]
307
300
308
301
#if _runtime(_ObjC)
309
302
// Now a bridged slice
310
- var a = Array < NSString > (
311
- _ArrayBuffer ( nsArray: nsArrayOfStrings ( ) . _buffer. _asCocoaArray ( ) ) )
303
+ let a = Array < NSString > ( _buffer: _ArrayBuffer ( nsArray: nsArrayOfStrings ( ) ) )
312
304
313
305
printSequence ( a) // CHECK-objc-NEXT: [foo, bar, baz]
314
306
@@ -456,8 +448,8 @@ func testIsEmptyFirstLast${A}() {
456
448
print ( " < \( ${ A} ( 3 ..< 43 ) . first!) > " ) // CHECK-NEXT: <3>
457
449
print ( " < \( ${ A} ( 3 ..< 43 ) . last!) > " ) // CHECK-NEXT: <42>
458
450
459
- print ( " < \( ${ A} < Int> ( ) . first) > " ) // CHECK-NEXT: nil
460
- print( " < \( ${ A} < Int> ( ) . last) > " ) // CHECK-NEXT: nil
451
+ print( " < \( String ( describing : ${ A} < Int> ( ) . first) ) > " ) // CHECK-NEXT: nil
452
+ print( " < \( String ( describing : ${ A} < Int> ( ) . last) ) > " ) // CHECK-NEXT: nil
461
453
462
454
var a = ${A}(LifetimeTracked(0)..<LifetimeTracked(10))
463
455
print(a.removeLast().value) // CHECK-NEXT: 9
0 commit comments