mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
Make Value take a pointer receiver
This commit is contained in:
parent
f95dd20cca
commit
54efccb61f
2 changed files with 25 additions and 1 deletions
|
@ -495,7 +495,10 @@ func (d *Decimal) Scan(value interface{}) error {
|
|||
}
|
||||
|
||||
// Value implements the driver.Valuer interface for database serialization.
|
||||
func (d Decimal) Value() (driver.Value, error) {
|
||||
func (d *Decimal) Value() (driver.Value, error) {
|
||||
if d == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return d.String(), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -874,6 +874,27 @@ func TestDecimal_Scan(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDecimal_Value(t *testing.T) {
|
||||
// check that nil is handled appropriately
|
||||
var decimalPtr *Decimal
|
||||
value, err := decimalPtr.Value()
|
||||
if err != nil {
|
||||
t.Errorf("(*Decimal)(<nil>) failed with message: %s", err)
|
||||
} else if value != nil {
|
||||
t.Errorf("%v is not nil", value)
|
||||
}
|
||||
|
||||
// check that normal case is handled appropriately
|
||||
a := New(1234, 2)
|
||||
expected := "123400"
|
||||
value, err = a.Value()
|
||||
if err != nil {
|
||||
t.Errorf("Decimal(123400).Value() failed with message: %s", err)
|
||||
} else if value.(string) != expected {
|
||||
t.Errorf("%s does not equal to %s", a, expected)
|
||||
}
|
||||
}
|
||||
|
||||
// old tests after this line
|
||||
|
||||
func TestDecimal_Scale(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue