Skip to content

Commit 6c4ca52

Browse files
committed
104 -- Add real world test case to ensure revrange bug doesn't persist
1 parent b449334 commit 6c4ca52

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Tests/RediStackIntegrationTests/Commands/SortedSetCommandsTests.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,55 @@ final class SortedSetCommandsTests: RediStackIntegrationTestCase {
512512
XCTAssertEqual(count, 1)
513513
}
514514
}
515+
516+
// MARK: - #104 zrevrange & zrange bug
517+
518+
extension SortedSetCommandsTests {
519+
func test_zrange_realworld() throws {
520+
struct Keys {
521+
static let first = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0185"
522+
static let second = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0186"
523+
static let third = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0187"
524+
static let fourth = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0188"
525+
static let fifth = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0189"
526+
}
527+
_ = try self.connection.send(.zadd([
528+
(Keys.first, 1),
529+
(Keys.second, 1),
530+
(Keys.third, 1),
531+
(Keys.fourth, 1),
532+
(Keys.fifth, 1),
533+
], to: #function)).wait()
534+
535+
let elements = try self.connection.send(.zrange(from: #function, fromIndex: 0, returning: .valuesOnly))
536+
.wait()
537+
.compactMap(\.string)
538+
539+
XCTAssertEqual(elements.count, 5)
540+
XCTAssertEqual(elements, elements.sorted(by: <))
541+
}
542+
543+
func test_zrevrange_realworld() throws {
544+
struct Keys {
545+
static let first = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0185"
546+
static let second = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0186"
547+
static let third = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0187"
548+
static let fourth = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0188"
549+
static let fifth = "1E4FD2C5-C32E-4E3F-91B3-45478BCF0189"
550+
}
551+
_ = try self.connection.send(.zadd([
552+
(Keys.first, 1),
553+
(Keys.second, 1),
554+
(Keys.third, 1),
555+
(Keys.fourth, 1),
556+
(Keys.fifth, 1),
557+
], to: #function)).wait()
558+
559+
let elements = try self.connection.send(.zrevrange(from: #function, fromIndex: 0, returning: .valuesOnly))
560+
.wait()
561+
.compactMap(\.string)
562+
563+
XCTAssertEqual(elements.count, 5)
564+
XCTAssertEqual(elements, elements.sorted(by: >))
565+
}
566+
}

0 commit comments

Comments
 (0)