@@ -41,6 +41,7 @@ var nextBaseSerialNumber = 0
41
41
func baz( )
42
42
}
43
43
44
+ /// A type that will be bridged verbatim to Objective-C
44
45
class Base : NSObject , Fooable {
45
46
func foo( ) { }
46
47
@@ -85,6 +86,7 @@ class Derived : Base, Barable {
85
86
var bridgeFromOperationCount = 0
86
87
var bridgeToOperationCount = 0
87
88
89
+ /// A value type that's bridged using _ObjectiveCBridgeable
88
90
struct BridgedSwift : CustomStringConvertible , _ObjectiveCBridgeable {
89
91
func _bridgeToObjectiveC( ) -> Derived {
90
92
bridgeToOperationCount += 1
@@ -151,30 +153,46 @@ class Thunks : NSObject {
151
153
return Derived ( value)
152
154
}
153
155
154
- @objc func acceptDerivedArray( _ x: [ Derived ] ) {
155
- print ( " acceptDerivedArray( \( x) ) " )
156
+ @objc func acceptDerivedArray(
157
+ _ x: [ Derived ] ,
158
+ expecting expected: NSArray
159
+ ) {
160
+ expectEqual ( x. count, expected. count)
161
+ for i in 0 ..< x. count {
162
+ expectTrue ( x [ i] === expected [ i] )
163
+ }
156
164
}
157
165
158
- @objc func produceDerivedArray( _ numItems: Int ) -> [ Derived ] {
166
+ @objc func produceDerivedArray(
167
+ _ expectations: NSMutableArray
168
+ ) -> [ Derived ] {
159
169
var array : [ Derived ] = [ ]
160
- for i in 0 ..< numItems {
170
+ for i in 0 ..< 5 {
161
171
array. append ( Derived ( i) )
172
+ expectations. add ( array [ i] )
162
173
}
163
- print ( " produceDerivedArray( \( array) ) " )
164
174
return array
165
175
}
166
176
167
- @objc func acceptBridgedSwiftArray( _ raw: NSArray ) {
177
+ @objc func checkProducedDerivedArray(
178
+ _ produced: NSArray , expecting expected: NSArray
179
+ ) {
180
+ expectEqual ( produced. count, expected. count)
181
+ for i in 0 ..< produced. count {
182
+ expectTrue ( produced [ i] === expected [ i] )
183
+ }
184
+ }
185
+
186
+ @objc func acceptBridgedSwiftArray( _ raw: NSArray ) -> AnyObject {
168
187
let x = raw as! [ BridgedSwift ]
169
- print ( " acceptBridgedSwiftArray( \( x ) ) " )
188
+ return Box ( x )
170
189
}
171
190
172
191
@objc func produceBridgedSwiftArray( _ numItems: Int ) -> NSArray {
173
192
var array : [ BridgedSwift ] = [ ]
174
193
for i in 0 ..< numItems {
175
194
array. append ( BridgedSwift ( i) )
176
195
}
177
- print ( " produceBridgedSwiftArray( \( array) ) " )
178
196
return array as NSArray
179
197
}
180
198
}
@@ -270,22 +288,9 @@ tests.test("testBridgedVerbatim") {
270
288
expectEmpty ( derivedAsAnyObjectArray as? [ protocol < Barable , Bazable > ] )
271
289
}
272
290
273
- func doTestDerived( ) {
274
- // CHECK: doTestDerived
275
- print ( " doTestDerived " )
276
-
277
- // CHECK-NEXT: produceDerivedArray([Derived[[A:#[0-9]+]](0), Derived[[B:#[0-9]+]](1), Derived[[C:#[0-9]+]](2), Derived[[D:#[0-9]+]](3), Derived[[E:#[0-9]+]](4)])
291
+ tests. test ( " doTestDerived " ) {
278
292
testDerived ( Thunks ( ) )
279
- // CHECK-NEXT: 5 elements in the array
280
- // CHECK-NEXT: Derived[[A]](0)
281
- // CHECK-NEXT: Derived[[B]](1)
282
- // CHECK-NEXT: Derived[[C]](2)
283
- // CHECK-NEXT: Derived[[D]](3)
284
- // CHECK-NEXT: Derived[[E]](4)
285
-
286
- // CHECK-NEXT: acceptDerivedArray([Derived[[A:#[0-9]+]](10), Derived[[B:#[0-9]+]](11), Derived[[C:#[0-9]+]](12), Derived[[D:#[0-9]+]](13), Derived[[E:#[0-9]+]](14)])
287
293
}
288
- doTestDerived ( )
289
294
290
295
//===--- Explicitly Bridged -----------------------------------------------===//
291
296
// BridgedSwift conforms to _ObjectiveCBridgeable
@@ -455,19 +460,12 @@ func testExplicitlyBridged() {
455
460
// CHECK-NEXT: Correctly rejected downcast of nil array
456
461
print ( " Correctly rejected downcast of nil array " )
457
462
}
463
+ }
464
+ testExplicitlyBridged ( )
458
465
459
- // CHECK-NEXT: produceBridgedSwiftArray([BridgedSwift[[A:#[0-9]+]](0), BridgedSwift[[B:#[0-9]+]](1), BridgedSwift[[C:#[0-9]+]](2), BridgedSwift[[D:#[0-9]+]](3), BridgedSwift[[E:#[0-9]+]](4)])
466
+ tests . test ( " testExplicitlyBridged " ) {
460
467
testBridgedSwift ( Thunks ( ) )
461
- // CHECK-NEXT: 5 elements in the array
462
- // CHECK-NEXT: Derived[[A:#[0-9]+]](0)
463
- // CHECK-NEXT: Derived[[B:#[0-9]+]](1)
464
- // CHECK-NEXT: Derived[[C:#[0-9]+]](2)
465
- // CHECK-NEXT: Derived[[D:#[0-9]+]](3)
466
- // CHECK-NEXT: Derived[[E:#[0-9]+]](4)
467
-
468
- // CHECK-NEXT: acceptBridgedSwiftArray([BridgedSwift[[A:#[0-9]+]](10), BridgedSwift[[B:#[0-9]+]](11), BridgedSwift[[C:#[0-9]+]](12), BridgedSwift[[D:#[0-9]+]](13), BridgedSwift[[E:#[0-9]+]](14)])
469
468
}
470
- testExplicitlyBridged ( )
471
469
472
470
tests. test ( " testRoundTrip " ) {
473
471
class Test : NSObject {
0 commit comments