Skip to content

Commit

Permalink
Reimplement array equality check
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed Jun 16, 2020
1 parent 693083a commit bb46957
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions Sources/BSON/Document/Document+Equatable.swift
Expand Up @@ -10,13 +10,26 @@ extension Document: Equatable {
return false
}

for key in lhs.keys {
guard
let lhsValue = lhs[key],
let rhsValue = rhs[key],
lhsValue.equals(rhsValue)
else {
return false
if lhs.isArray {
for i in 0..<lhs.count {
let lhsValue = lhs[i]
let rhsValue = rhs[i]

guard
lhsValue.equals(rhsValue)
else {
return false
}
}
} else {
for key in lhs.keys {
guard
let lhsValue = lhs[key],
let rhsValue = rhs[key],
lhsValue.equals(rhsValue)
else {
return false
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/BSONTests/BSONPublicTests.swift
Expand Up @@ -145,10 +145,10 @@ final class BSONPublicTests: XCTestCase {
}

func testRemoveArray() throws {
var array: Document = ["A", "B", "C"]
var array: Document = ["ACXZCXZCXZZX", "BaSDASDASAS", "C"]
XCTAssertEqual(array.values.count, 3)
array.remove(at: 0)
XCTAssertEqual(array, ["B", "C"])
XCTAssertEqual(array, ["BaSDASDASAS", "C"])
}

func testDecodeSingleValue() throws {
Expand Down

0 comments on commit bb46957

Please sign in to comment.