Skip to content

Commit 2aff76f

Browse files
authored
SWIFT-297 Use synthesized Equatable where possible (#229)
1 parent a681184 commit 2aff76f

File tree

6 files changed

+0
-107
lines changed

6 files changed

+0
-107
lines changed

Sources/MongoSwift/BSON/BSONValue.swift

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ public struct BSONNull: BSONValue, Codable, Equatable {
157157
throw bsonTooLargeError(value: self, forKey: key)
158158
}
159159
}
160-
161-
public static func == (lhs: BSONNull, rhs: BSONNull) -> Bool {
162-
return true
163-
}
164160
}
165161

166162
/// A struct to represent the BSON Binary type.
@@ -285,10 +281,6 @@ public struct Binary: BSONValue, Equatable, Codable {
285281
let dataObj = Data(bytes: data, count: Int(length))
286282
return try self.init(data: dataObj, subtype: UInt8(subtype.rawValue))
287283
}
288-
289-
public static func == (lhs: Binary, rhs: Binary) -> Bool {
290-
return lhs.data == rhs.data && lhs.subtype == rhs.subtype
291-
}
292284
}
293285

294286
/// An extension of `Bool` to represent the BSON Boolean type.
@@ -391,10 +383,6 @@ public struct DBPointer: BSONValue, Codable, Equatable {
391383

392384
return DBPointer(ref: String(cString: collectionP), id: ObjectId(fromPointer: oidP))
393385
}
394-
395-
public static func == (lhs: DBPointer, rhs: DBPointer) -> Bool {
396-
return lhs.ref == rhs.ref && lhs.id == rhs.id
397-
}
398386
}
399387

400388
/// A struct to represent the BSON Decimal128 type.
@@ -620,10 +608,6 @@ public struct CodeWithScope: BSONValue, Equatable, Codable {
620608

621609
return self.init(code: code, scope: scopeDoc)
622610
}
623-
624-
public static func == (lhs: CodeWithScope, rhs: CodeWithScope) -> Bool {
625-
return lhs.code == rhs.code && lhs.scope == rhs.scope
626-
}
627611
}
628612

629613
/// A struct to represent the BSON MaxKey type.
@@ -655,8 +639,6 @@ public struct MaxKey: BSONValue, Equatable, Codable {
655639
}
656640
return MaxKey()
657641
}
658-
659-
public static func == (lhs: MaxKey, rhs: MaxKey) -> Bool { return true }
660642
}
661643

662644
/// A struct to represent the BSON MinKey type.
@@ -688,8 +670,6 @@ public struct MinKey: BSONValue, Equatable, Codable {
688670
}
689671
return MinKey()
690672
}
691-
692-
public static func == (lhs: MinKey, rhs: MinKey) -> Bool { return true }
693673
}
694674

695675
/// A struct to represent the BSON ObjectId type.
@@ -904,11 +884,6 @@ public struct RegularExpression: BSONValue, Equatable, Codable {
904884

905885
return self.init(pattern: patternString, options: optionsString)
906886
}
907-
908-
/// Returns `true` if the two `RegularExpression`s have matching patterns and options, and `false` otherwise.
909-
public static func == (lhs: RegularExpression, rhs: RegularExpression) -> Bool {
910-
return lhs.pattern == rhs.pattern && lhs.options == rhs.options
911-
}
912887
}
913888

914889
/// An extension of String to represent the BSON string type.
@@ -991,10 +966,6 @@ public struct Symbol: BSONValue, CustomStringConvertible, Codable, Equatable {
991966

992967
return Symbol(strValue)
993968
}
994-
995-
public static func == (lhs: Symbol, rhs: Symbol) -> Bool {
996-
return lhs.stringValue == rhs.stringValue
997-
}
998969
}
999970

1000971
/// A struct to represent the BSON Timestamp type.
@@ -1044,10 +1015,6 @@ public struct Timestamp: BSONValue, Equatable, Codable {
10441015

10451016
return self.init(timestamp: t, inc: i)
10461017
}
1047-
1048-
public static func == (lhs: Timestamp, rhs: Timestamp) -> Bool {
1049-
return lhs.timestamp == rhs.timestamp && lhs.increment == rhs.increment
1050-
}
10511018
}
10521019

10531020
/// A struct to represent the deprecated Undefined type.
@@ -1077,10 +1044,6 @@ public struct BSONUndefined: BSONValue, Equatable, Codable {
10771044
}
10781045
return BSONUndefined()
10791046
}
1080-
1081-
public static func == (lhs: BSONUndefined, rhs: BSONUndefined) -> Bool {
1082-
return true
1083-
}
10841047
}
10851048

10861049
// See https://github.com/realm/SwiftLint/issues/461

Sources/MongoSwift/SDAM.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public struct ConnectionId: Equatable {
2828
// swiftlint:disable:next force_unwrapping - should be valid UInt16 unless server response malformed.
2929
self.port = UInt16(parts[1])!
3030
}
31-
32-
/// ConnectionIds are equal if their hosts and ports match.
33-
public static func == (lhs: ConnectionId, rhs: ConnectionId) -> Bool {
34-
return lhs.host == rhs.host && rhs.port == lhs.port
35-
}
3631
}
3732

3833
/// A struct describing a mongod or mongos process.

Sources/MongoSwift/WriteConcern.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,6 @@ public class WriteConcern: Codable {
3636
try container.encode("majority")
3737
}
3838
}
39-
40-
public static func == (lhs: W, rhs: W) -> Bool {
41-
switch (lhs, rhs) {
42-
case let (.number(lNum), .number(rNum)):
43-
return lNum == rNum
44-
case let (.tag(lTag), .tag(rTag)):
45-
return lTag == rTag
46-
case (.majority, .majority):
47-
return true
48-
default:
49-
return false
50-
}
51-
}
5239
}
5340

