mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-28 05:04:22 +00:00
Add support for Date type to StructuredFieldValues (#49)
Motivation: The parser and serializer for the Date type has been implemented. The high-level encoder and decoder should follow. Modifications: - Implement the encoder and decoder for Date. Result: The StructuredFieldValues module will support the Date type.
This commit is contained in:
1 parent
c2e79ce44c
commit
6e527aa16a
12 files changed
+222
No files matched your search
@@ -43,6 +43,16 @@ final class StructuredFieldEncoderTests: XCTestCase {
|
||||
|
||||
// Binary Data
|
||||
XCTAssertEqual(Array(":AQIDBA==:".utf8), try encoder.encode(ItemField(Data([1, 2, 3, 4]))))
|
||||
|
||||
// Date
|
||||
XCTAssertEqual(
|
||||
Array("@4294967296".utf8),
|
||||
try encoder.encode(ItemField(Date(timeIntervalSince1970: 4_294_967_296)))
|
||||
)
|
||||
XCTAssertEqual(
|
||||
Array("@-1659578233".utf8),
|
||||
try encoder.encode(ItemField(Date(timeIntervalSince1970: -1_659_578_233)))
|
||||
)
|
||||
}
|
||||
|
||||
func testEncodeKeyedItemHeader() throws {
|
||||
@@ -96,6 +106,26 @@ final class StructuredFieldEncoderTests: XCTestCase {
|
||||
Array(":AQIDBA==:".utf8),
|
||||
try encoder.encode(KeyedItem(item: Data([1, 2, 3, 4]), parameters: [:]))
|
||||
)
|
||||
|
||||
// Date
|
||||
XCTAssertEqual(
|
||||
Array("@4294967296;x".utf8),
|
||||
try encoder.encode(
|
||||
KeyedItem(
|
||||
item: Date(timeIntervalSince1970: 4_294_967_296),
|
||||
parameters: ["x": true]
|
||||
)
|
||||
)
|
||||
)
|
||||
XCTAssertEqual(
|
||||
Array("@-1659578233".utf8),
|
||||
try encoder.encode(
|
||||
KeyedItem(
|
||||
item: Date(timeIntervalSince1970: -1_659_578_233),
|
||||
parameters: [:]
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
func testEncodeKeyedItemHeaderWithParamsAsStruct() throws {
|
||||
@@ -189,6 +219,19 @@ final class StructuredFieldEncoderTests: XCTestCase {
|
||||
Array(":AQIDBA==:, :BQYHCA==:".utf8),
|
||||
try encoder.encode(List([Data([1, 2, 3, 4]), Data([5, 6, 7, 8])]))
|
||||
)
|
||||
|
||||
// Date
|
||||
XCTAssertEqual(
|
||||
Array("@4294967296, @-1659578233".utf8),
|
||||
try encoder.encode(
|
||||
List(
|
||||
[
|
||||
Date(timeIntervalSince1970: 4_294_967_296),
|
||||
Date(timeIntervalSince1970: -1_659_578_233),
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
func testListFieldInnerItemsWithDict() throws {
|
||||
|
||||
Reference in new issue
Block a user