Skip to content

Commit

Permalink
Fixed an issue where optional comparisons would not be ordered correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitribouniol committed Apr 20, 2024
1 parent a877838 commit c686708
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/CodableDatastore/Indexes/Indexable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension UInt64: DiscreteIndexable, RangedIndexable {}
extension Optional: Comparable where Wrapped: Comparable {
public static func < (lhs: Self, rhs: Self) -> Bool {
if let lhs, let rhs { return lhs < rhs }
return lhs == nil
return lhs == nil && rhs != nil
}
}
extension Optional: DiscreteIndexable where Wrapped: DiscreteIndexable {}
Expand Down
19 changes: 19 additions & 0 deletions Tests/CodableDatastoreTests/OptionalTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// OptionalTests.swift
// CodableDatastore
//
// Created by Dimitri Bouniol on 2024-04-20.
// Copyright © 2023-24 Mochi Development, Inc. All rights reserved.
//

import XCTest
@testable import CodableDatastore

final class OptionalTests: XCTestCase {
func testComparable() throws {
XCTAssertTrue(Int?.some(5) < Int?.some(10))
XCTAssertTrue(Int?.none < Int?.some(10))
XCTAssertFalse(Int?.some(5) < Int?.none)
XCTAssertFalse(Int?.none < Int?.none)
}
}

0 comments on commit c686708

Please sign in to comment.