Skip to content

Commit c2a874a

Browse files
authored
Drop -0 from omitzero test (#308)
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.
1 parent 76ac386 commit c2a874a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arshal_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ func TestMarshal(t *testing.T) {
14211421
Bytes: []byte{}, // not omitted since allocated slice is non-zero
14221422
Int: 1, // not omitted since 1 is non-zero
14231423
Uint: 1, // not omitted since 1 is non-zero
1424-
Float: math.Copysign(0, -1), // not omitted since -0 is technically non-zero
1424+
Float: math.SmallestNonzeroFloat64, // not omitted since still slightly above zero
14251425
Map: map[string]string{}, // not omitted since allocated map is non-zero
14261426
StructScalars: structScalars{unexported: true}, // not omitted since unexported is non-zero
14271427
StructSlices: structSlices{Ignored: true}, // not omitted since Ignored is non-zero
@@ -1437,7 +1437,7 @@ func TestMarshal(t *testing.T) {
14371437
"Bytes": "",
14381438
"Int": 1,
14391439
"Uint": 1,
1440-
"Float": -0,
1440+
"Float": 5e-324,
14411441
"Map": {},
14421442
"StructScalars": {
14431443
"Bool": false,
@@ -1641,7 +1641,7 @@ func TestMarshal(t *testing.T) {
16411641
PointerSlice: addr([]string{""}),
16421642
PointerSliceEmpty: addr(sliceMarshalEmpty{"value"}),
16431643
PointerSliceNonEmpty: addr(sliceMarshalNonEmpty{"value"}),
1644-
Pointer: &structOmitZeroEmptyAll{Float: math.Copysign(0, -1)},
1644+
Pointer: &structOmitZeroEmptyAll{Float: math.SmallestNonzeroFloat64},
16451645
Interface: []string{""},
16461646
},
16471647
want: `{
@@ -1686,7 +1686,7 @@ func TestMarshal(t *testing.T) {
16861686
"value"
16871687
],
16881688
"Pointer": {
1689-
"Float": -0
1689+
"Float": 5e-324
16901690
},
16911691
"Interface": [
16921692
""

0 commit comments

Comments
 (0)