mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Update enum handling, part 3
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="SabreTools.Test" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ namespace SabreTools.Core.Tools
|
|||||||
/// <param name="value">String value to parse/param>
|
/// <param name="value">String value to parse/param>
|
||||||
/// <typeparam name="T">Enum type that is expected</typeparam>
|
/// <typeparam name="T">Enum type that is expected</typeparam>
|
||||||
/// <returns>Enum value representing the input, default on error</returns>
|
/// <returns>Enum value representing the input, default on error</returns>
|
||||||
private static T AsEnumValue<T>(string value)
|
internal static T AsEnumValue<T>(string value)
|
||||||
{
|
{
|
||||||
// Get the mapping dictionary
|
// Get the mapping dictionary
|
||||||
var mappings = GenerateToEnum<T>();
|
var mappings = GenerateToEnum<T>();
|
||||||
@@ -340,7 +340,7 @@ namespace SabreTools.Core.Tools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Enum type that is expected</typeparam>
|
/// <typeparam name="T">Enum type that is expected</typeparam>
|
||||||
/// <returns>Dictionary of string to enum values</returns>
|
/// <returns>Dictionary of string to enum values</returns>
|
||||||
private static Dictionary<string, T> GenerateToEnum<T>()
|
internal static Dictionary<string, T> GenerateToEnum<T>()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -565,7 +565,7 @@ namespace SabreTools.Core.Tools
|
|||||||
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
|
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
|
||||||
/// <typeparam name="T">Enum type that is expected</typeparam>
|
/// <typeparam name="T">Enum type that is expected</typeparam>
|
||||||
/// <returns>String value representing the input, default on error</returns>
|
/// <returns>String value representing the input, default on error</returns>
|
||||||
private static string? AsStringValue<T>(T value, bool useSecond = false)
|
internal static string? AsStringValue<T>(T value, bool useSecond = false)
|
||||||
{
|
{
|
||||||
// Get the mapping dictionary
|
// Get the mapping dictionary
|
||||||
var mappings = GenerateToString<T>(useSecond);
|
var mappings = GenerateToString<T>(useSecond);
|
||||||
@@ -584,7 +584,7 @@ namespace SabreTools.Core.Tools
|
|||||||
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
|
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
|
||||||
/// <typeparam name="T">Enum type that is expected</typeparam>
|
/// <typeparam name="T">Enum type that is expected</typeparam>
|
||||||
/// <returns>Dictionary of enum to string values</returns>
|
/// <returns>Dictionary of enum to string values</returns>
|
||||||
private static Dictionary<T, string> GenerateToString<T>(bool useSecond)
|
internal static Dictionary<T, string> GenerateToString<T>(bool useSecond)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -857,5 +857,41 @@ namespace SabreTools.Test.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Generators
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(ChipType.NULL, 2)]
|
||||||
|
[InlineData(ControlType.NULL, 15)]
|
||||||
|
[InlineData(DatHeaderField.NULL, 94)]
|
||||||
|
[InlineData(DatItemField.NULL, 197)]
|
||||||
|
[InlineData(DeviceType.NULL, 21)]
|
||||||
|
[InlineData(DisplayType.NULL, 5)]
|
||||||
|
[InlineData(Endianness.NULL, 2)]
|
||||||
|
[InlineData(FeatureStatus.NULL, 2)]
|
||||||
|
[InlineData(FeatureType.NULL, 14)]
|
||||||
|
[InlineData(ItemStatus.NULL, 7)]
|
||||||
|
[InlineData(ItemType.NULL, 51)]
|
||||||
|
[InlineData(LoadFlag.NULL, 14)]
|
||||||
|
[InlineData(LogLevel.VERBOSE, 4)]
|
||||||
|
[InlineData(MachineField.NULL, 68)]
|
||||||
|
[InlineData(MachineType.None, 6)]
|
||||||
|
[InlineData(MergingFlag.None, 12)]
|
||||||
|
[InlineData(NodumpFlag.None, 4)]
|
||||||
|
[InlineData(OpenMSXSubType.NULL, 3)]
|
||||||
|
[InlineData(PackingFlag.None, 7)]
|
||||||
|
[InlineData(Relation.NULL, 6)]
|
||||||
|
[InlineData(Runnable.NULL, 3)]
|
||||||
|
[InlineData(SoftwareListStatus.None, 3)]
|
||||||
|
[InlineData(Supported.NULL, 5)]
|
||||||
|
[InlineData(SupportStatus.NULL, 3)]
|
||||||
|
public void GenerateToEnumTest<T>(T value, int expected)
|
||||||
|
{
|
||||||
|
var actual = Converters.GenerateToEnum<T>();
|
||||||
|
Assert.Equal(default, value);
|
||||||
|
Assert.Equal(expected, actual.Keys.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user