Skip to content

Commit 20ebe9b

Browse files
Adding failing test that includes an optional struct
This test passes with release 0.14.1, but fails starting with 0.15
1 parent e78ae02 commit 20ebe9b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Tests/SQLiteTests/Typed/QueryIntegrationTests.swift

+27
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,33 @@ class QueryIntegrationTests: SQLiteTestCase {
152152
XCTAssertEqual(values.count, 2)
153153
}
154154

155+
func test_insert_custom_encodable_type() throws {
156+
struct TestTypeWithOptionalArray: Codable {
157+
var myInt: Int
158+
var myString: String
159+
var myOptionalArray: [Int]?
160+
}
161+
162+
let table = Table("custom_codable")
163+
try db.run(table.create { builder in
164+
builder.column(Expression<Int?>("myInt"))
165+
builder.column(Expression<String?>("myString"))
166+
builder.column(Expression<String?>("myOptionalArray"))
167+
})
168+
169+
let customType = TestTypeWithOptionalArray(myInt: 13, myString: "foo", myOptionalArray: [1, 2, 3])
170+
try db.run(table.insert(customType))
171+
let rows = try db.prepare(table)
172+
let values: [TestTypeWithOptionalArray] = try rows.map({ try $0.decode() })
173+
XCTAssertEqual(values.count, 1, "return one optional custom type")
174+
175+
let customTypeWithNil = TestTypeWithOptionalArray(myInt: 123, myString: "String", myOptionalArray: nil)
176+
try db.run(table.insert(customTypeWithNil))
177+
let rowsNil = try db.prepare(table)
178+
let valuesNil: [TestTypeWithOptionalArray] = try rowsNil.map({ try $0.decode() })
179+
XCTAssertEqual(valuesNil.count, 2, "return two custom objects, including one that contains a nil optional")
180+
}
181+
155182
func test_upsert() throws {
156183
try XCTSkipUnless(db.satisfiesMinimumVersion(minor: 24))
157184
let fetchAge = { () throws -> Int? in

0 commit comments

Comments
 (0)