mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 03:14:16 +00:00
internal/impl: fix Has for proto3 scalars
The definition of Has for proto3 scalars is whether the value is non-zero. Change-Id: I6aee92dd518d63a66515ad35da84b2be7aa22527 Reviewed-on: https://go-review.googlesource.com/c/150320 Reviewed-by: Herbie Ong <herbie@google.com> Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
parent
c6320b9f23
commit
44e389ca6c
@ -192,11 +192,11 @@ func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField) fieldIn
|
||||
case reflect.Bool:
|
||||
return rv.Bool()
|
||||
case reflect.Int32, reflect.Int64:
|
||||
return rv.Int() > 0
|
||||
return rv.Int() != 0
|
||||
case reflect.Uint32, reflect.Uint64:
|
||||
return rv.Uint() > 0
|
||||
return rv.Uint() != 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return rv.Float() > 0
|
||||
return rv.Float() != 0
|
||||
case reflect.String, reflect.Slice:
|
||||
return rv.Len() > 0
|
||||
default:
|
||||
|
@ -351,6 +351,12 @@ func TestScalarProto3(t *testing.T) {
|
||||
true, 2, 3, 4, 5, 6, 7, "8", []byte("9"), []byte("10"), "11",
|
||||
true, 13, 14, 15, 16, 17, 18, "19", []byte("20"), []byte("21"), "22",
|
||||
}},
|
||||
setFields{
|
||||
2: V(int32(-2)), 3: V(int64(-3)), 6: V(float32(math.Inf(-1))), 7: V(float64(math.NaN())),
|
||||
},
|
||||
hasFields{
|
||||
2: true, 3: true, 6: true, 7: true,
|
||||
},
|
||||
clearFields{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22},
|
||||
equalMessage{&ScalarProto3{}},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user