From 65a0e71430da8bb8c1be4376686006fcbd53cfe0 Mon Sep 17 00:00:00 2001 From: Ethan Shea Date: Sat, 3 Apr 2021 16:37:14 -0700 Subject: [PATCH] Fix nullable enum roundtrip --- .../Serialization/SerializationTests.cs | 21 +++- .../ScalarNodeDeserializer.cs | 117 +++++++++--------- 2 files changed, 75 insertions(+), 63 deletions(-) diff --git a/YamlDotNet.Test/Serialization/SerializationTests.cs b/YamlDotNet.Test/Serialization/SerializationTests.cs index b18acd650..7b0682925 100644 --- a/YamlDotNet.Test/Serialization/SerializationTests.cs +++ b/YamlDotNet.Test/Serialization/SerializationTests.cs @@ -162,14 +162,25 @@ public void DeserializeScalarLongBase60Number() result.Should().Be(77744246530L); } - [Fact] - public void RoundtripEnums() + [Theory] + [InlineData(EnumExample.One)] + [InlineData(EnumExample.One | EnumExample.Two)] + public void RoundtripEnums(EnumExample value) { - var flags = EnumExample.One | EnumExample.Two; + var result = DoRoundtripFromObjectTo(value); + + result.Should().Be(value); + } - var result = DoRoundtripFromObjectTo(flags); + [Theory] + [InlineData(EnumExample.One)] + [InlineData(EnumExample.One | EnumExample.Two)] + [InlineData(null)] + public void RoundtripNullableEnums(EnumExample? value) + { + var result = DoRoundtripFromObjectTo(value); - result.Should().Be(flags); + result.Should().Be(value); } [Fact] diff --git a/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs b/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs index 9bcb584df..2915378b5 100644 --- a/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs +++ b/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs @@ -42,68 +42,69 @@ bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func