Skip to content

Commit 2648457

Browse files
Added more tests to Indexed to check codable conformance of leaf types
1 parent d784480 commit 2648457

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Tests/CodableDatastoreTests/IndexedTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,37 @@ final class IndexedTests: XCTestCase {
110110
print(jsonString)
111111
XCTAssertEqual(jsonString, #"{"age":1,"id":"58167FAA-18C2-43E7-8E31-66E28141C9FE","name":"Hello!","other":[]}"#)
112112
}
113+
114+
func testCodableIndexedString() throws {
115+
let encoder = JSONEncoder()
116+
encoder.outputFormatting = [.sortedKeys]
117+
let data = try encoder.encode(Indexed(wrappedValue: "A string"))
118+
let jsonString = String(data: data, encoding: .utf8)!
119+
let decodedValue = try JSONDecoder().decode(String.self, from: data)
120+
121+
XCTAssertEqual(jsonString, #""A string""#)
122+
XCTAssertEqual(decodedValue, "A string")
123+
}
124+
125+
func testCodableIndexedInt() throws {
126+
let encoder = JSONEncoder()
127+
encoder.outputFormatting = [.sortedKeys]
128+
let data = try encoder.encode(Indexed(wrappedValue: 1234))
129+
let jsonString = String(data: data, encoding: .utf8)!
130+
let decodedValue = try JSONDecoder().decode(Int.self, from: data)
131+
132+
XCTAssertEqual(jsonString, #"1234"#)
133+
XCTAssertEqual(decodedValue, 1234)
134+
}
135+
136+
func testCodableIndexedUUID() throws {
137+
let encoder = JSONEncoder()
138+
encoder.outputFormatting = [.sortedKeys]
139+
let data = try encoder.encode(Indexed(wrappedValue: UUID(uuidString: "00112233-4455-6677-8899-AABBCCDDEEFF")!))
140+
let jsonString = String(data: data, encoding: .utf8)!
141+
let decodedValue = try JSONDecoder().decode(UUID.self, from: data)
142+
143+
XCTAssertEqual(jsonString, #""00112233-4455-6677-8899-AABBCCDDEEFF""#)
144+
XCTAssertEqual(decodedValue, UUID(uuidString: "00112233-4455-6677-8899-AABBCCDDEEFF"))
145+
}
113146
}

0 commit comments

Comments
 (0)