mirror of
https://github.com/apple/swift-http-types
synced 2026-11-22 04:30:40 +00:00
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:
1 parent
e84a4ff0bc
commit
4b1dd0cab3
1 file changed
+38
@@ -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 }
|
||||
|
||||
Reference in new issue
Block a user