diff --git a/Sources/CodableDatastore/Indexes/Indexable.swift b/Sources/CodableDatastore/Indexes/Indexable.swift index b7e3481..d08cd2d 100644 --- a/Sources/CodableDatastore/Indexes/Indexable.swift +++ b/Sources/CodableDatastore/Indexes/Indexable.swift @@ -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 {} diff --git a/Tests/CodableDatastoreTests/OptionalTests.swift b/Tests/CodableDatastoreTests/OptionalTests.swift new file mode 100644 index 0000000..84b64a0 --- /dev/null +++ b/Tests/CodableDatastoreTests/OptionalTests.swift @@ -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) + } +}