14
14
import TestSupport
15
15
#endif
16
16
17
- // Predicate does not back-deploy to older Darwin versions
18
- #if FOUNDATION_FRAMEWORK || os(Linux) || os(Windows)
19
-
20
- @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
21
17
final class PredicateTests : XCTestCase {
22
18
19
+ override func setUp( ) async throws {
20
+ guard #available( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * ) else {
21
+ throw XCTSkip ( " This test is not available on this OS version " )
22
+ }
23
+ }
24
+
23
25
struct Object {
24
26
var a : Int
25
27
var b : String
@@ -35,6 +37,7 @@ final class PredicateTests: XCTestCase {
35
37
var a : Bool
36
38
}
37
39
40
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
38
41
func testBasic( ) throws {
39
42
let compareTo = 2
40
43
let predicate = Predicate< Object> {
@@ -53,6 +56,7 @@ final class PredicateTests: XCTestCase {
53
56
try XCTAssertTrue ( predicate. evaluate ( Object ( a: 2 , b: " " , c: 0 , d: 0 , e: " c " , f: true , g: [ ] ) ) )
54
57
}
55
58
59
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
56
60
func testBasicMacro( ) throws {
57
61
#if compiler(<5.9) || os(Windows)
58
62
throw XCTSkip ( " Macros are not supported on this platform " )
@@ -66,6 +70,7 @@ final class PredicateTests: XCTestCase {
66
70
#endif
67
71
}
68
72
73
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
69
74
func testVariadic( ) throws {
70
75
let predicate = Predicate < Object , Int > {
71
76
// $0.a == $1 + 1
@@ -88,6 +93,7 @@ final class PredicateTests: XCTestCase {
88
93
XCTAssert ( try predicate. evaluate ( Object ( a: 3 , b: " " , c: 0 , d: 0 , e: " c " , f: true , g: [ ] ) , 2 ) )
89
94
}
90
95
96
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
91
97
func testArithmetic( ) throws {
92
98
let predicate = Predicate< Object> {
93
99
// $0.a + 2 == 4
@@ -110,6 +116,7 @@ final class PredicateTests: XCTestCase {
110
116
XCTAssert ( try predicate. evaluate ( Object ( a: 2 , b: " " , c: 0 , d: 0 , e: " c " , f: true , g: [ ] ) ) )
111
117
}
112
118
119
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
113
120
func testDivision( ) throws {
114
121
let predicate = Predicate< Object> {
115
122
// $0.a / 2 == 3
@@ -150,6 +157,7 @@ final class PredicateTests: XCTestCase {
150
157
XCTAssert ( try predicate2. evaluate ( Object ( a: 2 , b: " " , c: 6.0 , d: 0 , e: " c " , f: true , g: [ ] ) ) )
151
158
}
152
159
160
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
153
161
func testBuildDivision( ) throws {
154
162
let predicate = Predicate< Object> {
155
163
PredicateExpressions . build_Equal (
@@ -169,6 +177,7 @@ final class PredicateTests: XCTestCase {
169
177
XCTAssert ( try predicate. evaluate ( Object ( a: 6 , b: " " , c: 0 , d: 0 , e: " c " , f: true , g: [ ] ) ) )
170
178
}
171
179
180
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
172
181
func testUnaryMinus( ) throws {
173
182
let predicate = Predicate< Object> {
174
183
// -$0.a == 17
@@ -189,6 +198,7 @@ final class PredicateTests: XCTestCase {
189
198
XCTAssert ( try predicate. evaluate ( Object ( a: - 17 , b: " " , c: 0 , d: 0 , e: " c " , f: true , g: [ ] ) ) )
190
199
}
191
200
201
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
192
202
func testCount( ) throws {
193
203
let predicate = Predicate< Object> {
194
204
// $0.g.count == 5
@@ -208,6 +218,7 @@ final class PredicateTests: XCTestCase {
208
218
XCTAssert ( try predicate. evaluate ( Object ( a: 0 , b: " " , c: 0 , d: 0 , e: " c " , f: true , g: [ 2 , 3 , 5 , 7 , 11 ] ) ) )
209
219
}
210
220
221
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
211
222
func testFilter( ) throws {
212
223
let predicate = Predicate< Object> { object in
213
224
/*object.g.filter {
@@ -246,6 +257,7 @@ final class PredicateTests: XCTestCase {
246
257
XCTAssert ( try predicate. evaluate ( Object ( a: 0 , b: " " , c: 0.0 , d: 17 , e: " c " , f: true , g: [ 3 , 5 , 7 , 11 , 13 , 17 , 19 ] ) ) )
247
258
}
248
259
260
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
249
261
func testContains( ) throws {
250
262
let predicate = Predicate< Object> {
251
263
// $0.g.contains($0.a)
@@ -267,6 +279,7 @@ final class PredicateTests: XCTestCase {
267
279
XCTAssert ( try predicate. evaluate ( Object ( a: 13 , b: " " , c: 0.0 , d: 0 , e: " c " , f: true , g: [ 2 , 3 , 5 , 11 , 13 , 17 ] ) ) )
268
280
}
269
281
282
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
270
283
func testContainsWhere( ) throws {
271
284
let predicate = Predicate< Object> { object in
272
285
// object.g.contains { $0 % object.a == 0 }
@@ -298,6 +311,7 @@ final class PredicateTests: XCTestCase {
298
311
XCTAssert ( try predicate. evaluate ( Object ( a: 2 , b: " " , c: 0.0 , d: 0 , e: " c " , f: true , g: [ 3 , 5 , 7 , 2 , 11 , 13 ] ) ) )
299
312
}
300
313
314
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
301
315
func testAllSatisfy( ) throws {
302
316
let predicate = Predicate< Object> { object in
303
317
// object.g.allSatisfy { $0 % object.d != 0 }
@@ -329,6 +343,7 @@ final class PredicateTests: XCTestCase {
329
343
XCTAssert ( try predicate. evaluate ( Object ( a: 0 , b: " " , c: 0.0 , d: 2 , e: " c " , f: true , g: [ 3 , 5 , 7 , 11 , 13 , 17 , 19 ] ) ) )
330
344
}
331
345
346
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
332
347
func testOptional( ) throws {
333
348
struct Wrapper < T> {
334
349
let wrapped : T ?
@@ -401,6 +416,7 @@ final class PredicateTests: XCTestCase {
401
416
XCTAssertTrue ( try predicate3. evaluate ( Wrapper ( wrapped: nil ) ) )
402
417
}
403
418
419
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
404
420
func testConditional( ) throws {
405
421
let predicate = Predicate < Bool , String , String > {
406
422
// ($0 ? $1 : $2) == "if branch"
@@ -418,6 +434,7 @@ final class PredicateTests: XCTestCase {
418
434
XCTAssert ( try predicate. evaluate ( true , " if branch " , " else branch " ) )
419
435
}
420
436
437
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
421
438
func testClosedRange( ) throws {
422
439
let predicate = Predicate< Object> {
423
440
// (3...5).contains($0.a)
@@ -462,6 +479,7 @@ final class PredicateTests: XCTestCase {
462
479
XCTAssert ( try predicate2. evaluate ( Object ( a: 3 , b: " " , c: 0.0 , d: 5 , e: " c " , f: true , g: [ ] ) ) )
463
480
}
464
481
482
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
465
483
func testRange( ) throws {
466
484
let predicate = Predicate< Object> {
467
485
// (3..<5).contains($0.a)
@@ -507,6 +525,7 @@ final class PredicateTests: XCTestCase {
507
525
XCTAssert ( try predicate2. evaluate ( Object ( a: 3 , b: " " , c: 0.0 , d: 5 , e: " c " , f: true , g: [ ] ) ) )
508
526
}
509
527
528
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
510
529
func testRangeContains( ) throws {
511
530
let date = Date . distantPast
512
531
let predicate = Predicate< Object> {
@@ -526,6 +545,7 @@ final class PredicateTests: XCTestCase {
526
545
XCTAssertFalse ( try predicate. evaluate ( Object ( a: 3 , b: " " , c: 0.0 , d: 5 , e: " c " , f: true , g: [ ] ) ) )
527
546
}
528
547
548
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
529
549
func testTypes( ) throws {
530
550
let predicate = Predicate< Object> {
531
551
// ($0.a as? Int).flatMap { $0 == 3 } ?? false
@@ -568,6 +588,7 @@ final class PredicateTests: XCTestCase {
568
588
XCTAssert ( try predicate2. evaluate ( Object ( a: 3 , b: " " , c: 0.0 , d: 5 , e: " c " , f: true , g: [ ] ) ) )
569
589
}
570
590
591
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
571
592
func testSubscripts( ) throws {
572
593
var predicate = Predicate< Object> {
573
594
// $0.g[0] == 0
@@ -609,6 +630,7 @@ final class PredicateTests: XCTestCase {
609
630
XCTAssertThrowsError ( try predicate. evaluate ( Object ( a: 3 , b: " " , c: 0.0 , d: 0 , e: " c " , f: true , g: [ ] ) ) )
610
631
}
611
632
633
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
612
634
func testLazyDefaultValueSubscript( ) throws {
613
635
struct Foo : Codable , Sendable {
614
636
static var num = 1
@@ -637,6 +659,7 @@ final class PredicateTests: XCTestCase {
637
659
XCTAssertEqual ( Foo . num, 1 )
638
660
}
639
661
662
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
640
663
func testStaticValues( ) throws {
641
664
func assertPredicate< T> ( _ pred: Predicate < T > , value: T , expected: Bool ) throws {
642
665
XCTAssertEqual ( try pred. evaluate ( value) , expected)
@@ -646,6 +669,7 @@ final class PredicateTests: XCTestCase {
646
669
try assertPredicate ( . false , value: " Hello " , expected: false )
647
670
}
648
671
672
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
649
673
func testMaxMin( ) throws {
650
674
var predicate = Predicate< Object> {
651
675
// $0.g.max() == 2
@@ -680,6 +704,7 @@ final class PredicateTests: XCTestCase {
680
704
681
705
#if FOUNDATION_FRAMEWORK
682
706
707
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
683
708
func testCaseInsensitiveCompare( ) throws {
684
709
let equal = ComparisonResult . orderedSame
685
710
let predicate = Predicate< Object> {
@@ -701,6 +726,7 @@ final class PredicateTests: XCTestCase {
701
726
702
727
#endif
703
728
729
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
704
730
func testBuildDynamically( ) throws {
705
731
func _build( _ equal: Bool ) -> Predicate < Int > {
706
732
Predicate< Int> {
@@ -722,6 +748,7 @@ final class PredicateTests: XCTestCase {
722
748
XCTAssertFalse ( try _build ( false ) . evaluate ( 1 ) )
723
749
}
724
750
751
+ @available ( macOS 14 , iOS 17 , tvOS 17 , watchOS 10 , * )
725
752
func testResilientKeyPaths( ) {
726
753
// Local, non-resilient type
727
754
struct Foo {
@@ -754,5 +781,3 @@ final class PredicateTests: XCTestCase {
754
781
}
755
782
}
756
783
}
757
-
758
- #endif
0 commit comments