5441
/// Indicates the `W` value for this `WriteConcern`.

Tests/MongoSwiftTests/CodecTests.swift

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,19 @@ final class CodecTests: MongoSwiftTestCase {
3232
struct BasicStruct: Codable, Equatable {
3333
let int: Int
3434
let string: String
35-
36-
public static func == (lhs: BasicStruct, rhs: BasicStruct) -> Bool {
37-
return lhs.int == rhs.int && lhs.string == rhs.string
38-
}
3935
}
4036

4137
struct NestedStruct: Codable, Equatable {
4238
let s1: BasicStruct
4339
let s2: BasicStruct
44-
45-
public static func == (lhs: NestedStruct, rhs: NestedStruct) -> Bool {
46-
return lhs.s1 == rhs.s1 && lhs.s2 == rhs.s2
47-
}
4840
}
4941

5042
struct NestedArray: Codable, Equatable {
5143
let array: [BasicStruct]
52-
53-
public static func == (lhs: NestedArray, rhs: NestedArray) -> Bool {
54-
return lhs.array == rhs.array
55-
}
5644
}
5745

5846
struct NestedNestedStruct: Codable, Equatable {
5947
let s: NestedStruct
60-
61-
public static func == (lhs: NestedNestedStruct, rhs: NestedNestedStruct) -> Bool {
62-
return lhs.s == rhs.s
63-
}
6448
}
6549

6650
/// Test encoding/decoding a variety of structs containing simple types that have
@@ -111,10 +95,6 @@ final class CodecTests: MongoSwiftTestCase {
11195
let int: Int?
11296
let bool: Bool?
11397
let string: String
114-
115-
public static func == (lhs: OptionalsStruct, rhs: OptionalsStruct) -> Bool {
116-
return lhs.int == rhs.int && lhs.bool == rhs.bool && lhs.string == rhs.string
117-
}
11898
}
11999

120100
/// Test encoding/decoding a struct containing optional values.
@@ -149,13 +129,6 @@ final class CodecTests: MongoSwiftTestCase {
149129

150130
static let keys = ["int8", "int16", "uint8", "uint16", "uint32", "uint64", "uint", "float"]
151131

152-
public static func == (lhs: Numbers, rhs: Numbers) -> Bool {
153-
return lhs.int8 == rhs.int8 && lhs.int16 == rhs.int16 &&
154-
lhs.uint8 == rhs.uint8 && lhs.uint16 == rhs.uint16 &&
155-
lhs.uint32 == rhs.uint32 && lhs.uint64 == rhs.uint64 &&
156-
lhs.uint == rhs.uint && lhs.float == rhs.float
157-
}
158-
159132
init(int8: Int8? = nil,
160133
int16: Int16? = nil,
161134
uint8: UInt8? = nil,
@@ -265,11 +238,6 @@ final class CodecTests: MongoSwiftTestCase {
265238
let int32: Int32
266239
let int64: Int64
267240
let double: Double
268-
269-
public static func == (lhs: BSONNumbers, rhs: BSONNumbers) -> Bool {
270-
return lhs.int == rhs.int && lhs.int32 == rhs.int32 &&
271-
lhs.int64 == rhs.int64 && lhs.double == rhs.double
272-
}
273241
}
274242

275243
/// Test that BSON number types are encoded properly, and can be decoded from any type they are stored as
@@ -321,16 +289,6 @@ final class CodecTests: MongoSwiftTestCase {
321289
let dbpointer: DBPointer
322290
let null: BSONNull
323291

324-
public static func == (lhs: AllBSONTypes, rhs: AllBSONTypes) -> Bool {
325-
return lhs.double == rhs.double && lhs.string == rhs.string &&
326-
lhs.doc == rhs.doc && lhs.arr == rhs.arr && lhs.binary == rhs.binary &&
327-
lhs.oid == rhs.oid && lhs.bool == rhs.bool && lhs.code == rhs.code &&
328-
lhs.int == rhs.int && lhs.ts == rhs.ts && lhs.int32 == rhs.int32 &&
329-
lhs.int64 == rhs.int64 && lhs.dec == rhs.dec && lhs.minkey == rhs.minkey &&
330-
lhs.maxkey == rhs.maxkey && lhs.regex == rhs.regex && lhs.date == rhs.date &&
331-
lhs.symbol == rhs.symbol && lhs.dbpointer == rhs.dbpointer && lhs.null == rhs.null
332-
}
333-
334292
public static func factory() throws -> AllBSONTypes {
335293
return AllBSONTypes(
336294
double: Double(2),

Tests/MongoSwiftTests/MongoCollectionTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,6 @@ final class MongoCollectionTests: MongoSwiftTestCase {
367367
struct Basic: Codable, Equatable {
368368
let x: Int
369369
let y: String
370-
371-
static func == (lhs: Basic, rhs: Basic) -> Bool {
372-
return lhs.x == rhs.x && lhs.y == rhs.y
373-
}
374370
}
375371

376372
func testCodableCollection() throws {

Tests/MongoSwiftTests/TestUtils.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ extension MongoClient {
112112
self.patch = patch ?? 0
113113
}
114114

115-
static func == (lhs: ServerVersion, rhs: ServerVersion) -> Bool {
116-
return lhs.major == rhs.major &&
117-
lhs.minor == rhs.minor &&
118-
lhs.patch == rhs.patch
119-
}
120-
121115
func isLessThan(_ version: ServerVersion) -> Bool {
122116
if self.major == version.major {
123117
if self.minor == version.minor {

0 commit comments

Comments
 (0)