23
23
24
24
import Foundation
25
25
import ArrayBridgeObjC
26
- import StdlibUnittest
27
- let tests = TestSuite ( " ArrayBridge " )
26
+
27
+ // CHECK: testing...
28
+ print ( " testing... " )
28
29
29
30
var trackedCount = 0
30
31
var nextTrackedSerialNumber = 0
@@ -66,14 +67,14 @@ class Tracked : NSObject, Fooable {
66
67
return self . dynamicType. init ( self . value + 1 )
67
68
}
68
69
69
- override func isEqual( _ other: AnyObject ? ) -> Bool {
70
- return ( other as? Tracked ) ? . value == self . value
71
- }
72
-
73
70
var value : Int
74
71
var serialNumber : Int
75
72
}
76
73
74
+ func == ( x: Tracked , y: Tracked ) -> Bool {
75
+ return x. value == y. value
76
+ }
77
+
77
78
typealias Base = Tracked
78
79
class Derived : Base , Barable {
79
80
func bar( ) { }
@@ -200,16 +201,14 @@ class Thunks : NSObject {
200
201
// Base is "bridged verbatim"
201
202
//===----------------------------------------------------------------------===//
202
203
203
- tests. test ( " testBridgedVerbatim " ) {
204
- nextTrackedSerialNumber = 0
204
+ func testBridgedVerbatim( ) {
205
205
let bases : [ Base ] = [ Base ( 100 ) , Base ( 200 ) , Base ( 300 ) ]
206
206
207
207
//===--- Implicit conversion to/from NSArray ------------------------------===//
208
208
209
+ // CHECK-NEXT: Base#1(100)
209
210
let basesConvertedToNSArray = bases as NSArray
210
- expectEqual (
211
- " Base#1(100) " ,
212
- String ( basesConvertedToNSArray. object ( at: 0 ) as! Base ) )
211
+ print ( basesConvertedToNSArray. object ( at: 0 ) as! Base )
213
212
214
213
// Create an ordinary NSArray, not a native one
215
214
let nsArrayOfBase : NSArray = NSArray ( object: Base ( 42 ) )
@@ -218,79 +217,107 @@ tests.test("testBridgedVerbatim") {
218
217
let nsArrayOfBaseConvertedToAnyObjectArray = nsArrayOfBase as [ AnyObject ]
219
218
220
219
// Capture the representation of the first element
221
- let base42 : ObjectIdentifier
222
- do {
223
- let b = nsArrayOfBase. object ( at: 0 ) as! Base
224
- expectEqual ( 42 , b. value)
225
- base42 = ObjectIdentifier ( b)
226
- }
220
+ // CHECK-NEXT: [[base42:Base.*42]]
221
+ print ( nsArrayOfBase. object ( at: 0 ) as! Base )
227
222
228
223
// ...with the same elements
229
- expectEqual (
230
- base42,
231
- ObjectIdentifier ( nsArrayOfBaseConvertedToAnyObjectArray [ 0 ] as! Base ) )
224
+ // CHECK-NEXT: [[base42]]
225
+ print ( nsArrayOfBaseConvertedToAnyObjectArray [ 0 ] as! Base )
232
226
233
227
// Verify that NSArray class methods are inherited by a Swift bridging class.
234
- let className = String ( reflecting: basesConvertedToNSArray. dynamicType)
235
- expectTrue ( className. hasPrefix ( " Swift._ContiguousArrayStorage " ) )
236
- expectTrue ( basesConvertedToNSArray. dynamicType. supportsSecureCoding)
228
+ // CHECK-NEXT: Swift.{{.*}}Array
229
+ debugPrint ( basesConvertedToNSArray. dynamicType)
230
+ // CHECK-NEXT: true
231
+ print ( basesConvertedToNSArray. dynamicType. supportsSecureCoding)
237
232
238
233
//===--- Up- and Down-casts -----------------------------------------------===//
239
234
var derived : [ Derived ] = [ Derived ( 11 ) , Derived ( 22 ) ]
240
- let derived0 = derived
235
+ // CHECK-NEXT: [[derived0:\[Derived#[0-9]+\(11\), Derived#[0-9]+\(22\)\]{1}]]
236
+ print ( derived)
241
237
242
238
// upcast is implicit
243
239
let derivedAsBases : [ Base ] = derived
244
- expectEqual ( derived. count, derivedAsBases. count)
245
- for (x, y) in zip ( derived, derivedAsBases) {
246
- expectTrue ( x === y)
247
- }
240
+
241
+ // CHECK-NEXT: [[derived0]]
242
+ print ( derivedAsBases)
248
243
249
244
// Arrays are logically distinct after upcast
250
245
derived [ 0 ] = Derived ( 33 )
246
+
247
+ // CHECK-NEXT: {{\[Derived#[0-9]+\(33\), Derived#[0-9]+\(22\)]}}
248
+ print ( derived)
249
+ // CHECK-NEXT: [[derived0]]
250
+ print ( derivedAsBases)
251
251
252
- expectEqual ( [ Derived ( 33 ) , Derived ( 22 ) ] , derived)
253
- expectEqual ( [ Derived ( 11 ) , Derived ( 22 ) ] , derivedAsBases)
254
-
255
- expectEqual ( derived0, derivedAsBases as! [ Derived ] )
252
+ // CHECK-NEXT: [[derived0]]
253
+ if let roundTripDerived = derivedAsBases as? [ Derived ] {
254
+ print ( roundTripDerived)
255
+ }
256
+ else {
257
+ print ( " roundTripDerived upcast failed " )
258
+ }
256
259
260
+ // CHECK-NEXT: [[derived2:\[Derived#[0-9]+\(44\), Derived#[0-9]+\(55\)\]{1}]]
257
261
let derivedInBaseBuffer : [ Base ] = [ Derived ( 44 ) , Derived ( 55 ) ]
258
- let derived2 = derivedInBaseBuffer
262
+ print ( derivedInBaseBuffer)
259
263
260
- // Explicit downcast-ability is based on element type, not buffer type
261
- expectNotEmpty ( derivedInBaseBuffer as? [ Derived ] )
264
+ // CHECK-NEXT: Explicit downcast-ability is based on element type, not buffer type
265
+ if let downcastBaseBuffer = derivedInBaseBuffer as? [ Derived ] {
266
+ print ( " Explicit downcast-ability is based on element type, not buffer type " )
267
+ }
268
+ else {
269
+ print ( " Unexpected downcast failure " )
270
+ }
262
271
263
272
// We can up-cast to array of AnyObject
273
+ // CHECK-NEXT: [[derived2]]
264
274
let derivedAsAnyObjectArray : [ AnyObject ] = derivedInBaseBuffer
265
- expectEqual ( derived2 , derivedAsAnyObjectArray. map { $0 as! Base } )
275
+ print ( derivedAsAnyObjectArray)
266
276
267
- let downcastBackToBase = derivedAsAnyObjectArray as? [ Base ]
268
- expectNotEmpty ( downcastBackToBase)
277
+ // CHECK-NEXT: downcastBackToBase = [[derived2]]
278
+ if let downcastBackToBase = derivedAsAnyObjectArray as? [ Base ] {
279
+ print ( " downcastBackToBase = \( downcastBackToBase) " )
280
+ }
281
+ else {
282
+ print ( " downcastBackToBase failed " )
283
+ }
269
284
270
- if let downcastBackToDerived = expectNotEmpty ( derivedAsAnyObjectArray as? [ Derived ] ) {
271
- expectEqual ( derived2, downcastBackToDerived)
285
+ // CHECK-NEXT: downcastBackToDerived = [[derived2]]
286
+ if let downcastBackToDerived = derivedAsAnyObjectArray as? [ Derived ] {
287
+ print ( " downcastBackToDerived = \( downcastBackToDerived) " )
288
+ }
289
+ else {
290
+ print ( " downcastBackToDerived failed " )
272
291
}
273
292
274
- if let downcastToProtocols = expectNotEmpty ( derivedAsAnyObjectArray as? [ Fooable ] ) {
275
- expectEqual ( derived2, downcastToProtocols. map { $0 as! Derived } )
293
+ // CHECK-NEXT: downcastToProtocols = [[derived2]]
294
+ if let downcastToProtocols = derivedAsAnyObjectArray as? [ Fooable ] {
295
+ print ( " downcastToProtocols = \( downcastToProtocols) " )
296
+ } else {
297
+ print ( " downcastToProtocols failed " )
276
298
}
277
299
278
- if let downcastToProtocols = expectNotEmpty ( derivedAsAnyObjectArray as? [ Barable ] ) {
279
- expectEqual ( derived2, downcastToProtocols. map { $0 as! Derived } )
300
+ // CHECK-NEXT: downcastToProtocols = [[derived2]]
301
+ if let downcastToProtocols = derivedAsAnyObjectArray as? [ Barable ] {
302
+ print ( " downcastToProtocols = \( downcastToProtocols) " )
303
+ } else {
304
+ print ( " downcastToProtocols failed " )
280
305
}
281
306
282
- if let downcastToProtocols = expectNotEmpty ( derivedAsAnyObjectArray as? [ protocol < Barable , Fooable > ] ) {
283
- expectEqual ( derived2, downcastToProtocols. map { $0 as! Derived } )
307
+ // CHECK-NEXT: downcastToProtocols = [[derived2]]
308
+ if let downcastToProtocols = derivedAsAnyObjectArray as? [ protocol < Barable , Fooable > ] {
309
+ print ( " downcastToProtocols = \( downcastToProtocols) " )
310
+ } else {
311
+ print ( " downcastToProtocols failed " )
284
312
}
285
313
286
- expectEmpty ( derivedAsAnyObjectArray as? [ protocol < Barable , Bazable > ] )
287
- }
314
+ // CHECK-NEXT: downcastToProtocols failed
315
+ if let downcastToProtocols = derivedAsAnyObjectArray as? [ protocol < Barable , Bazable > ] {
316
+ print ( " downcastToProtocols = \( downcastToProtocols) " )
317
+ } else {
318
+ print ( " downcastToProtocols failed " )
319
+ }
288
320
289
- func doTestBridgedObjC( ) {
290
- // CHECK: doTestBridgedObjC
291
- print ( " doTestBridgedObjC " )
292
-
293
- testBridgedObjC ( Thunks ( ) )
294
321
// CHECK-NEXT: produceBridgedObjCArray([BridgedObjC[[A:#[0-9]+]](0), BridgedObjC[[B:#[0-9]+]](1), BridgedObjC[[C:#[0-9]+]](2), BridgedObjC[[D:#[0-9]+]](3), BridgedObjC[[E:#[0-9]+]](4)])
295
322
testBridgedObjC ( Thunks ( ) )
296
323
// CHECK-NEXT: 5 elements in the array
@@ -302,7 +329,7 @@ func doTestBridgedObjC() {
302
329
303
330
// CHECK-NEXT: acceptBridgedObjCArray([BridgedObjC[[A:#[0-9]+]](10), BridgedObjC[[B:#[0-9]+]](11), BridgedObjC[[C:#[0-9]+]](12), BridgedObjC[[D:#[0-9]+]](13), BridgedObjC[[E:#[0-9]+]](14)])
304
331
}
305
- doTestBridgedObjC ( )
332
+ testBridgedVerbatim ( )
306
333
307
334
//===--- Explicitly Bridged -----------------------------------------------===//
308
335
// BridgedSwift conforms to _ObjectiveCBridgeable
@@ -427,7 +454,7 @@ func testExplicitlyBridged() {
427
454
428
455
// Downcast of Cocoa array to an array of strings (which should fail)
429
456
// CHECK-NEXT: Could not downcast [AnyObject] to [String]
430
- if let _ = wrappedCocoaBridgedSwifts as? [ String ] {
457
+ if let downcasted = wrappedCocoaBridgedSwifts as? [ String ] {
431
458
print ( " Shouldn't be able to downcast to an array of strings " )
432
459
} else {
433
460
print ( " Could not downcast [AnyObject] to [String] " )
@@ -446,7 +473,7 @@ func testExplicitlyBridged() {
446
473
447
474
// Downcast from a nil implicitly unwrapped optional array of AnyObjects.
448
475
wrappedCocoaBridgedSwiftsIUO = nil
449
- if let _ = wrappedCocoaBridgedSwiftsIUO as? [ BridgedSwift ] {
476
+ if let downcasted = wrappedCocoaBridgedSwiftsIUO as? [ BridgedSwift ] {
450
477
print ( " Cannot downcast from a nil array! " )
451
478
} else {
452
479
// CHECK-NEXT: Correctly rejected downcast of nil array
@@ -466,7 +493,7 @@ func testExplicitlyBridged() {
466
493
467
494
// Downcast from a nil optional array of AnyObjects.
468
495
wrappedCocoaBridgedSwiftsOpt = nil
469
- if let _ = wrappedCocoaBridgedSwiftsOpt as? [ BridgedSwift ] {
496
+ if let downcasted = wrappedCocoaBridgedSwiftsOpt as? [ BridgedSwift ] {
470
497
print ( " Cannot downcast from a nil array! " )
471
498
} else {
472
499
// CHECK-NEXT: Correctly rejected downcast of nil array
@@ -490,9 +517,12 @@ func testRoundTrip() {
490
517
class Test : NSObject {
491
518
@objc dynamic func call( _ array: NSArray ) -> NSArray {
492
519
520
+ // CHECK-NEXT: ---Passed array---
521
+ print ( " ---Passed array--- " )
493
522
let result = array as! [ BridgedSwift ]
494
- expectEqual ( 0 , bridgeFromOperationCount)
495
- expectEqual ( 0 , bridgeToOperationCount)
523
+ // CHECK-NEXT: bridge operations (from, to) = (0, 0)
524
+ BridgedSwift . printStats ( )
525
+
496
526
497
527
// Clear out the stats before returning array
498
528
BridgedSwift . resetStats ( )
@@ -507,10 +537,12 @@ func testRoundTrip() {
507
537
BridgedSwift ( 40 ) , BridgedSwift ( 50 ) ]
508
538
509
539
BridgedSwift . resetStats ( )
510
- _ = test. call ( array as NSArray )
540
+ test. call ( array as NSArray )
511
541
512
- expectEqual ( 0 , bridgeFromOperationCount)
513
- expectEqual ( 0 , bridgeToOperationCount)
542
+ // CHECK-NEXT: ---Returned Array---
543
+ print ( " ---Returned Array--- " )
544
+ // CHECK-NEXT: bridge operations (from, to) = (0, 0)
545
+ BridgedSwift . printStats ( )
514
546
}
515
547
testRoundTrip ( )
516
548
//===--- Non-bridging -----------------------------------------------------===//
@@ -534,4 +566,5 @@ func testMutableArray() {
534
566
}
535
567
testMutableArray ( )
536
568
537
- runAllTests ( )
569
+ // CHECK-NEXT: done.
570
+ print ( " done. " )
0 commit comments