| 3262 | } |
| 3263 | |
| 3264 | func TestNullDecimal_Value(t *testing.T) { |
| 3265 | // Make sure this does implement the database/sql's driver.Valuer interface |
| 3266 | var nullDecimal NullDecimal |
| 3267 | if _, ok := interface{}(nullDecimal).(driver.Valuer); !ok { |
| 3268 | t.Error("NullDecimal does not implement driver.Valuer") |
| 3269 | } |
| 3270 | |
| 3271 | // check that null is handled appropriately |
| 3272 | value, err := nullDecimal.Value() |
| 3273 | if err != nil { |
| 3274 | t.Errorf("NullDecimal{}.Valid() failed with message: %s", err) |
| 3275 | } else if value != nil { |
| 3276 | t.Errorf("%v is not nil", value) |
| 3277 | } |
| 3278 | |
| 3279 | // check that normal case is handled appropriately |
| 3280 | a := NullDecimal{Decimal: New(1234, -2), Valid: true} |
| 3281 | expected := "12.34" |
| 3282 | value, err = a.Value() |
| 3283 | if err != nil { |
| 3284 | t.Errorf("NullDecimal(12.34).Value() failed with message: %s", err) |
| 3285 | } else if value.(string) != expected { |
| 3286 | t.Errorf("%v does not equal %v", a, expected) |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | func TestBinary(t *testing.T) { |
| 3291 | for _, y := range testTable { |