WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 282204a

Browse files
committed
Swap ranges upper and lower
1 parent 8eb80f2 commit 282204a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/FoundationEssentials/Predicate/NSPredicateConversion.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ extension PredicateExpressions.RangeExpressionContains : ConvertibleExpression {
374374
} else if let rangeValue = (range as? _RangeValue)?._anyRange {
375375
// Otherwise, if the range is a captured value then convert it to appropriate comparison expressions based on the range type
376376
switch rangeValue {
377-
case let .range(upper, lower):
377+
case let .range(lower, upper):
378378
let lowerBoundCondition = _comparison(elementExpr, try _expressionForBound(lower), type: .greaterThanOrEqualTo)
379379
let upperBoundCondition = _comparison(elementExpr, try _expressionForBound(upper), type: .lessThan)
380380
return .predicate(NSCompoundPredicate(andPredicateWithSubpredicates: [lowerBoundCondition, upperBoundCondition]))
381-
case let .closed(upper, lower):
381+
case let .closed(lower, upper):
382382
let lowerValue = try _expressionCompatibleValue(for: lower)
383383
let upperValue = try _expressionCompatibleValue(for: upper)
384384
return .predicate(NSComparisonPredicate(

Tests/FoundationEssentialsTests/PredicateConversionTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ private struct NSPredicateConversionTests {
177177
#expect(!converted.evaluate(with: ObjCObject()))
178178
}
179179

180+
@Test func rangesDistinctBounds() throws {
181+
let lower = Date.distantPast
182+
let upper = Date.distantFuture
183+
let range = lower ..< upper
184+
let predicate = #Predicate<ObjCObject> {
185+
range.contains($0.i)
186+
}
187+
let converted = try #require(convert(predicate))
188+
#expect(converted == NSPredicate(format: "i >= %@ AND i < %@", lower as NSDate, upper as NSDate))
189+
#expect(!converted.evaluate(with: ObjCObject()))
190+
}
191+
180192
@Test func nonObjC() throws {
181193
let predicate = #Predicate<ObjCObject> {
182194
$0.nonObjCKeypath == 2

0 commit comments

Comments
 (0)