Skip to content

Commit

Permalink
Drop -0 from omitzero test (#308)
Browse files Browse the repository at this point in the history
https://go.dev/issue/61827 redefined reflect.Value.IsZero to
treat -0 as zero. Since we define omitzero as operating on the
Go definition of zero, we adopt this change in behavior.
  • Loading branch information
dsnet authored Sep 2, 2023
1 parent 76ac386 commit c2a874a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions arshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ func TestMarshal(t *testing.T) {
Bytes: []byte{}, // not omitted since allocated slice is non-zero
Int: 1, // not omitted since 1 is non-zero
Uint: 1, // not omitted since 1 is non-zero
Float: math.Copysign(0, -1), // not omitted since -0 is technically non-zero
Float: math.SmallestNonzeroFloat64, // not omitted since still slightly above zero
Map: map[string]string{}, // not omitted since allocated map is non-zero
StructScalars: structScalars{unexported: true}, // not omitted since unexported is non-zero
StructSlices: structSlices{Ignored: true}, // not omitted since Ignored is non-zero
Expand All @@ -1437,7 +1437,7 @@ func TestMarshal(t *testing.T) {
"Bytes": "",
"Int": 1,
"Uint": 1,
"Float": -0,
"Float": 5e-324,
"Map": {},
"StructScalars": {
"Bool": false,
Expand Down Expand Up @@ -1641,7 +1641,7 @@ func TestMarshal(t *testing.T) {
PointerSlice: addr([]string{""}),
PointerSliceEmpty: addr(sliceMarshalEmpty{"value"}),
PointerSliceNonEmpty: addr(sliceMarshalNonEmpty{"value"}),
Pointer: &structOmitZeroEmptyAll{Float: math.Copysign(0, -1)},
Pointer: &structOmitZeroEmptyAll{Float: math.SmallestNonzeroFloat64},
Interface: []string{""},
},
want: `{
Expand Down Expand Up @@ -1686,7 +1686,7 @@ func TestMarshal(t *testing.T) {
"value"
],
"Pointer": {
"Float": -0
"Float": 5e-324
},
"Interface": [
""
Expand Down

0 comments on commit c2a874a

Please sign in to comment.