Skip to content
Merged
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
38 changes: 38 additions & 0 deletions Tests/HTTPTypesTests/HTTPTypesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,44 @@ extension HTTPField.Name {
#expect(fields1 != fields6)
}

@Test func hashMatchesEqualityForSameOrder() {
let fields1: HTTPFields = [
.acceptEncoding: "br",
.acceptEncoding: "gzip",
.accept: "*/*",
]

let fields2: HTTPFields = [
.acceptEncoding: "br",
.acceptEncoding: "gzip",
.accept: "*/*",
]
#expect(fields1 == fields2)
#expect(fields1.hashValue == fields2.hashValue)
}

@Test func hashMatchesEqualityForDifferentOrder() {
let fields1: HTTPFields = [
.acceptEncoding: "br",
.acceptEncoding: "gzip",
.accept: "*/*",
]

// Fields with differently named fields in a different order are equal, since the
// relative order of same-named fields is preserved.
let fields2: HTTPFields = [
.acceptEncoding: "br",
.accept: "*/*",
.acceptEncoding: "gzip",
]
#expect(fields1 == fields2)

// Equal values must therefore hash equally.
withKnownIssue("HTTPFields.hash(into:) is order sensitive while == is not") {
#expect(fields1.hashValue == fields2.hashValue)
}
}

@Test func sendable() {
func isSendable(_ value: some Sendable) -> Bool { true }
func isSendable(_ value: Any) -> Bool { false }
Expand Down
Loading