Skip to content

Commit 498b6a5

Browse files
committed
Conform RedisCommand to Equatable
1 parent 252b0b8 commit 498b6a5

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Sources/RediStack/Commands/RedisCommand.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the RediStack open source project
44
//
5-
// Copyright (c) 2020 RediStack project authors
5+
// Copyright (c) 2020-2022 RediStack project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -83,6 +83,16 @@ extension RedisCommand where ResultType == Void {
8383
}
8484
}
8585

86+
87+
// MARK: Equatable
88+
extension RedisCommand: Equatable {
89+
public static func ==<T>(lhs: RedisCommand<T>, rhs: RedisCommand<T>) -> Bool {
90+
return lhs.keyword == rhs.keyword && lhs.arguments == rhs.arguments
91+
}
92+
}
93+
94+
// MARK: - Common helpers
95+
8696
extension RedisCommand {
8797
@usableFromInline
8898
internal static func _scan<T>(
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the RediStack open source project
4+
//
5+
// Copyright (c) 2022 RediStack project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of RediStack project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import RediStack
16+
import XCTest
17+
18+
final class RedisCommandTests: XCTestCase { }
19+
20+
// MARK: Equatable Tests
21+
22+
extension RedisCommandTests {
23+
func test_equatableConformance() {
24+
let first = RedisCommand<String>(keyword: #function, arguments: [])
25+
let second = RedisCommand<String>(keyword: #function, arguments: [])
26+
XCTAssertEqual(first, second)
27+
28+
let third = RedisCommand<String>(keyword: #function, arguments: [#line.convertedToRESPValue()])
29+
XCTAssertNotEqual(first, third)
30+
XCTAssertNotEqual(second, third)
31+
32+
let fourth = RedisCommand<String>(keyword: "buzz", arguments: [])
33+
XCTAssertNotEqual(first, fourth)
34+
XCTAssertNotEqual(third, fourth)
35+
}
36+
}

0 commit comments

Comments
 (0)