updated to use boolean IsNaN field on Numeric
This commit is contained in:
+12
-6
@@ -210,8 +210,8 @@ func TestNumericSet(t *testing.T) {
|
||||
{source: float64(1234), result: &pgtype.Numeric{Int: big.NewInt(1234), Exp: 0, Status: pgtype.Present}},
|
||||
{source: float64(12345678900), result: &pgtype.Numeric{Int: big.NewInt(123456789), Exp: 2, Status: pgtype.Present}},
|
||||
{source: float64(12345.678901), result: &pgtype.Numeric{Int: big.NewInt(12345678901), Exp: -6, Status: pgtype.Present}},
|
||||
{source: math.NaN(), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Undefined}},
|
||||
{source: float32(math.NaN()), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Undefined}},
|
||||
{source: math.NaN(), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Present, IsNaN: true}},
|
||||
{source: float32(math.NaN()), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Present, IsNaN: true}},
|
||||
}
|
||||
|
||||
for i, tt := range successfulTests {
|
||||
@@ -269,8 +269,8 @@ func TestNumericAssignTo(t *testing.T) {
|
||||
{src: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Null}, dst: &pi8, expected: ((*int8)(nil))},
|
||||
{src: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Null}, dst: &_pi8, expected: ((*_int8)(nil))},
|
||||
{src: &pgtype.Numeric{Int: big.NewInt(1006), Exp: -2, Status: pgtype.Present}, dst: &f64, expected: float64(10.06)}, // https://github.com/jackc/pgtype/issues/27
|
||||
{src: &pgtype.Numeric{}, dst: &f64, expected: math.NaN()},
|
||||
{src: &pgtype.Numeric{}, dst: &f32, expected: float32(math.NaN())},
|
||||
{src: &pgtype.Numeric{Status: pgtype.Present, IsNaN: true}, dst: &f64, expected: math.NaN()},
|
||||
{src: &pgtype.Numeric{Status: pgtype.Present, IsNaN: true}, dst: &f32, expected: float32(math.NaN())},
|
||||
}
|
||||
|
||||
for i, tt := range simpleTests {
|
||||
@@ -282,11 +282,17 @@ func TestNumericAssignTo(t *testing.T) {
|
||||
dst := reflect.ValueOf(tt.dst).Elem().Interface()
|
||||
switch dstTyped := dst.(type) {
|
||||
case float32:
|
||||
if math.IsNaN(float64(tt.expected.(float32))) && !math.IsNaN(float64(dstTyped)) {
|
||||
nanExpected := math.IsNaN(float64(tt.expected.(float32)))
|
||||
if nanExpected && !math.IsNaN(float64(dstTyped)) {
|
||||
t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
|
||||
} else if !nanExpected && dst != tt.expected {
|
||||
t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
|
||||
}
|
||||
case float64:
|
||||
if math.IsNaN(tt.expected.(float64)) && !math.IsNaN(dstTyped) {
|
||||
nanExpected := math.IsNaN(tt.expected.(float64))
|
||||
if nanExpected && !math.IsNaN(dstTyped) {
|
||||
t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
|
||||
} else if !nanExpected && dst != tt.expected {
|
||||
t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user