1
- // RUN: %target-run-simple-swift
1
+ // RUN: rm -rf %t && mkdir -p %t
2
+ // RUN: %target-build-swift -swift-version 3 %s -o %t/a.out3 && %target-run %t/a.out3
3
+ // RUN: %target-build-swift -swift-version 4 %s -o %t/a.out4 && %target-run %t/a.out4
2
4
// REQUIRES: executable_test
3
- // REQUIRES: OS=ios
5
+ // UNSUPPORTED: OS=macosx
6
+ // REQUIRES: objc_interop
4
7
5
8
import UIKit
6
9
import StdlibUnittest
7
10
import StdlibUnittestFoundationExtras
8
11
9
- let UIKitTests = TestSuite ( " UIKit " )
12
+ #if swift(>=4)
13
+ let UIKitTests = TestSuite ( " UIKit_Swift4 " )
14
+ #else
15
+ let UIKitTests = TestSuite ( " UIKit_Swift3 " )
16
+ #endif
10
17
18
+ #if !os(watchOS) && !os(tvOS)
11
19
private func printDevice( _ o: UIDeviceOrientation ) -> String {
12
20
var s = " \( o. isPortrait) \( UIDeviceOrientationIsPortrait ( o) ) , "
13
21
s += " \( o. isLandscape) \( UIDeviceOrientationIsLandscape ( o) ) , "
@@ -60,6 +68,7 @@ UIKitTests.test("UIInterfaceOrientation") {
60
68
expectEqual ( " false false, true true " ,
61
69
printInterface ( . landscapeRight) )
62
70
}
71
+ #endif
63
72
64
73
UIKitTests . test ( " UIEdgeInsets " ) {
65
74
let insets = [
@@ -79,6 +88,66 @@ UIKitTests.test("UIOffset") {
79
88
checkEquatable ( offsets, oracle: { $0 == $1 } )
80
89
}
81
90
91
+ UIKitTests . test ( " UIFont.Weight " ) {
92
+ guard #available( iOS 8 . 2 , * ) else { return }
93
+ #if swift(>=4) // Swift 4
94
+ let regularFontWeight : UIFont . Weight = . regular
95
+
96
+ expectTrue ( regularFontWeight == . regular)
97
+ expectTrue ( regularFontWeight > . light)
98
+ expectTrue ( regularFontWeight < . heavy)
99
+ expectTrue ( regularFontWeight + 0.1 == 0.1 + regularFontWeight)
100
+ #else // Swift 3
101
+ let regularFontWeight : UIFontWeight = UIFontWeightRegular
102
+
103
+ expectTrue ( regularFontWeight == UIFontWeightRegular)
104
+ expectTrue ( regularFontWeight > UIFontWeightLight)
105
+ expectTrue ( regularFontWeight < UIFontWeightHeavy)
106
+ expectTrue ( regularFontWeight + 0.1 == 0.1 + UIFontWeightRegular)
107
+ #endif
108
+ }
109
+
110
+ #if !os(watchOS)
111
+ UIKitTests . test ( " UILayoutPriority " ) {
112
+ #if swift(>=4) // Swift 4
113
+ let lowLayoutPriority : UILayoutPriority = . defaultLow
114
+ let highLayoutPriority : UILayoutPriority = . defaultHigh
115
+
116
+ expectTrue ( lowLayoutPriority < highLayoutPriority)
117
+
118
+ expectTrue ( lowLayoutPriority + 2.0 == UILayoutPriority ( lowLayoutPriority. rawValue + 2.0 ) )
119
+ expectTrue ( 2.0 + lowLayoutPriority == UILayoutPriority ( lowLayoutPriority. rawValue + 2.0 ) )
120
+ expectTrue ( lowLayoutPriority - 2.0 == UILayoutPriority ( lowLayoutPriority. rawValue - 2.0 ) )
121
+ expectTrue ( highLayoutPriority - lowLayoutPriority == highLayoutPriority. rawValue - lowLayoutPriority. rawValue)
122
+
123
+ expectTrue ( lowLayoutPriority + ( highLayoutPriority - lowLayoutPriority) == highLayoutPriority)
124
+
125
+ var mutablePriority = lowLayoutPriority
126
+ mutablePriority -= 1.0
127
+ mutablePriority += 2.0
128
+ expectTrue ( mutablePriority == lowLayoutPriority + 1.0 )
129
+
130
+ let priorotyRange = lowLayoutPriority... highLayoutPriority
131
+ expectTrue ( priorotyRange. contains ( . defaultLow) )
132
+ expectFalse ( priorotyRange. contains ( . required) )
133
+ #else // Swift 3
134
+ let lowLayoutPriority : UILayoutPriority = UILayoutPriorityDefaultLow
135
+ let highLayoutPriority : UILayoutPriority = UILayoutPriorityDefaultHigh
136
+
137
+ expectTrue ( lowLayoutPriority < highLayoutPriority)
138
+
139
+ expectTrue ( 2.0 + lowLayoutPriority == lowLayoutPriority + 2.0 )
140
+ expectTrue ( lowLayoutPriority + ( highLayoutPriority - lowLayoutPriority) == highLayoutPriority)
141
+
142
+ var mutablePriority = lowLayoutPriority
143
+ mutablePriority -= 1.0
144
+ mutablePriority += 2.0
145
+ expectTrue ( mutablePriority == lowLayoutPriority + 1.0 )
146
+ #endif
147
+ }
148
+ #endif
149
+
150
+ #if !os(watchOS)
82
151
class TestChildView : UIView , CustomPlaygroundQuickLookable {
83
152
convenience init ( ) {
84
153
self . init ( frame: CGRect ( x: 0 , y: 0 , width: 10 , height: 10 ) )
@@ -95,6 +164,7 @@ UIKitTests.test("CustomPlaygroundQuickLookable") {
95
164
" TestChildView custom quicklookable should have been invoked " )
96
165
}
97
166
}
167
+ #endif
98
168
99
169
UIKitTests . test ( " NSValue bridging " ) {
100
170
expectBridgeToNSValue ( UIEdgeInsets ( top: 17 , left: 38 , bottom: 6 , right: 79 ) ,
0 commit comments