Skip to content

Commit 8945b10

Browse files
committed
add failing test case for 0 numeric value
1 parent c8b01a3 commit 8945b10

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift

+21
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,26 @@ class PostgreSQLConnectionTests: XCTestCase {
538538
print(c)
539539
}
540540
}
541+
542+
// https://github.com/vapor/postgresql/pull/109
543+
func testZeroNumeric() throws {
544+
let conn = try PostgreSQLConnection.makeTest()
545+
struct ZeroNumeric: PostgreSQLTable, Equatable {
546+
static let sqlTableIdentifierString = "zeronumerictest"
547+
var foo: Int
548+
}
549+
550+
defer { try? conn.drop(table: ZeroNumeric.self).ifExists().run().wait() }
551+
try conn.create(table: ZeroNumeric.self).column(for: \ZeroNumeric.foo, type: .numeric).run().wait()
552+
553+
let a = ZeroNumeric(foo: 0)
554+
try conn.insert(into: ZeroNumeric.self).value(a).run().wait()
555+
let fetch: [ZeroNumeric] = try conn.select().all().from(ZeroNumeric.self).all(decoding: ZeroNumeric.self).wait()
556+
switch fetch.count {
557+
case 1: XCTAssertEqual(fetch[0].foo, 0)
558+
default: XCTFail("invalid row count")
559+
}
560+
}
541561

542562
static var allTests = [
543563
("testBenchmark", testBenchmark),
@@ -558,6 +578,7 @@ class PostgreSQLConnectionTests: XCTestCase {
558578
("testOrderBy", testOrderBy),
559579
("testInvalidDate", testInvalidDate),
560580
("testEmptyArray", testEmptyArray),
581+
("testZeroNumeric", testZeroNumeric),
561582
]
562583
}
563584

0 commit comments

Comments
 (0)