Skip to content

Commit f59a814

Browse files
authored
SWIFT-659 Remove ExpressibleByArrayLiteral conformance from Document (#347)
1 parent 7ccdd89 commit f59a814

File tree

5 files changed

+12
-48
lines changed

5 files changed

+12
-48
lines changed

Sources/MongoSwift/BSON/Document.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -545,24 +545,6 @@ internal func withMutableBSONPointer<T>(
545545
return try body(document._storage._bson)
546546
}
547547

548-
/// An extension of `Document` to add the capability to be initialized with an array literal.
549-
extension Document: ExpressibleByArrayLiteral {
550-
/**
551-
* Initializes a `Document` using an array literal where the values
552-
* are `BSONValue`s. Values are stored under a string of their
553-
* index in the array. For example:
554-
* `d: Document = ["a", "b"]` will become `["0": "a", "1": "b"]`
555-
*
556-
* - Parameters:
557-
* - arrayLiteral: a `[BSONValue]`
558-
*
559-
* - Returns: a new `Document`
560-
*/
561-
public init(arrayLiteral elements: BSON...) {
562-
self.init(elements)
563-
}
564-
}
565-
566548
// An extension of `Document` to add the capability to be hashed
567549
extension Document: Hashable {
568550
public func hash(into hasher: inout Hasher) {

Tests/LinuxMain.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ extension DocumentTests {
111111
static var allTests = [
112112
("testDocument", testDocument),
113113
("testDocumentDynamicMemberLookup", testDocumentDynamicMemberLookup),
114-
("testDocumentFromArray", testDocumentFromArray),
115114
("testEquatable", testEquatable),
116115
("testRawBSON", testRawBSON),
117116
("testValueBehavior", testValueBehavior),

Tests/MongoSwiftTests/Document+SequenceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ final class Document_SequenceTests: MongoSwiftTestCase {
262262
expect(self.smallDoc.suffix(2)).to(equal(self.smallDoc))
263263
expect(self.smallDoc.suffix(5)).to(equal(self.smallDoc))
264264

265-
expect(self.doc.suffix(0)).to(equal([]))
265+
expect(self.doc.suffix(0)).to(equal([:]))
266266
expect(self.doc.suffix(1)).to(equal(["g": 10]))
267267
expect(self.doc.suffix(2)).to(equal(["f": .minKey, "g": 10]))
268268
expect(self.doc.suffix(4)).to(equal(["d": false, "e": .null, "f": .minKey, "g": 10]))

Tests/MongoSwiftTests/DocumentTests.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,6 @@ final class DocumentTests: MongoSwiftTestCase {
243243
expect(doc.b).to(equal("different"))
244244
}
245245

246-
func testDocumentFromArray() {
247-
let doc1: Document = ["foo", .minKey, .null]
248-
249-
expect(doc1.keys).to(equal(["0", "1", "2"]))
250-
expect(doc1["0"]).to(equal("foo"))
251-
expect(doc1["1"]).to(equal(.minKey))
252-
expect(doc1["2"]).to(equal(.null))
253-
254-
let elements: [BSON] = ["foo", .minKey, .null]
255-
let doc2 = Document(elements)
256-
257-
expect(doc2.keys).to(equal(["0", "1", "2"]))
258-
expect(doc2["0"]).to(equal("foo"))
259-
expect(doc2["1"]).to(equal(.minKey))
260-
expect(doc2["2"]).to(equal(.null))
261-
}
262-
263246
func testEquatable() {
264247
expect(["hi": true, "hello": "hi", "cat": 2] as Document)
265248
.to(equal(["hi": true, "hello": "hi", "cat": 2] as Document))

Tests/MongoSwiftTests/ReadPreferenceTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ final class ReadPreferenceTests: MongoSwiftTestCase {
3131
let rpNoTagSets = try ReadPreference(.nearest, tagSets: nil)
3232
expect(rpNoTagSets.tagSets).to(equal([]))
3333

34-
let rpSomeTagSets = try ReadPreference(.nearest, tagSets: [["dc": "east"], []])
35-
expect(rpSomeTagSets.tagSets).to(equal([["dc": "east"], []]))
34+
let rpSomeTagSets = try ReadPreference(.nearest, tagSets: [["dc": "east"], [:]])
35+
expect(rpSomeTagSets.tagSets).to(equal([["dc": "east"], [:]]))
3636

37-
let rpOnlyEmptyTagSet = try ReadPreference(.nearest, tagSets: [[]])
38-
expect(rpOnlyEmptyTagSet.tagSets).to(equal([[]]))
37+
let rpOnlyEmptyTagSet = try ReadPreference(.nearest, tagSets: [[:]])
38+
expect(rpOnlyEmptyTagSet.tagSets).to(equal([[:]]))
3939

4040
// Non-empty tag sets cannot be combined with primary mode
41-
expect(try ReadPreference(.primary, tagSets: [["dc": "east"], []]))
41+
expect(try ReadPreference(.primary, tagSets: [["dc": "east"], [:]]))
4242
.to(throwError(UserError.invalidArgumentError(message: "")))
43-
expect(try ReadPreference(.primary, tagSets: [[]])).to(throwError(UserError.invalidArgumentError(message: "")))
43+
expect(try ReadPreference(.primary, tagSets: [[:]])).to(throwError(UserError.invalidArgumentError(message: "")))
4444
}
4545

4646
func testMaxStalenessSeconds() throws {
@@ -80,11 +80,11 @@ final class ReadPreferenceTests: MongoSwiftTestCase {
8080
.to(equal(ReadPreference(.secondary)))
8181
expect(try ReadPreference(.secondary, tagSets: []))
8282
.to(equal(try ReadPreference(.secondary, tagSets: [])))
83-
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], []]))
84-
.to(equal(try ReadPreference(.secondary, tagSets: [["dc": "east"], []])))
85-
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], []]))
86-
.toNot(equal(try ReadPreference(.nearest, tagSets: [["dc": "east"], []])))
87-
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], []]))
83+
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]]))
84+
.to(equal(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]])))
85+
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]]))
86+
.toNot(equal(try ReadPreference(.nearest, tagSets: [["dc": "east"], [:]])))
87+
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]]))
8888
.toNot(equal(try ReadPreference(.secondary, maxStalenessSeconds: 90)))
8989

9090
expect(try ReadPreference(.secondaryPreferred, maxStalenessSeconds: nil))

0 commit comments

Comments
 (0)