diff --git a/Tests/SQLiteTests/QueryIntegrationTests.swift b/Tests/SQLiteTests/QueryIntegrationTests.swift index 4b9c4bbf..b28a6851 100644 --- a/Tests/SQLiteTests/QueryIntegrationTests.swift +++ b/Tests/SQLiteTests/QueryIntegrationTests.swift @@ -106,6 +106,23 @@ class QueryIntegrationTests: SQLiteTestCase { XCTAssertNil(values[0].sub?.sub) } + func test_select_codable_camelCase() throws { + let table = Table("codable_enum") + let column = Expression("camelCaseString") + try db.run(table.create { builder in + builder.column(column) + }) + let value = CamelCaseStruct(camelCaseString: .one) + try db.run(table.insert(value)) + try db.run(table.insert(column <- .one)) + + let rows = try db.prepare(table) + let values: [CamelCaseStruct] = try rows.map({ try $0.decode() }) + XCTAssertEqual(values.count, 2) + XCTAssertEqual(values[0].camelCaseString, .one) + XCTAssertEqual(values[1].camelCaseString, .one) + } + func test_scalar() { XCTAssertEqual(0, try! db.scalar(users.count)) XCTAssertEqual(false, try! db.scalar(users.exists)) diff --git a/Tests/SQLiteTests/TestHelpers.swift b/Tests/SQLiteTests/TestHelpers.swift index a6efa2e7..6c387bd3 100644 --- a/Tests/SQLiteTests/TestHelpers.swift +++ b/Tests/SQLiteTests/TestHelpers.swift @@ -140,3 +140,24 @@ class TestCodable: Codable, Equatable { lhs.sub == rhs.sub } } + +enum StringEnum: String { + case one + case nope +} +extension StringEnum: Codable {} +struct CamelCaseStruct: Codable { + var camelCaseString: StringEnum +} +extension StringEnum: Value { + public typealias Datatype = String + public static var declaredDatatype: String = String.declaredDatatype + + public static func fromDatatypeValue(_ datatypeValue: String) -> StringEnum { + return StringEnum(rawValue: datatypeValue) ?? .nope + } + + public var datatypeValue: String { + return self.rawValue + } +}