Skip to content

Commit b9960b8

Browse files
committed
Updated unit tests
1 parent 6f1a81c commit b9960b8

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

Tests/TLVCodingTests/TLVCodingTests.swift

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import XCTest
1212

1313
final class TLVCodingTests: XCTestCase {
1414

15-
static var allTests = [
15+
static let allTests = [
1616
("testCodable", testCodable),
1717
("testCodingKeys", testCodingKeys),
18-
("testUUID", testUUID)
18+
("testUUID", testUUID),
19+
("testDate", testDate),
20+
("testDateSecondsSince1970", testDateSecondsSince1970)
1921
]
2022

2123
func testCodable() {
@@ -293,6 +295,28 @@ final class TLVCodingTests: XCTestCase {
293295
}
294296
}
295297
}
298+
299+
func testDateSecondsSince1970() {
300+
301+
let date = Date(timeIntervalSince1970: 60 * 60 * 24 * 365)
302+
303+
let value = Transaction(
304+
id: UUID(),
305+
date: date,
306+
description: "Test"
307+
)
308+
309+
let rawValue = TransactionRaw(
310+
id: value.id,
311+
date: value.date.timeIntervalSince1970,
312+
description: value.description
313+
)
314+
315+
var encoder = TLVEncoder()
316+
encoder.dateFormat = .secondsSince1970
317+
encoder.log = { print("Encoder:", $0) }
318+
XCTAssertEqual(try encoder.encode(value), try encoder.encode(rawValue))
319+
}
296320
}
297321

298322
// MARK: - Supporting Types
@@ -309,6 +333,20 @@ public enum Gender: UInt8, Codable {
309333
case female
310334
}
311335

336+
public struct Transaction: Equatable, Codable {
337+
338+
public let id: UUID
339+
public let date: Date
340+
public let description: String
341+
}
342+
343+
public struct TransactionRaw: Equatable, Codable {
344+
345+
public let id: UUID
346+
public let date: Double
347+
public let description: String
348+
}
349+
312350
public struct ProvisioningState: Codable, Equatable {
313351

314352
public var state: State

0 commit comments

Comments
 (0)