Skip to content

Commit

Permalink
Update test to show that generated code for field of type enum? does not
Browse files Browse the repository at this point in the history
compile
  • Loading branch information
bernardnormier committed Sep 27, 2023
1 parent bf1bcbb commit a63ced0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions tests/ZeroC.Slice.Tests/StructTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void Decode_struct()
[Test]
public void Decode_struct_with_optional_fields(
[Values(10, null)] int? k,
[Values(20, null)] int? l)
[Values(20, null)] int? l,
[Values(MyEnum.Enum1, null)] MyEnum? e)
{
// Arrange
var buffer = new MemoryBufferWriter(new byte[256]);
Expand All @@ -64,6 +65,13 @@ public void Decode_struct_with_optional_fields(
{
encoder.EncodeInt32(l.Value);
}

bitSequenceWriter.Write(e is not null);
if (e is not null)
{
encoder.EncodeMyEnum(e.Value);
}

encoder.EncodeVarInt32(Slice2Definitions.TagEndMarker);

var decoder = new SliceDecoder(buffer.WrittenMemory, SliceEncoding.Slice2);
Expand All @@ -76,6 +84,7 @@ public void Decode_struct_with_optional_fields(
Assert.That(decoded.J, Is.EqualTo(20));
Assert.That(decoded.K, Is.EqualTo(k));
Assert.That(decoded.L, Is.EqualTo(l));
Assert.That(decoded.E, Is.EqualTo(e));
Assert.That(decoder.Consumed, Is.EqualTo(buffer.WrittenMemory.Length));
}

Expand Down Expand Up @@ -114,11 +123,12 @@ public void Encode_struct()
[Test]
public void Encode_struct_with_optional_fields(
[Values(10, null)] int? k,
[Values(20, null)] int? l)
[Values(20, null)] int? l,
[Values(MyEnum.Enum2, null)] MyEnum? e)
{
var buffer = new MemoryBufferWriter(new byte[256]);
var encoder = new SliceEncoder(buffer, SliceEncoding.Slice2);
var expected = new MyStructWithOptionalFields(10, 20, k, l);
var expected = new MyStructWithOptionalFields(10, 20, k, l, e);

expected.Encode(ref encoder);

Expand Down Expand Up @@ -147,6 +157,16 @@ public void Encode_struct_with_optional_fields(
{
Assert.That(bitSequenceReader.Read(), Is.False);
}
if (e is not null)
{
Assert.That(bitSequenceReader.Read(), Is.True);
Assert.That(decoder.DecodeMyEnum(), Is.EqualTo(MyEnum.Enum2));
}
else
{
Assert.That(bitSequenceReader.Read(), Is.False);
}

Assert.That(decoder.DecodeVarInt32(), Is.EqualTo(Slice2Definitions.TagEndMarker));
Assert.That(decoder.Consumed, Is.EqualTo(buffer.WrittenMemory.Length));
}
Expand Down
1 change: 1 addition & 0 deletions tests/ZeroC.Slice.Tests/StructTests.slice
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct MyStructWithOptionalFields {
j: int32
k: int32?
l: int32?
e: MyEnum?
}

compact struct MyCompactStruct {
Expand Down

0 comments on commit a63ced0

Please sign in to comment.