mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-07-08 18:16:25 +00:00
YesNo enum is valid for both sites
This commit is contained in:
@@ -2,7 +2,6 @@ using System;
|
||||
using SabreTools.CommandLine.Inputs;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
using SabreTools.RedumpLib.RedumpOrg;
|
||||
using SabreTools.RedumpLib.RedumpOrg.Data;
|
||||
|
||||
namespace RedumpTool.Features
|
||||
{
|
||||
|
||||
@@ -2541,5 +2541,68 @@ namespace SabreTools.RedumpLib.Test.Data
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Yes/No
|
||||
|
||||
/// <summary>
|
||||
/// Check that every YesNo has a long name provided
|
||||
/// </summary>
|
||||
/// <param name="yesNo">YesNo value to check</param>
|
||||
/// <param name="expectNull">True to expect a null value, false otherwise</param>
|
||||
[Theory]
|
||||
[MemberData(nameof(GenerateYesNoTestData))]
|
||||
public void YesNo_LongName(YesNo? yesNo, bool expectNull)
|
||||
{
|
||||
string actual = yesNo.LongName();
|
||||
|
||||
if (expectNull)
|
||||
Assert.Null(actual);
|
||||
else
|
||||
Assert.NotNull(actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, YesNo.Yes)]
|
||||
[InlineData(false, YesNo.No)]
|
||||
[InlineData(null, YesNo.NULL)]
|
||||
public void YesNo_ToYesNo_Boolean(bool? value, YesNo? expected)
|
||||
{
|
||||
YesNo? actual = value.ToYesNo();
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("True", YesNo.Yes)]
|
||||
[InlineData("true", YesNo.Yes)]
|
||||
[InlineData("Yes", YesNo.Yes)]
|
||||
[InlineData("yes", YesNo.Yes)]
|
||||
[InlineData("False", YesNo.No)]
|
||||
[InlineData("false", YesNo.No)]
|
||||
[InlineData("No", YesNo.No)]
|
||||
[InlineData("no", YesNo.No)]
|
||||
[InlineData("INVALID", YesNo.NULL)]
|
||||
[InlineData(null, YesNo.NULL)]
|
||||
public void YesNo_ToYesNo_String(string? value, YesNo? expected)
|
||||
{
|
||||
YesNo? actual = value.ToYesNo();
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a test set of YesNo values
|
||||
/// </summary>
|
||||
/// <returns>MemberData-compatible list of YesNo values</returns>
|
||||
public static TheoryData<YesNo?, bool> GenerateYesNoTestData()
|
||||
{
|
||||
var testData = new TheoryData<YesNo?, bool>() { { null, false } };
|
||||
foreach (YesNo? yesNo in Enum.GetValues<YesNo>().Cast<YesNo?>())
|
||||
{
|
||||
testData.Add(yesNo, false);
|
||||
}
|
||||
|
||||
return testData;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,68 +386,5 @@ namespace SabreTools.RedumpLib.Test.RedumpOrg
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Yes/No
|
||||
|
||||
/// <summary>
|
||||
/// Check that every YesNo has a long name provided
|
||||
/// </summary>
|
||||
/// <param name="yesNo">YesNo value to check</param>
|
||||
/// <param name="expectNull">True to expect a null value, false otherwise</param>
|
||||
[Theory]
|
||||
[MemberData(nameof(GenerateYesNoTestData))]
|
||||
public void YesNo_LongName(YesNo? yesNo, bool expectNull)
|
||||
{
|
||||
string actual = yesNo.LongName();
|
||||
|
||||
if (expectNull)
|
||||
Assert.Null(actual);
|
||||
else
|
||||
Assert.NotNull(actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, YesNo.Yes)]
|
||||
[InlineData(false, YesNo.No)]
|
||||
[InlineData(null, YesNo.NULL)]
|
||||
public void YesNo_ToYesNo_Boolean(bool? value, YesNo? expected)
|
||||
{
|
||||
YesNo? actual = value.ToYesNo();
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("True", YesNo.Yes)]
|
||||
[InlineData("true", YesNo.Yes)]
|
||||
[InlineData("Yes", YesNo.Yes)]
|
||||
[InlineData("yes", YesNo.Yes)]
|
||||
[InlineData("False", YesNo.No)]
|
||||
[InlineData("false", YesNo.No)]
|
||||
[InlineData("No", YesNo.No)]
|
||||
[InlineData("no", YesNo.No)]
|
||||
[InlineData("INVALID", YesNo.NULL)]
|
||||
[InlineData(null, YesNo.NULL)]
|
||||
public void YesNo_ToYesNo_String(string? value, YesNo? expected)
|
||||
{
|
||||
YesNo? actual = value.ToYesNo();
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a test set of YesNo values
|
||||
/// </summary>
|
||||
/// <returns>MemberData-compatible list of YesNo values</returns>
|
||||
public static TheoryData<YesNo?, bool> GenerateYesNoTestData()
|
||||
{
|
||||
var testData = new TheoryData<YesNo?, bool>() { { null, false } };
|
||||
foreach (YesNo? yesNo in Enum.GetValues<YesNo>().Cast<YesNo?>())
|
||||
{
|
||||
testData.Add(yesNo, false);
|
||||
}
|
||||
|
||||
return testData;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SabreTools.RedumpLib.RedumpOrg.Data;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
|
||||
namespace SabreTools.RedumpLib.RedumpOrg.Converters
|
||||
namespace SabreTools.RedumpLib.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Serialize YesNo enum values
|
||||
@@ -3673,4 +3673,19 @@ namespace SabreTools.RedumpLib.Data
|
||||
[HumanReadable(LongName = "Other")]
|
||||
Other,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Generic yes/no values
|
||||
/// </summary>
|
||||
public enum YesNo
|
||||
{
|
||||
[HumanReadable(LongName = "Yes/No")]
|
||||
NULL = 0,
|
||||
|
||||
[HumanReadable(LongName = "No")]
|
||||
No = 1,
|
||||
|
||||
[HumanReadable(LongName = "Yes")]
|
||||
Yes = 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1973,5 +1973,61 @@ namespace SabreTools.RedumpLib.Data
|
||||
=> AttributeHelper<SystemCategory?>.GetHumanReadableAttribute(category)?.LongName;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Yes/No
|
||||
|
||||
/// <summary>
|
||||
/// Get the string representation of the YesNo value
|
||||
/// </summary>
|
||||
/// <param name="yesno"></param>
|
||||
/// <returns></returns>
|
||||
public static string LongName(this YesNo? yesno)
|
||||
=> AttributeHelper<YesNo?>.GetHumanReadableAttribute(yesno)?.LongName ?? "Yes/No";
|
||||
|
||||
/// <summary>
|
||||
/// Get the YesNo enum value for a given nullable boolean
|
||||
/// </summary>
|
||||
/// <param name="yesno">Nullable boolean value to convert</param>
|
||||
/// <returns>YesNo represented by the nullable boolean, if possible</returns>
|
||||
public static YesNo ToYesNo(this bool yesno)
|
||||
{
|
||||
return yesno switch
|
||||
{
|
||||
false => YesNo.No,
|
||||
true => YesNo.Yes,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the YesNo enum value for a given nullable boolean
|
||||
/// </summary>
|
||||
/// <param name="yesno">Nullable boolean value to convert</param>
|
||||
/// <returns>YesNo represented by the nullable boolean, if possible</returns>
|
||||
public static YesNo? ToYesNo(this bool? yesno)
|
||||
{
|
||||
return yesno switch
|
||||
{
|
||||
false => YesNo.No,
|
||||
true => YesNo.Yes,
|
||||
_ => YesNo.NULL,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the YesNo enum value for a given string
|
||||
/// </summary>
|
||||
/// <param name="yesno">String value to convert</param>
|
||||
/// <returns>YesNo represented by the string, if possible</returns>
|
||||
public static YesNo? ToYesNo(this string? yesno)
|
||||
{
|
||||
return (yesno?.ToLowerInvariant()) switch
|
||||
{
|
||||
"no" or "false" => YesNo.No,
|
||||
"yes" or "true" => YesNo.Yes,
|
||||
_ => YesNo.NULL,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.RedumpLib.RedumpOrg.Converters;
|
||||
using SabreTools.RedumpLib.RedumpOrg.Data;
|
||||
using SabreTools.RedumpLib.Converters;
|
||||
|
||||
namespace SabreTools.RedumpLib.Data.Sections
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.RedumpLib.RedumpOrg.Converters;
|
||||
using SabreTools.RedumpLib.RedumpOrg.Data;
|
||||
using SabreTools.RedumpLib.Converters;
|
||||
|
||||
namespace SabreTools.RedumpLib.Data.Sections
|
||||
{
|
||||
|
||||
@@ -309,19 +309,4 @@ namespace SabreTools.RedumpLib.RedumpOrg.Data
|
||||
[HumanReadable(ShortName = "<b>XMID</b>:", LongName = "<b>XMID</b>:")]
|
||||
XMID,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generic yes/no values
|
||||
/// </summary>
|
||||
public enum YesNo
|
||||
{
|
||||
[HumanReadable(LongName = "Yes/No")]
|
||||
NULL = 0,
|
||||
|
||||
[HumanReadable(LongName = "No")]
|
||||
No = 1,
|
||||
|
||||
[HumanReadable(LongName = "Yes")]
|
||||
Yes = 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,62 +310,6 @@ namespace SabreTools.RedumpLib.RedumpOrg.Data
|
||||
=> AttributeHelper<SiteCode?>.GetHumanReadableAttribute(siteCode)?.ShortName;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Yes/No
|
||||
|
||||
/// <summary>
|
||||
/// Get the string representation of the YesNo value
|
||||
/// </summary>
|
||||
/// <param name="yesno"></param>
|
||||
/// <returns></returns>
|
||||
public static string LongName(this YesNo? yesno)
|
||||
=> AttributeHelper<YesNo?>.GetHumanReadableAttribute(yesno)?.LongName ?? "Yes/No";
|
||||
|
||||
/// <summary>
|
||||
/// Get the YesNo enum value for a given nullable boolean
|
||||
/// </summary>
|
||||
/// <param name="yesno">Nullable boolean value to convert</param>
|
||||
/// <returns>YesNo represented by the nullable boolean, if possible</returns>
|
||||
public static YesNo ToYesNo(this bool yesno)
|
||||
{
|
||||
return yesno switch
|
||||
{
|
||||
false => YesNo.No,
|
||||
true => YesNo.Yes,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the YesNo enum value for a given nullable boolean
|
||||
/// </summary>
|
||||
/// <param name="yesno">Nullable boolean value to convert</param>
|
||||
/// <returns>YesNo represented by the nullable boolean, if possible</returns>
|
||||
public static YesNo? ToYesNo(this bool? yesno)
|
||||
{
|
||||
return yesno switch
|
||||
{
|
||||
false => YesNo.No,
|
||||
true => YesNo.Yes,
|
||||
_ => YesNo.NULL,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the YesNo enum value for a given string
|
||||
/// </summary>
|
||||
/// <param name="yesno">String value to convert</param>
|
||||
/// <returns>YesNo represented by the string, if possible</returns>
|
||||
public static YesNo? ToYesNo(this string? yesno)
|
||||
{
|
||||
return (yesno?.ToLowerInvariant()) switch
|
||||
{
|
||||
"no" or "false" => YesNo.No,
|
||||
"yes" or "true" => YesNo.Yes,
|
||||
_ => YesNo.NULL,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#pragma warning restore IDE0072
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
using SabreTools.RedumpLib.RedumpOrg.Data;
|
||||
using SabreTools.RedumpLib.Web;
|
||||
|
||||
namespace SabreTools.RedumpLib.RedumpOrg
|
||||
|
||||
Reference in New Issue
Block a user