mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Merge branch 'tomlinford-master'
This commit is contained in:
commit
96e19b482b
2 changed files with 25 additions and 1 deletions
|
@ -508,7 +508,10 @@ func (d *Decimal) Scan(value interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver.Valuer interface for database serialization.
|
// 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
|
return d.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -929,6 +929,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>).Value() 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 := "12.34"
|
||||||
|
value, err = a.Value()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Decimal(12.34).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
|
// old tests after this line
|
||||||
|
|
||||||
func TestDecimal_Scale(t *testing.T) {
|
func TestDecimal_Scale(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue