From f7fa2e74b05de482610ee33743247205f79d7934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Thu, 23 May 2024 19:36:29 +0200 Subject: [PATCH] STJ: bit more tests for enum converter --- .../Serialization/ViewModelSerializationMap.cs | 2 +- src/Tests/ViewModel/SerializerTests.cs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Framework/Framework/ViewModel/Serialization/ViewModelSerializationMap.cs b/src/Framework/Framework/ViewModel/Serialization/ViewModelSerializationMap.cs index b35bf442d4..6172a3ce49 100644 --- a/src/Framework/Framework/ViewModel/Serialization/ViewModelSerializationMap.cs +++ b/src/Framework/Framework/ViewModel/Serialization/ViewModelSerializationMap.cs @@ -843,7 +843,7 @@ private static void SerializeViewModelDynamic(Utf8JsonWriter writer, JsonSe } return (TValue?)JsonSerializer.Deserialize(ref reader, type!, options); - null!} + } public static readonly MethodInfo DeserializeViewModelDynamicMethod = typeof(JsonSerializationCodegenFragments).GetMethod(nameof(DeserializeViewModelDynamic), BindingFlags.NonPublic | BindingFlags.Static).NotNull(); private static TVM? DeserializeViewModelDynamic(ref Utf8JsonReader reader, JsonSerializerOptions options, TVM? existingValue, bool populate, ViewModelJsonConverter factory, IDotvvmJsonConverter defaultConverter, DotvvmSerializationState state) diff --git a/src/Tests/ViewModel/SerializerTests.cs b/src/Tests/ViewModel/SerializerTests.cs index f0056a812b..54bf53fe11 100644 --- a/src/Tests/ViewModel/SerializerTests.cs +++ b/src/Tests/ViewModel/SerializerTests.cs @@ -533,17 +533,27 @@ public void SupportsEnums() [DataRow(TestViewModelWithEnums.ByteEnum.A, "'A'", true)] [DataRow(TestViewModelWithEnums.ByteEnum.B, "'B'", true)] [DataRow(TestViewModelWithEnums.ByteEnum.C, "'C'", true)] + [DataRow((TestViewModelWithEnums.ByteEnum)45, "45", false)] + [DataRow(TestViewModelWithEnums.Int16Enum.A, "'A'", true)] + [DataRow(TestViewModelWithEnums.Int16Enum.B, "'B'", true)] + [DataRow((TestViewModelWithEnums.Int16Enum)(-6), "-6", false)] [DataRow(TestViewModelWithEnums.EnumMemberEnum.A, "'member-a'", true)] [DataRow(TestViewModelWithEnums.DuplicateNameEnum.A, "'A'", true)] [DataRow(TestViewModelWithEnums.DuplicateNameEnum.B, "'A'", true)] [DataRow(TestViewModelWithEnums.DuplicateNameEnum.C, "'C'", true)] [DataRow(TestViewModelWithEnums.DuplicateNameEnum.DAndAlsoLonger, "'D'", true)] + [DataRow((TestViewModelWithEnums.DuplicateNameEnum)3, "3", false)] [DataRow(TestViewModelWithEnums.Int32FlagsEnum.ABC, "'a+b+c'", true)] [DataRow(TestViewModelWithEnums.Int32FlagsEnum.A | TestViewModelWithEnums.Int32FlagsEnum.BCD, "'b+c+d,a'", true)] + [DataRow(TestViewModelWithEnums.Int32FlagsEnum.Everything, "'everything'", true)] [DataRow((TestViewModelWithEnums.Int32FlagsEnum)2356543, "2356543", false)] [DataRow((TestViewModelWithEnums.Int32FlagsEnum)0, "0", true)] [DataRow((TestViewModelWithEnums.UInt64FlagsEnum)0, "0", true)] [DataRow(TestViewModelWithEnums.UInt64FlagsEnum.F1 | TestViewModelWithEnums.UInt64FlagsEnum.F2 | TestViewModelWithEnums.UInt64FlagsEnum.F64, "'F64,F2,F1'", true)] + [DataRow(TestViewModelWithEnums.UInt64FlagsEnum.F64, "'F64'", true)] + [DataRow((TestViewModelWithEnums.UInt64FlagsEnum)12 | TestViewModelWithEnums.UInt64FlagsEnum.F64, "9223372036854775820", false)] + [DataRow((TestViewModelWithEnums.UInt64FlagsEnum)ulong.MaxValue, "18446744073709551615", false)] + [DataRow((TestViewModelWithEnums.UInt64FlagsEnum)0, "0", true)] public void TestEnumSerialization(object enumValue, string serializedValue, bool canDeserialize) { var json = JsonSerializer.Serialize(enumValue, DefaultSerializerSettingsProvider.Instance.SettingsHtmlUnsafe); @@ -958,11 +968,11 @@ public enum Int32FlagsEnum : int } [Flags] - public enum UInt64FlagsEnum: long + public enum UInt64FlagsEnum: ulong { F1 = 1, F2 = 2, - F64 = 1L << 63, + F64 = 1UL << 63, } }