[#107] proto/test: Add oneof test

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-08-26 14:33:30 +03:00
parent 866db105ed
commit 981dc785f3
4 changed files with 13 additions and 0 deletions

View file

@ -49,6 +49,8 @@ func TestStableMarshalSingle(t *testing.T) {
{name: "fixed32", input: &generated.Primitives{FieldK: nonZero[uint32]()}},
{name: "enum, positive", input: &generated.Primitives{FieldH: generated.Primitives_POSITIVE}},
{name: "enum, negative", input: &generated.Primitives{FieldH: generated.Primitives_NEGATIVE}},
{name: "oneof, first", input: &generated.Primitives{FieldM: &generated.Primitives_FieldMa{FieldMa: []byte{4, 2}}}},
{name: "oneof, second", input: &generated.Primitives{FieldM: &generated.Primitives_FieldMe{FieldMe: nonZero[uint32]()}}},
}
for _, tc := range marshalCases {
t.Run(tc.name, func(t *testing.T) {
@ -97,6 +99,9 @@ func primitivesEqual(t *testing.T, a *generated.Primitives, b *test.Primitives)
require.Equal(t, a.FieldJ, b.FieldJ)
require.Equal(t, a.FieldK, b.FieldK)
require.EqualValues(t, a.FieldH, b.FieldH)
require.Equal(t, a.GetFieldMa(), b.GetFieldMa())
require.Equal(t, a.GetFieldMe(), b.GetFieldMe())
require.Equal(t, a.GetFieldAux().GetInnerField(), b.GetFieldAux().GetInnerField())
}
func repPrimitivesEqual(t *testing.T, a *generated.RepPrimitives, b *test.RepPrimitives) {

Binary file not shown.

Binary file not shown.

View file

@ -22,6 +22,14 @@ message Primitives {
NEGATIVE = -1;
}
SomeEnum field_h = 300;
message Aux { uint32 inner_field = 1; }
oneof field_m {
bytes field_ma = 401;
uint32 field_me = 402;
Aux field_aux = 403;
}
}
message RepPrimitives {