2
2
// RUN: mkdir -p %t
3
3
//
4
4
// RUN: %S/../../utils/gyb %s -o %t/main.swift
5
- // RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o
6
- // RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Set -Xfrontend -disable-access-control
5
+ // RUN: if [ %target-runtime == "objc" ]; then \
6
+ // RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o; \
7
+ // RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Set -Xfrontend -disable-access-control; \
8
+ // RUN: else \
9
+ // RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %t/main.swift -o %t/Set -Xfrontend -disable-access-control -Xfrontend -disable-objc-attr-requires-foundation-module; \
10
+ // RUN: fi
7
11
//
8
12
// RUN: %S/../../utils/line-directive %t/main.swift -- %target-run %t/Set
9
13
// REQUIRES: executable_test
10
14
11
- // XFAIL: linux
12
-
13
15
import StdlibUnittest
14
16
import StdlibCollectionUnittest
15
17
16
18
// For rand32
17
19
import SwiftPrivate
20
+ #if _runtime(_ObjC)
18
21
import Foundation
22
+ #else
23
+ // for random, srandom
24
+ import Glibc
25
+ #endif
19
26
20
27
// For experimental Set operators
21
28
import SwiftExperimental
22
29
30
+
23
31
// Check that the generic parameter is called 'Element'.
24
32
protocol TestProtocol1 { }
25
33
@@ -50,12 +58,16 @@ var SetTestSuite = TestSuite("Set")
50
58
51
59
SetTestSuite . setUp {
52
60
resetLeaksOfDictionaryKeysValues ( )
61
+ #if _runtime(_ObjC)
53
62
resetLeaksOfObjCDictionaryKeysValues ( )
63
+ #endif
54
64
}
55
65
56
66
SetTestSuite . tearDown {
57
67
expectNoLeaksOfDictionaryKeysValues ( )
68
+ #if _runtime(_ObjC)
58
69
expectNoLeaksOfObjCDictionaryKeysValues ( )
70
+ #endif
59
71
}
60
72
61
73
func getCOWFastSet( _ members: [ Int ] = [ 1010 , 2020 , 3030 ] ) -> Set < Int > {
@@ -106,6 +118,12 @@ func pickRandom<T>(_ a: [T]) -> T {
106
118
return a [ uniformRandom ( a. count) ]
107
119
}
108
120
121
+ func equalsUnordered( _ lhs: Set < Int > , _ rhs: Set < Int > ) -> Bool {
122
+ return lhs. sorted ( ) . elementsEqual ( rhs. sorted ( ) ) {
123
+ $0 == $1
124
+ }
125
+ }
126
+
109
127
func isNativeSet< T : Hashable > ( _ s: Set < T > ) -> Bool {
110
128
switch s. _variantStorage {
111
129
case . native:
@@ -115,6 +133,7 @@ func isNativeSet<T : Hashable>(_ s: Set<T>) -> Bool {
115
133
}
116
134
}
117
135
136
+ #if _runtime(_ObjC)
118
137
func isNativeNSSet( _ s: NSSet ) -> Bool {
119
138
let className : NSString = NSStringFromClass ( s. dynamicType) as NSString
120
139
return className. range ( of: " NativeSetStorage " ) . length > 0
@@ -135,17 +154,10 @@ func getBridgedEmptyNSSet() -> NSSet {
135
154
return bridged
136
155
}
137
156
138
-
139
157
func isCocoaSet< T : Hashable > ( _ s: Set < T > ) -> Bool {
140
158
return !isNativeSet( s)
141
159
}
142
160
143
- func equalsUnordered( _ lhs: Set < Int > , _ rhs: Set < Int > ) -> Bool {
144
- return lhs. sorted ( ) . elementsEqual ( rhs. sorted ( ) ) {
145
- $0 == $1
146
- }
147
- }
148
-
149
161
/// Get an NSSet of TestObjCKeyTy values
150
162
func getAsNSSet( _ members: [ Int ] = [ 1010 , 2020 , 3030 ] ) -> NSSet {
151
163
let nsArray = NSMutableArray ( )
@@ -295,6 +307,7 @@ func getBridgedNSSet_MemberTypesCustomBridged() -> NSSet {
295
307
296
308
return bridged
297
309
}
310
+ #endif // _runtime(_ObjC)
298
311
299
312
SetTestSuite . test ( " AssociatedTypes " ) {
300
313
typealias Collection = Set < MinimalHashableValue >
@@ -1167,6 +1180,7 @@ SetTestSuite.test("deleteChainCollisionRandomized") {
1167
1180
}
1168
1181
}
1169
1182
1183
+ #if _runtime(_ObjC)
1170
1184
@objc
1171
1185
class CustomImmutableNSSet : NSSet {
1172
1186
init ( _privateInit: ( ) ) {
@@ -2679,6 +2693,7 @@ SetTestSuite.test("SetBridgeFromObjectiveCConditional") {
2679
2693
expectTrue ( false )
2680
2694
}
2681
2695
}
2696
+ #endif // _runtime(_ObjC)
2682
2697
2683
2698
// Public API
2684
2699
@@ -2933,6 +2948,7 @@ SetTestSuite.test("Equatable.Native.Native") {
2933
2948
checkEquatable ( false , s1, s2)
2934
2949
}
2935
2950
2951
+ #if _runtime(_ObjC)
2936
2952
SetTestSuite . test ( " Equatable.Native.BridgedVerbatim " ) {
2937
2953
let s1 = getNativeBridgedVerbatimSet ( )
2938
2954
let bvs1 = getBridgedVerbatimSet ( )
@@ -2964,6 +2980,7 @@ SetTestSuite.test("Equatable.BridgedNonverbatim.BridgedNonverbatim") {
2964
2980
checkEquatable ( false , bnvs1, bnvsEmpty)
2965
2981
checkEquatable ( false , bnvs2, bnvsEmpty)
2966
2982
}
2983
+ #endif // _runtime(_ObjC)
2967
2984
2968
2985
SetTestSuite . test ( " isDisjointWith.Set.Set " ) {
2969
2986
let s1 = Set ( [ 1010 , 2020 , 3030 , 4040 , 5050 , 6060 ] )
@@ -3478,6 +3495,15 @@ SetTestSuite.test("first") {
3478
3495
expectEmpty ( emptySet. first)
3479
3496
}
3480
3497
3498
+ SetTestSuite . test ( " isEmpty " ) {
3499
+ let s1 = Set ( [ 1010 , 2020 , 3030 ] )
3500
+ expectFalse ( s1. isEmpty)
3501
+
3502
+ let emptySet = Set < Int > ( )
3503
+ expectTrue ( emptySet. isEmpty)
3504
+ }
3505
+
3506
+ #if _runtime(_ObjC)
3481
3507
@objc
3482
3508
class MockSetWithCustomCount : NSSet {
3483
3509
init ( count: Int ) {
@@ -3536,14 +3562,6 @@ func callGenericIsEmpty<C : Collection>(_ collection: C) -> Bool {
3536
3562
return collection. isEmpty
3537
3563
}
3538
3564
3539
- SetTestSuite . test ( " isEmpty " ) {
3540
- let s1 = Set ( [ 1010 , 2020 , 3030 ] )
3541
- expectFalse ( s1. isEmpty)
3542
-
3543
- let emptySet = Set < Int > ( )
3544
- expectTrue ( emptySet. isEmpty)
3545
- }
3546
-
3547
3565
SetTestSuite . test ( " isEmpty/ImplementationIsCustomized " ) {
3548
3566
do {
3549
3567
var d = getMockSetWithCustomCount ( count: 0 )
@@ -3571,6 +3589,7 @@ SetTestSuite.test("isEmpty/ImplementationIsCustomized") {
3571
3589
expectEqual ( 1 , MockSetWithCustomCount . timesCountWasCalled)
3572
3590
}
3573
3591
}
3592
+ #endif // _runtime(_ObjC)
3574
3593
3575
3594
SetTestSuite . test ( " count " ) {
3576
3595
let s1 = Set ( [ 1010 , 2020 , 3030 ] )
0 commit comments