Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Sources/MongoSwift/BSON/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,24 +545,6 @@ internal func withMutableBSONPointer<T>(
return try body(document._storage._bson)
}

/// An extension of `Document` to add the capability to be initialized with an array literal.
extension Document: ExpressibleByArrayLiteral {
/**
* Initializes a `Document` using an array literal where the values
* are `BSONValue`s. Values are stored under a string of their
* index in the array. For example:
* `d: Document = ["a", "b"]` will become `["0": "a", "1": "b"]`
*
* - Parameters:
* - arrayLiteral: a `[BSONValue]`
*
* - Returns: a new `Document`
*/
public init(arrayLiteral elements: BSON...) {
self.init(elements)
}
}

// An extension of `Document` to add the capability to be hashed
extension Document: Hashable {
public func hash(into hasher: inout Hasher) {
Expand Down
1 change: 0 additions & 1 deletion Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ extension DocumentTests {
static var allTests = [
("testDocument", testDocument),
("testDocumentDynamicMemberLookup", testDocumentDynamicMemberLookup),
("testDocumentFromArray", testDocumentFromArray),
("testEquatable", testEquatable),
("testRawBSON", testRawBSON),
("testValueBehavior", testValueBehavior),
Expand Down
2 changes: 1 addition & 1 deletion Tests/MongoSwiftTests/Document+SequenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ final class Document_SequenceTests: MongoSwiftTestCase {
expect(self.smallDoc.suffix(2)).to(equal(self.smallDoc))
expect(self.smallDoc.suffix(5)).to(equal(self.smallDoc))

expect(self.doc.suffix(0)).to(equal([]))
expect(self.doc.suffix(0)).to(equal([:]))
expect(self.doc.suffix(1)).to(equal(["g": 10]))
expect(self.doc.suffix(2)).to(equal(["f": .minKey, "g": 10]))
expect(self.doc.suffix(4)).to(equal(["d": false, "e": .null, "f": .minKey, "g": 10]))
Expand Down
17 changes: 0 additions & 17 deletions Tests/MongoSwiftTests/DocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,6 @@ final class DocumentTests: MongoSwiftTestCase {
expect(doc.b).to(equal("different"))
}

func testDocumentFromArray() {
let doc1: Document = ["foo", .minKey, .null]

expect(doc1.keys).to(equal(["0", "1", "2"]))
expect(doc1["0"]).to(equal("foo"))
expect(doc1["1"]).to(equal(.minKey))
expect(doc1["2"]).to(equal(.null))

let elements: [BSON] = ["foo", .minKey, .null]
let doc2 = Document(elements)

expect(doc2.keys).to(equal(["0", "1", "2"]))
expect(doc2["0"]).to(equal("foo"))
expect(doc2["1"]).to(equal(.minKey))
expect(doc2["2"]).to(equal(.null))
}

func testEquatable() {
expect(["hi": true, "hello": "hi", "cat": 2] as Document)
.to(equal(["hi": true, "hello": "hi", "cat": 2] as Document))
Expand Down
22 changes: 11 additions & 11 deletions Tests/MongoSwiftTests/ReadPreferenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ final class ReadPreferenceTests: MongoSwiftTestCase {
let rpNoTagSets = try ReadPreference(.nearest, tagSets: nil)
expect(rpNoTagSets.tagSets).to(equal([]))

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

let rpOnlyEmptyTagSet = try ReadPreference(.nearest, tagSets: [[]])
expect(rpOnlyEmptyTagSet.tagSets).to(equal([[]]))
let rpOnlyEmptyTagSet = try ReadPreference(.nearest, tagSets: [[:]])
expect(rpOnlyEmptyTagSet.tagSets).to(equal([[:]]))

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

func testMaxStalenessSeconds() throws {
Expand Down Expand Up @@ -80,11 +80,11 @@ final class ReadPreferenceTests: MongoSwiftTestCase {
.to(equal(ReadPreference(.secondary)))
expect(try ReadPreference(.secondary, tagSets: []))
.to(equal(try ReadPreference(.secondary, tagSets: [])))
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], []]))
.to(equal(try ReadPreference(.secondary, tagSets: [["dc": "east"], []])))
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], []]))
.toNot(equal(try ReadPreference(.nearest, tagSets: [["dc": "east"], []])))
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], []]))
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]]))
.to(equal(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]])))
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]]))
.toNot(equal(try ReadPreference(.nearest, tagSets: [["dc": "east"], [:]])))
expect(try ReadPreference(.secondary, tagSets: [["dc": "east"], [:]]))
.toNot(equal(try ReadPreference(.secondary, maxStalenessSeconds: 90)))

expect(try ReadPreference(.secondaryPreferred, maxStalenessSeconds: nil))
Expand Down