@@ -559,6 +559,36 @@ class PostgreSQLConnectionTests: XCTestCase {
559
559
}
560
560
}
561
561
562
+ // https://github.com/vapor/postgresql/pull/111
563
+ func testNumericDecode( ) throws {
564
+ let conn = try PostgreSQLConnection . makeTest ( )
565
+
566
+ let sum = { ( value: String ) -> PostgreSQLSelectExpression in
567
+ . expression( . function( . function( " SUM " , [ . expression( . literal( . numeric( value) ) ) ] ) ) , alias: . identifier( " value " ) )
568
+ }
569
+
570
+ var testValues = [ " 0.543201203 " , " 1000.1 " , " 10000.1 " , " 42.0001 " , " 42.00001 " , " 10234.543201 " , " 102340567.8 " ]
571
+ testValues += testValues. map { " - \( $0) " }
572
+
573
+ struct NumericString : PostgreSQLTable {
574
+ let value : String
575
+ }
576
+
577
+ for value in testValues {
578
+ let result = try conn. select ( ) . column ( sum ( value) ) . first ( decoding: NumericString . self) . wait ( ) ? . value
579
+ XCTAssert ( result == value)
580
+ }
581
+
582
+ struct NumericDouble : PostgreSQLTable {
583
+ let value : Double
584
+ }
585
+
586
+ for value in testValues {
587
+ let result = try conn. select ( ) . column ( sum ( value) ) . first ( decoding: NumericDouble . self) . wait ( ) ? . value
588
+ XCTAssert ( result == Double ( value) )
589
+ }
590
+ }
591
+
562
592
static var allTests = [
563
593
( " testBenchmark " , testBenchmark) ,
564
594
( " testVersion " , testVersion) ,
@@ -579,6 +609,7 @@ class PostgreSQLConnectionTests: XCTestCase {
579
609
( " testInvalidDate " , testInvalidDate) ,
580
610
( " testEmptyArray " , testEmptyArray) ,
581
611
( " testZeroNumeric " , testZeroNumeric) ,
612
+ ( " testNumericDecode " , testNumericDecode) ,
582
613
]
583
614
}
584
615
0 commit comments