Merge branch 'tomlinford-master'

This commit is contained in:
Vadim Graboys 2016-09-18 13:32:48 -07:00
commit 96e19b482b
2 changed files with 25 additions and 1 deletions

View file

@ -508,7 +508,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
}

View file

@ -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
func TestDecimal_Scale(t *testing.T) {