Skip to content

Commit

Permalink
STJ: bit more tests for enum converter
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed May 23, 2024
1 parent abf5ce9 commit f7fa2e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ private static void SerializeViewModelDynamic<TVM>(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<TVM>(ref Utf8JsonReader reader, JsonSerializerOptions options, TVM? existingValue, bool populate, ViewModelJsonConverter factory, IDotvvmJsonConverter<TVM> defaultConverter, DotvvmSerializationState state)
Expand Down
14 changes: 12 additions & 2 deletions src/Tests/ViewModel/SerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
}
}

Expand Down

0 comments on commit f7fa2e7

Please sign in to comment.