-
Notifications
You must be signed in to change notification settings - Fork 26
fix(scalar): Handle nil pointer to []byte in uuid and binary #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,18 @@ import ( | |
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestFloat32Set(t *testing.T) { | ||
| var nilPointerInt8 *int8 | ||
| var nilPointerInt16 *int16 | ||
| var nilPointerInt32 *int32 | ||
| var nilPointerInt64 *int64 | ||
| var nilPointerUint8 *uint8 | ||
| var nilPointerUint16 *uint16 | ||
| var nilPointerUint32 *uint32 | ||
| var nilPointerUint64 *uint64 | ||
| var nilPointerFloat32 *float32 | ||
| var nilPointerFloat64 *float64 | ||
|
|
||
| func TestFloatAllWidthsSet(t *testing.T) { | ||
| successfulTests := []struct { | ||
| source any | ||
| expect Float | ||
|
|
@@ -30,6 +41,16 @@ func TestFloat32Set(t *testing.T) { | |
| {source: "1", expect: Float{Value: 1, Valid: true}}, | ||
| {source: _int8(1), expect: Float{Value: 1, Valid: true}}, | ||
| {source: &Float{Value: 1, Valid: true, BitWidth: 32}, expect: Float{Value: 1, Valid: true}}, | ||
| {source: nilPointerInt8, expect: Float{Valid: false}}, | ||
| {source: nilPointerInt16, expect: Float{Valid: false}}, | ||
| {source: nilPointerInt32, expect: Float{Valid: false}}, | ||
| {source: nilPointerInt64, expect: Float{Valid: false}}, | ||
| {source: nilPointerUint8, expect: Float{Valid: false}}, | ||
| {source: nilPointerUint16, expect: Float{Valid: false}}, | ||
| {source: nilPointerUint32, expect: Float{Valid: false}}, | ||
| {source: nilPointerUint64, expect: Float{Valid: false}}, | ||
| {source: nilPointerFloat32, expect: Float{Valid: false}}, | ||
| {source: nilPointerFloat64, expect: Float{Valid: false}}, | ||
| } | ||
|
|
||
| for _, bitWidth := range []uint8{8, 16, 32, 64} { | ||
|
|
@@ -74,6 +95,16 @@ func TestFloat64Set(t *testing.T) { | |
| {source: "1", result: Float{Value: 1, Valid: true}}, | ||
| {source: _int8(1), result: Float{Value: 1, Valid: true}}, | ||
| {source: &Float{Value: 1, Valid: true}, result: Float{Value: 1, Valid: true}}, | ||
| {source: nilPointerInt8, result: Float{Valid: false}}, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can remove |
||
| {source: nilPointerInt16, result: Float{Valid: false}}, | ||
| {source: nilPointerInt32, result: Float{Valid: false}}, | ||
| {source: nilPointerInt64, result: Float{Valid: false}}, | ||
| {source: nilPointerUint8, result: Float{Valid: false}}, | ||
| {source: nilPointerUint16, result: Float{Valid: false}}, | ||
| {source: nilPointerUint32, result: Float{Valid: false}}, | ||
| {source: nilPointerUint64, result: Float{Valid: false}}, | ||
| {source: nilPointerFloat32, result: Float{Valid: false}}, | ||
| {source: nilPointerFloat64, result: Float{Valid: false}}, | ||
| } | ||
|
|
||
| for i, tt := range successfulTests { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,15 @@ func (s *UUID) Set(src any) error { | |
| return s.Set(value2) | ||
| case [16]byte: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works since |
||
| s.Value = uuid.UUID(value) | ||
| case *[]byte: | ||
| if value == nil { | ||
| s.Valid = false | ||
| return nil | ||
| } | ||
| return s.Set(*value) | ||
| case []byte: | ||
| if value == nil { | ||
| s.Valid = false | ||
| return nil | ||
| } | ||
| if len(value) != 16 { | ||
|
|
@@ -79,6 +86,7 @@ func (s *UUID) Set(src any) error { | |
| s.Value = uuidVal | ||
| case *string: | ||
| if value == nil { | ||
| s.Valid = false | ||
| return nil | ||
| } | ||
| return s.Set(*value) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed
TestFloat32SettoTestFloatAllWidthsSet