Add hash tests, incl. a known failing one (#137)

### Motivation

The more we test the more we know about current behavior

### Changes

- Add tests for hashing, incl. a failing one

### Result

We know that our hash implementation isn't respecting different header
order
This commit is contained in:
Fabian Fett authored and GitHub committed 2026-08-14 12:56:29 +02:00
1 parent e84a4ff0bc
commit 4b1dd0cab3
1 file changed
+38
+38
View File
@@ -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 }