You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because the comparison logic for oneof fields relies on the getters for the individual fields, it cannot differentiate between a field not being set, and a field being set to the zero value. While the nil checks allow distinguishing protos where one has a oneof field set to a zero value, while the other doesn't have any field in the oneof set, the code fails to distinguish protos where different fields in a oneof are set to the respective zero value.
Test case:
func TestEqualVT_Oneof_AbsenceVsZeroValue(t *testing.T) {
a := &TestAllTypesProto3{
OneofField: &TestAllTypesProto3_OneofUint32{
OneofUint32: 0,
},
}
b := &TestAllTypesProto3{
OneofField: &TestAllTypesProto3_OneofString{
OneofString: "",
},
}
aJson, err := protojson.Marshal(a)
require.NoError(t, err)
bJson, err := protojson.Marshal(b)
require.NoError(t, err)
if a.EqualVT(b) {
assert.JSONEq(t, string(aJson), string(bJson))
err := fmt.Errorf("these %T should not be equal:\nmsg = %+v\noriginal = %+v", a, a, b)
require.NoError(t, err)
}
}
This is similar to #48 , but applies to oneofs and exercises different paths in the code generation.
The text was updated successfully, but these errors were encountered:
Because the comparison logic for oneof fields relies on the getters for the individual fields, it cannot differentiate between a field not being set, and a field being set to the zero value. While the
nil
checks allow distinguishing protos where one has a oneof field set to a zero value, while the other doesn't have any field in the oneof set, the code fails to distinguish protos where different fields in a oneof are set to the respective zero value.Test case:
This is similar to #48 , but applies to oneofs and exercises different paths in the code generation.
The text was updated successfully, but these errors were encountered: