@@ -3562,6 +3562,45 @@ func TestScanNullNumeric(t *testing.T) {
35623562 }
35633563}
35643564
3565+ func TestScanPGNumeric (t * testing.T ) {
3566+ for _ , test := range []struct {
3567+ name string
3568+ input any
3569+ want PGNumeric
3570+ }{
3571+ {name : "string" , input : "3.14" , want : PGNumeric {Numeric : "3.14" , Valid : true }},
3572+ {name : "stringptr" , input : stringPointer ("3.14" ), want : PGNumeric {Numeric : "3.14" , Valid : true }},
3573+ {name : "nil" , input : nil , want : PGNumeric {}},
3574+ {name : "nilstringptr" , input : (* string )(nil ), want : PGNumeric {}},
3575+ {name : "float32" , input : float32 (3.14 ), want : PGNumeric {Numeric : "3.140000105" , Valid : true }},
3576+ {name : "float32ptr" , input : float32Pointer (float32 (3.14 )), want : PGNumeric {Numeric : "3.140000105" , Valid : true }},
3577+ {name : "float64" , input : 3.14 , want : PGNumeric {Numeric : "3.140000000" , Valid : true }},
3578+ {name : "float64ptr" , input : float64Pointer (3.14 ), want : PGNumeric {Numeric : "3.140000000" , Valid : true }},
3579+ {name : "NullNumeric" , input : NullNumeric {Numeric : * bigRatFromString ("3.14" ), Valid : true }, want : PGNumeric {Numeric : "3.140000000" , Valid : true }},
3580+ {name : "NullNumericPtr" , input : & NullNumeric {Numeric : * bigRatFromString ("3.14" ), Valid : true }, want : PGNumeric {Numeric : "3.140000000" , Valid : true }},
3581+ {name : "NullNumericWithNullValue" , input : NullNumeric {}, want : PGNumeric {}},
3582+ {name : "NullNumericPtrWithNullValue" , input : & NullNumeric {}, want : PGNumeric {}},
3583+ {name : "bigrat" , input : * bigRatFromString ("6.626" ), want : PGNumeric {Numeric : "6.626000000" , Valid : true }},
3584+ {name : "bigratptr" , input : bigRatFromString ("9.99" ), want : PGNumeric {Numeric : "9.990000000" , Valid : true }},
3585+ {name : "nilbigratptr" , input : (* big .Rat )(nil ), want : PGNumeric {}},
3586+ } {
3587+ t .Run (test .name , func (t * testing.T ) {
3588+ n := PGNumeric {Numeric : "should be overwritten" , Valid : true }
3589+ if err := n .Scan (test .input ); err != nil {
3590+ t .Fatal (err )
3591+ }
3592+ if g , w := n , test .want ; ! reflect .DeepEqual (g , w ) {
3593+ t .Fatalf ("value mismatch\n Got: %v\n Want: %v" , g , w )
3594+ }
3595+ })
3596+ }
3597+ }
3598+
3599+ func bigRatFromString (s string ) * big.Rat {
3600+ r , _ := (& big.Rat {}).SetString (s )
3601+ return r
3602+ }
3603+
35653604func TestInterval (t * testing.T ) {
35663605 tests := []struct {
35673606 name string
0 commit comments