-
Notifications
You must be signed in to change notification settings - Fork 214
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
[FIX] Issue #202 and #190 #206
Open
quetzyg
wants to merge
4
commits into
google:master
Choose a base branch
from
quetzyg:fix/numeric-precision
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7674e75
fix(request): ensure the precision isn't lost when decoding numeric v…
quetzyg 1774d8b
tests(request): update an expected ID value to a high value
quetzyg 7ea5e24
tests(request): full coverage of the handleNumeric() function
quetzyg cb512b4
fix(request): ensure numeric values are all handled as json.Number in…
quetzyg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"errors" | ||
"fmt" | ||
"io" | ||
"math" | ||
"reflect" | ||
"sort" | ||
"strings" | ||
|
@@ -303,7 +304,7 @@ func TestUnmarshalSetsID(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
if out.ID != 2 { | ||
if out.ID != 9223372036854775807 { | ||
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. If we used this value previously, the test would fail; |
||
t.Fatalf("Did not set ID on dst interface") | ||
} | ||
} | ||
|
@@ -1070,7 +1071,7 @@ func samplePayload() io.Reader { | |
func samplePayloadWithID() io.Reader { | ||
payload := &OnePayload{ | ||
Data: &Node{ | ||
ID: "2", | ||
ID: "9223372036854775807", | ||
Type: "blogs", | ||
Attributes: map[string]interface{}{ | ||
"title": "New blog", | ||
|
@@ -1416,3 +1417,90 @@ func TestUnmarshalNestedStructSlice(t *testing.T) { | |
out.Teams[0].Members[0].Firstname) | ||
} | ||
} | ||
|
||
func TestUnmarshalNumerics(t *testing.T) { | ||
data, err := json.Marshal(map[string]interface{}{ | ||
"data": map[string]interface{}{ | ||
"id": "9223372036854775807", | ||
"type": "numerics", | ||
"attributes": map[string]interface{}{ | ||
"int": math.MinInt32, | ||
"int8": math.MinInt8, | ||
"int16": math.MinInt16, | ||
"int32": math.MinInt32, | ||
"int64": math.MinInt64, | ||
|
||
"uint": math.MaxInt32, | ||
"uint8": math.MaxInt8, | ||
"uint16": math.MaxInt16, | ||
"uint32": math.MaxInt32, | ||
"uint64": math.MaxInt64, | ||
|
||
"float32": math.MaxFloat32, | ||
"float64": math.MaxFloat64, | ||
}, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
in := bytes.NewReader(data) | ||
n := new(Numerics) | ||
|
||
if err = UnmarshalPayload(in, n); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if n.ID != "9223372036854775807" { | ||
t.Fatalf("Unexpected value for ID") | ||
} | ||
|
||
if n.Int != math.MinInt32 { | ||
t.Fatalf("Unexpected value for Int") | ||
} | ||
|
||
if n.Int8 != math.MinInt8 { | ||
t.Fatalf("Unexpected value for Int8") | ||
} | ||
|
||
if n.Int16 != math.MinInt16 { | ||
t.Fatalf("Unexpected value for Int16") | ||
} | ||
|
||
if n.Int32 != math.MinInt32 { | ||
t.Fatalf("Unexpected value for Int32") | ||
} | ||
|
||
if n.Int64 != math.MinInt64 { | ||
t.Fatalf("Unexpected value for Int64") | ||
} | ||
|
||
if n.Uint != math.MaxInt32 { | ||
t.Fatalf("Unexpected value for Uint") | ||
} | ||
|
||
if n.Uint8 != math.MaxInt8 { | ||
t.Fatalf("Unexpected value for Uint8") | ||
} | ||
|
||
if n.Uint16 != math.MaxInt16 { | ||
t.Fatalf("Unexpected value for Uint16") | ||
} | ||
|
||
if n.Uint32 != math.MaxInt32 { | ||
t.Fatalf("Unexpected value for Uint32") | ||
} | ||
|
||
if n.Uint64 != math.MaxInt64 { | ||
t.Fatalf("Unexpected value for Uint64") | ||
} | ||
|
||
if n.Float32 != math.MaxFloat32 { | ||
t.Fatalf("Unexpected value for Float32") | ||
} | ||
|
||
if n.Float64 != math.MaxFloat64 { | ||
t.Fatalf("Unexpected value for Float64") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The original logic was kept, since we're still checking the type of the
attribute
, while the previous/following checks are done to thefieldValue
kind.I wonder if we should check the
fieldValue
kind here as well for consistency.