diff --git a/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.cs b/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.cs index 5302c6b..f52cf9f 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.cs +++ b/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.cs @@ -64,18 +64,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -91,18 +92,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -118,25 +120,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -154,12 +158,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -169,13 +175,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -250,17 +256,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -276,17 +283,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -302,24 +310,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -337,11 +347,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -351,13 +363,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -434,18 +446,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -461,18 +474,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -488,25 +502,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -524,12 +540,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -539,13 +557,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -620,17 +638,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -646,17 +665,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -672,24 +692,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -707,11 +729,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -721,13 +745,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -804,18 +828,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -831,18 +856,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -858,25 +884,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -894,12 +922,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -909,13 +939,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -990,17 +1020,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1016,17 +1047,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1042,24 +1074,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1077,11 +1111,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1091,13 +1127,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1174,18 +1210,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1201,18 +1238,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1228,25 +1266,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1264,12 +1304,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1279,13 +1321,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1360,17 +1402,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1386,17 +1429,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1412,24 +1456,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1447,11 +1493,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1461,13 +1509,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.tt b/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.tt index bd7d667..b690bbd 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.tt +++ b/src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.tt @@ -87,20 +87,21 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>("", ignoreCase)).Should().Throw(); @@ -116,20 +117,21 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>("", ignoreCase)).Should().Throw(); @@ -145,27 +147,29 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -183,14 +187,16 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -200,13 +206,13 @@ public sealed class Basic<#= x.AliasType #>Tests FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.cs b/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.cs index 15d9592..5172a35 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.cs +++ b/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.cs @@ -54,19 +54,20 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -82,19 +83,20 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -110,26 +112,28 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -147,13 +151,15 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -163,13 +169,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -237,19 +243,20 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -265,19 +272,20 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -293,26 +301,28 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -330,13 +340,15 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -346,13 +358,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.tt b/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.tt index d577f09..a02c70b 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.tt +++ b/src/insights/FastEnum.UnitTests/Cases/Generators/SameValueTests.tt @@ -67,19 +67,20 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>("", ignoreCase)).Should().Throw(); @@ -95,19 +96,20 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>, <#= x.BoosterType #>>("", ignoreCase)).Should().Throw(); @@ -123,26 +125,28 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -160,13 +164,15 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -176,13 +182,13 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>, <#= x.BoosterType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.cs b/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.cs index 015f9a8..738fecb 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.cs +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.cs @@ -197,18 +197,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -224,18 +225,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -251,25 +253,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -287,12 +291,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue), valueString: ((sbyte)SByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero), valueString: ((sbyte)SByteEnum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue), valueString: ((sbyte)SByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: SByteEnum.MinValue, name: nameof(SByteEnum.MinValue)), + (value: SByteEnum.Zero, name: nameof(SByteEnum.Zero)), + (value: SByteEnum.MaxValue, name: nameof(SByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -302,13 +308,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -557,17 +563,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -583,17 +590,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -609,24 +617,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -644,11 +654,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue), valueString: ((byte)ByteEnum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue), valueString: ((byte)ByteEnum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: ByteEnum.MinValue, name: nameof(ByteEnum.MinValue)), + (value: ByteEnum.MaxValue, name: nameof(ByteEnum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -658,13 +670,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -915,18 +927,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -942,18 +955,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -969,25 +983,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1005,12 +1021,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue), valueString: ((short)Int16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero), valueString: ((short)Int16Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue), valueString: ((short)Int16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int16Enum.MinValue, name: nameof(Int16Enum.MinValue)), + (value: Int16Enum.Zero, name: nameof(Int16Enum.Zero)), + (value: Int16Enum.MaxValue, name: nameof(Int16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1020,13 +1038,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1275,17 +1293,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1301,17 +1320,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1327,24 +1347,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1362,11 +1384,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue), valueString: ((ushort)UInt16Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue), valueString: ((ushort)UInt16Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt16Enum.MinValue, name: nameof(UInt16Enum.MinValue)), + (value: UInt16Enum.MaxValue, name: nameof(UInt16Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1376,13 +1400,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1633,18 +1657,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1660,18 +1685,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1687,25 +1713,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1723,12 +1751,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue), valueString: ((int)Int32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero), valueString: ((int)Int32Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue), valueString: ((int)Int32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int32Enum.MinValue, name: nameof(Int32Enum.MinValue)), + (value: Int32Enum.Zero, name: nameof(Int32Enum.Zero)), + (value: Int32Enum.MaxValue, name: nameof(Int32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1738,13 +1768,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1993,17 +2023,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2019,17 +2050,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2045,24 +2077,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2080,11 +2114,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue), valueString: ((uint)UInt32Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue), valueString: ((uint)UInt32Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt32Enum.MinValue, name: nameof(UInt32Enum.MinValue)), + (value: UInt32Enum.MaxValue, name: nameof(UInt32Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2094,13 +2130,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2351,18 +2387,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2378,18 +2415,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2405,25 +2443,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2441,12 +2481,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue), valueString: ((long)Int64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero), valueString: ((long)Int64Enum.Zero).ToString(CultureInfo.InvariantCulture)), - (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue), valueString: ((long)Int64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: Int64Enum.MinValue, name: nameof(Int64Enum.MinValue)), + (value: Int64Enum.Zero, name: nameof(Int64Enum.Zero)), + (value: Int64Enum.MaxValue, name: nameof(Int64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2456,13 +2498,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2711,17 +2753,18 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2737,17 +2780,18 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2763,24 +2807,26 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2798,11 +2844,13 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue), valueString: ((ulong)UInt64Enum.MinValue).ToString(CultureInfo.InvariantCulture)), - (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue), valueString: ((ulong)UInt64Enum.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: UInt64Enum.MinValue, name: nameof(UInt64Enum.MinValue)), + (value: UInt64Enum.MaxValue, name: nameof(UInt64Enum.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2812,13 +2860,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.tt b/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.tt index f5e6459..217ad12 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.tt +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/BasicTests.tt @@ -222,20 +222,21 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -251,20 +252,21 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -280,27 +282,29 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -318,14 +322,16 @@ public sealed class Basic<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MinValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MinValue, name: nameof(<#= x.EnumType #>.MinValue)), <# if (x.IsSignedType) { #> - (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.Zero).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.Zero, name: nameof(<#= x.EnumType #>.Zero)), <# } #> - (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.MaxValue).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.MaxValue, name: nameof(<#= x.EnumType #>.MaxValue)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -335,13 +341,13 @@ public sealed class Basic<#= x.AliasType #>Tests FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.cs b/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.cs index 7567118..930d965 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.cs +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.cs @@ -201,18 +201,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A), valueString: ((sbyte)ContinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B), valueString: ((sbyte)ContinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C), valueString: ((sbyte)ContinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A)), + (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B)), + (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -228,18 +229,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A), valueString: ((sbyte)ContinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B), valueString: ((sbyte)ContinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C), valueString: ((sbyte)ContinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A)), + (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B)), + (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -255,25 +257,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A), valueString: ((sbyte)ContinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B), valueString: ((sbyte)ContinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C), valueString: ((sbyte)ContinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A)), + (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B)), + (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -291,12 +295,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A), valueString: ((sbyte)ContinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B), valueString: ((sbyte)ContinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C), valueString: ((sbyte)ContinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousSByteEnum.A, name: nameof(ContinuousSByteEnum.A)), + (value: ContinuousSByteEnum.B, name: nameof(ContinuousSByteEnum.B)), + (value: ContinuousSByteEnum.C, name: nameof(ContinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -306,13 +312,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -568,18 +574,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A), valueString: ((byte)ContinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B), valueString: ((byte)ContinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C), valueString: ((byte)ContinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A)), + (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B)), + (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -595,18 +602,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A), valueString: ((byte)ContinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B), valueString: ((byte)ContinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C), valueString: ((byte)ContinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A)), + (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B)), + (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -622,25 +630,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A), valueString: ((byte)ContinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B), valueString: ((byte)ContinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C), valueString: ((byte)ContinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A)), + (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B)), + (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -658,12 +668,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A), valueString: ((byte)ContinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B), valueString: ((byte)ContinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C), valueString: ((byte)ContinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousByteEnum.A, name: nameof(ContinuousByteEnum.A)), + (value: ContinuousByteEnum.B, name: nameof(ContinuousByteEnum.B)), + (value: ContinuousByteEnum.C, name: nameof(ContinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -673,13 +685,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -935,18 +947,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A), valueString: ((short)ContinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B), valueString: ((short)ContinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C), valueString: ((short)ContinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A)), + (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B)), + (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -962,18 +975,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A), valueString: ((short)ContinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B), valueString: ((short)ContinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C), valueString: ((short)ContinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A)), + (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B)), + (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -989,25 +1003,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A), valueString: ((short)ContinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B), valueString: ((short)ContinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C), valueString: ((short)ContinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A)), + (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B)), + (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1025,12 +1041,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A), valueString: ((short)ContinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B), valueString: ((short)ContinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C), valueString: ((short)ContinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt16Enum.A, name: nameof(ContinuousInt16Enum.A)), + (value: ContinuousInt16Enum.B, name: nameof(ContinuousInt16Enum.B)), + (value: ContinuousInt16Enum.C, name: nameof(ContinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1040,13 +1058,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1302,18 +1320,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A), valueString: ((ushort)ContinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B), valueString: ((ushort)ContinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C), valueString: ((ushort)ContinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A)), + (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B)), + (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1329,18 +1348,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A), valueString: ((ushort)ContinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B), valueString: ((ushort)ContinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C), valueString: ((ushort)ContinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A)), + (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B)), + (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1356,25 +1376,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A), valueString: ((ushort)ContinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B), valueString: ((ushort)ContinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C), valueString: ((ushort)ContinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A)), + (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B)), + (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1392,12 +1414,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A), valueString: ((ushort)ContinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B), valueString: ((ushort)ContinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C), valueString: ((ushort)ContinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt16Enum.A, name: nameof(ContinuousUInt16Enum.A)), + (value: ContinuousUInt16Enum.B, name: nameof(ContinuousUInt16Enum.B)), + (value: ContinuousUInt16Enum.C, name: nameof(ContinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1407,13 +1431,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1669,18 +1693,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A), valueString: ((int)ContinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B), valueString: ((int)ContinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C), valueString: ((int)ContinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A)), + (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B)), + (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1696,18 +1721,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A), valueString: ((int)ContinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B), valueString: ((int)ContinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C), valueString: ((int)ContinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A)), + (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B)), + (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1723,25 +1749,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A), valueString: ((int)ContinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B), valueString: ((int)ContinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C), valueString: ((int)ContinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A)), + (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B)), + (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1759,12 +1787,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A), valueString: ((int)ContinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B), valueString: ((int)ContinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C), valueString: ((int)ContinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt32Enum.A, name: nameof(ContinuousInt32Enum.A)), + (value: ContinuousInt32Enum.B, name: nameof(ContinuousInt32Enum.B)), + (value: ContinuousInt32Enum.C, name: nameof(ContinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1774,13 +1804,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2036,18 +2066,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A), valueString: ((uint)ContinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B), valueString: ((uint)ContinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C), valueString: ((uint)ContinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A)), + (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B)), + (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2063,18 +2094,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A), valueString: ((uint)ContinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B), valueString: ((uint)ContinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C), valueString: ((uint)ContinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A)), + (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B)), + (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2090,25 +2122,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A), valueString: ((uint)ContinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B), valueString: ((uint)ContinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C), valueString: ((uint)ContinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A)), + (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B)), + (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2126,12 +2160,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A), valueString: ((uint)ContinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B), valueString: ((uint)ContinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C), valueString: ((uint)ContinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt32Enum.A, name: nameof(ContinuousUInt32Enum.A)), + (value: ContinuousUInt32Enum.B, name: nameof(ContinuousUInt32Enum.B)), + (value: ContinuousUInt32Enum.C, name: nameof(ContinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2141,13 +2177,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2403,18 +2439,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A), valueString: ((long)ContinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B), valueString: ((long)ContinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C), valueString: ((long)ContinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A)), + (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B)), + (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2430,18 +2467,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A), valueString: ((long)ContinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B), valueString: ((long)ContinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C), valueString: ((long)ContinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A)), + (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B)), + (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2457,25 +2495,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A), valueString: ((long)ContinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B), valueString: ((long)ContinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C), valueString: ((long)ContinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A)), + (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B)), + (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2493,12 +2533,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A), valueString: ((long)ContinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B), valueString: ((long)ContinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C), valueString: ((long)ContinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousInt64Enum.A, name: nameof(ContinuousInt64Enum.A)), + (value: ContinuousInt64Enum.B, name: nameof(ContinuousInt64Enum.B)), + (value: ContinuousInt64Enum.C, name: nameof(ContinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2508,13 +2550,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2770,18 +2812,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A), valueString: ((ulong)ContinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B), valueString: ((ulong)ContinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C), valueString: ((ulong)ContinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A)), + (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B)), + (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2797,18 +2840,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A), valueString: ((ulong)ContinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B), valueString: ((ulong)ContinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C), valueString: ((ulong)ContinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A)), + (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B)), + (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2824,25 +2868,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A), valueString: ((ulong)ContinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B), valueString: ((ulong)ContinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C), valueString: ((ulong)ContinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A)), + (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B)), + (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2860,12 +2906,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A), valueString: ((ulong)ContinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B), valueString: ((ulong)ContinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C), valueString: ((ulong)ContinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: ContinuousUInt64Enum.A, name: nameof(ContinuousUInt64Enum.A)), + (value: ContinuousUInt64Enum.B, name: nameof(ContinuousUInt64Enum.B)), + (value: ContinuousUInt64Enum.C, name: nameof(ContinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2875,13 +2923,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.tt b/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.tt index 72476d5..8bb04a7 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.tt +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/ContinuousTests.tt @@ -220,18 +220,19 @@ public sealed class Continuous<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -247,18 +248,19 @@ public sealed class Continuous<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -274,25 +276,27 @@ public sealed class Continuous<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -310,12 +314,14 @@ public sealed class Continuous<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -325,13 +331,13 @@ public sealed class Continuous<#= x.AliasType #>Tests FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.cs b/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.cs index 4443a88..d1e6006 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.cs +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.cs @@ -197,18 +197,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A), valueString: ((sbyte)DiscontinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B), valueString: ((sbyte)DiscontinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C), valueString: ((sbyte)DiscontinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A)), + (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B)), + (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -224,18 +225,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A), valueString: ((sbyte)DiscontinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B), valueString: ((sbyte)DiscontinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C), valueString: ((sbyte)DiscontinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A)), + (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B)), + (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -251,25 +253,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A), valueString: ((sbyte)DiscontinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B), valueString: ((sbyte)DiscontinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C), valueString: ((sbyte)DiscontinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A)), + (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B)), + (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -287,12 +291,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A), valueString: ((sbyte)DiscontinuousSByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B), valueString: ((sbyte)DiscontinuousSByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C), valueString: ((sbyte)DiscontinuousSByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousSByteEnum.A, name: nameof(DiscontinuousSByteEnum.A)), + (value: DiscontinuousSByteEnum.B, name: nameof(DiscontinuousSByteEnum.B)), + (value: DiscontinuousSByteEnum.C, name: nameof(DiscontinuousSByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((sbyte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -302,13 +308,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -560,18 +566,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A), valueString: ((byte)DiscontinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B), valueString: ((byte)DiscontinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C), valueString: ((byte)DiscontinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A)), + (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B)), + (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -587,18 +594,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A), valueString: ((byte)DiscontinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B), valueString: ((byte)DiscontinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C), valueString: ((byte)DiscontinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A)), + (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B)), + (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -614,25 +622,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A), valueString: ((byte)DiscontinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B), valueString: ((byte)DiscontinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C), valueString: ((byte)DiscontinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A)), + (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B)), + (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -650,12 +660,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A), valueString: ((byte)DiscontinuousByteEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B), valueString: ((byte)DiscontinuousByteEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C), valueString: ((byte)DiscontinuousByteEnum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousByteEnum.A, name: nameof(DiscontinuousByteEnum.A)), + (value: DiscontinuousByteEnum.B, name: nameof(DiscontinuousByteEnum.B)), + (value: DiscontinuousByteEnum.C, name: nameof(DiscontinuousByteEnum.C)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -665,13 +677,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -923,18 +935,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A), valueString: ((short)DiscontinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B), valueString: ((short)DiscontinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C), valueString: ((short)DiscontinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A)), + (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B)), + (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -950,18 +963,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A), valueString: ((short)DiscontinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B), valueString: ((short)DiscontinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C), valueString: ((short)DiscontinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A)), + (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B)), + (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -977,25 +991,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A), valueString: ((short)DiscontinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B), valueString: ((short)DiscontinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C), valueString: ((short)DiscontinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A)), + (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B)), + (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1013,12 +1029,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A), valueString: ((short)DiscontinuousInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B), valueString: ((short)DiscontinuousInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C), valueString: ((short)DiscontinuousInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt16Enum.A, name: nameof(DiscontinuousInt16Enum.A)), + (value: DiscontinuousInt16Enum.B, name: nameof(DiscontinuousInt16Enum.B)), + (value: DiscontinuousInt16Enum.C, name: nameof(DiscontinuousInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((short)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1028,13 +1046,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1286,18 +1304,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A), valueString: ((ushort)DiscontinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B), valueString: ((ushort)DiscontinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C), valueString: ((ushort)DiscontinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A)), + (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B)), + (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1313,18 +1332,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A), valueString: ((ushort)DiscontinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B), valueString: ((ushort)DiscontinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C), valueString: ((ushort)DiscontinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A)), + (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B)), + (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1340,25 +1360,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A), valueString: ((ushort)DiscontinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B), valueString: ((ushort)DiscontinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C), valueString: ((ushort)DiscontinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A)), + (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B)), + (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1376,12 +1398,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A), valueString: ((ushort)DiscontinuousUInt16Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B), valueString: ((ushort)DiscontinuousUInt16Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C), valueString: ((ushort)DiscontinuousUInt16Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt16Enum.A, name: nameof(DiscontinuousUInt16Enum.A)), + (value: DiscontinuousUInt16Enum.B, name: nameof(DiscontinuousUInt16Enum.B)), + (value: DiscontinuousUInt16Enum.C, name: nameof(DiscontinuousUInt16Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ushort)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1391,13 +1415,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1649,18 +1673,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A), valueString: ((int)DiscontinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B), valueString: ((int)DiscontinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C), valueString: ((int)DiscontinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A)), + (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B)), + (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1676,18 +1701,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A), valueString: ((int)DiscontinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B), valueString: ((int)DiscontinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C), valueString: ((int)DiscontinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A)), + (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B)), + (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -1703,25 +1729,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A), valueString: ((int)DiscontinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B), valueString: ((int)DiscontinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C), valueString: ((int)DiscontinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A)), + (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B)), + (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -1739,12 +1767,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A), valueString: ((int)DiscontinuousInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B), valueString: ((int)DiscontinuousInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C), valueString: ((int)DiscontinuousInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt32Enum.A, name: nameof(DiscontinuousInt32Enum.A)), + (value: DiscontinuousInt32Enum.B, name: nameof(DiscontinuousInt32Enum.B)), + (value: DiscontinuousInt32Enum.C, name: nameof(DiscontinuousInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((int)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -1754,13 +1784,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2012,18 +2042,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A), valueString: ((uint)DiscontinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B), valueString: ((uint)DiscontinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C), valueString: ((uint)DiscontinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A)), + (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B)), + (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2039,18 +2070,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A), valueString: ((uint)DiscontinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B), valueString: ((uint)DiscontinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C), valueString: ((uint)DiscontinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A)), + (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B)), + (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2066,25 +2098,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A), valueString: ((uint)DiscontinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B), valueString: ((uint)DiscontinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C), valueString: ((uint)DiscontinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A)), + (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B)), + (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2102,12 +2136,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A), valueString: ((uint)DiscontinuousUInt32Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B), valueString: ((uint)DiscontinuousUInt32Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C), valueString: ((uint)DiscontinuousUInt32Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt32Enum.A, name: nameof(DiscontinuousUInt32Enum.A)), + (value: DiscontinuousUInt32Enum.B, name: nameof(DiscontinuousUInt32Enum.B)), + (value: DiscontinuousUInt32Enum.C, name: nameof(DiscontinuousUInt32Enum.C)), }; foreach (var x in parameters) { + var valueString = ((uint)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2117,13 +2153,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2375,18 +2411,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A), valueString: ((long)DiscontinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B), valueString: ((long)DiscontinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C), valueString: ((long)DiscontinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A)), + (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B)), + (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2402,18 +2439,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A), valueString: ((long)DiscontinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B), valueString: ((long)DiscontinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C), valueString: ((long)DiscontinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A)), + (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B)), + (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2429,25 +2467,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A), valueString: ((long)DiscontinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B), valueString: ((long)DiscontinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C), valueString: ((long)DiscontinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A)), + (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B)), + (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2465,12 +2505,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A), valueString: ((long)DiscontinuousInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B), valueString: ((long)DiscontinuousInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C), valueString: ((long)DiscontinuousInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousInt64Enum.A, name: nameof(DiscontinuousInt64Enum.A)), + (value: DiscontinuousInt64Enum.B, name: nameof(DiscontinuousInt64Enum.B)), + (value: DiscontinuousInt64Enum.C, name: nameof(DiscontinuousInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((long)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2480,13 +2522,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2738,18 +2780,19 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A), valueString: ((ulong)DiscontinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B), valueString: ((ulong)DiscontinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C), valueString: ((ulong)DiscontinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A)), + (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B)), + (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2765,18 +2808,19 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A), valueString: ((ulong)DiscontinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B), valueString: ((ulong)DiscontinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C), valueString: ((ulong)DiscontinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A)), + (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B)), + (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -2792,25 +2836,27 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A), valueString: ((ulong)DiscontinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B), valueString: ((ulong)DiscontinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C), valueString: ((ulong)DiscontinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A)), + (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B)), + (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -2828,12 +2874,14 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A), valueString: ((ulong)DiscontinuousUInt64Enum.A).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B), valueString: ((ulong)DiscontinuousUInt64Enum.B).ToString(CultureInfo.InvariantCulture)), - (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C), valueString: ((ulong)DiscontinuousUInt64Enum.C).ToString(CultureInfo.InvariantCulture)), + (value: DiscontinuousUInt64Enum.A, name: nameof(DiscontinuousUInt64Enum.A)), + (value: DiscontinuousUInt64Enum.B, name: nameof(DiscontinuousUInt64Enum.B)), + (value: DiscontinuousUInt64Enum.C, name: nameof(DiscontinuousUInt64Enum.C)), }; foreach (var x in parameters) { + var valueString = ((ulong)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -2843,13 +2891,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.tt b/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.tt index 7a3967c..9a0bf4b 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.tt +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/DiscontinuousTests.tt @@ -216,18 +216,19 @@ public sealed class Discontinuous<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -243,18 +244,19 @@ public sealed class Discontinuous<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -270,25 +272,27 @@ public sealed class Discontinuous<#= x.AliasType #>Tests const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -306,12 +310,14 @@ public sealed class Discontinuous<#= x.AliasType #>Tests const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -321,13 +327,13 @@ public sealed class Discontinuous<#= x.AliasType #>Tests FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.cs b/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.cs index b2d71f5..9e344b0 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.cs +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.cs @@ -100,19 +100,20 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -128,19 +129,20 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -156,26 +158,28 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -193,13 +197,15 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A), valueString: ((byte)SameValueContinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B), valueString: ((byte)SameValueContinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C), valueString: ((byte)SameValueContinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D), valueString: ((byte)SameValueContinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueContinuousEnum.A, name: nameof(SameValueContinuousEnum.A)), + (value: SameValueContinuousEnum.B, name: nameof(SameValueContinuousEnum.B)), + (value: SameValueContinuousEnum.C, name: nameof(SameValueContinuousEnum.C)), + (value: SameValueContinuousEnum.D, name: nameof(SameValueContinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -209,13 +215,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -398,19 +404,20 @@ public void Parse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -426,19 +433,20 @@ public void ParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse("", ignoreCase)).Should().Throw(); @@ -454,26 +462,28 @@ public void TryParse() const bool ignoreCase = false; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -491,13 +501,15 @@ public void TryParseIgnoreCase() const bool ignoreCase = true; var parameters = new[] { - (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A), valueString: ((byte)SameValueDiscontinuousEnum.A).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B), valueString: ((byte)SameValueDiscontinuousEnum.B).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C), valueString: ((byte)SameValueDiscontinuousEnum.C).ToString(CultureInfo.InvariantCulture)), - (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D), valueString: ((byte)SameValueDiscontinuousEnum.D).ToString(CultureInfo.InvariantCulture)), + (value: SameValueDiscontinuousEnum.A, name: nameof(SameValueDiscontinuousEnum.A)), + (value: SameValueDiscontinuousEnum.B, name: nameof(SameValueDiscontinuousEnum.B)), + (value: SameValueDiscontinuousEnum.C, name: nameof(SameValueDiscontinuousEnum.C)), + (value: SameValueDiscontinuousEnum.D, name: nameof(SameValueDiscontinuousEnum.D)), }; foreach (var x in parameters) { + var valueString = ((byte)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -507,13 +519,13 @@ public void TryParseIgnoreCase() FastEnum.TryParse(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse((string?)null, ignoreCase, out var _).Should().BeFalse(); diff --git a/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.tt b/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.tt index e7bb740..0681d66 100644 --- a/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.tt +++ b/src/insights/FastEnum.UnitTests/Cases/Reflections/SameValueTests.tt @@ -113,19 +113,20 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FluentActions.Invoking(() => FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase)).Should().Throw(); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -141,19 +142,20 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); FastEnum.Parse<<#= x.EnumType #>>(x.name, ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); FastEnum.Parse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString, ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); - FastEnum.Parse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString, ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); + FastEnum.Parse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase).Should().Be(x.value); } FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>((string?)null, ignoreCase)).Should().Throw(); FluentActions.Invoking(static () => FastEnum.Parse<<#= x.EnumType #>>("", ignoreCase)).Should().Throw(); @@ -169,26 +171,28 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = false; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeFalse(); FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var _).Should().BeTrue(); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r2).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r2).Should().BeTrue(); r2.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse(); @@ -206,13 +210,15 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" const bool ignoreCase = true; var parameters = new[] { - (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.A).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.B).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.C).ToString(CultureInfo.InvariantCulture)), - (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D), valueString: ((<#= x.UnderlyingType #>)<#= x.EnumType #>.D).ToString(CultureInfo.InvariantCulture)), + (value: <#= x.EnumType #>.A, name: nameof(<#= x.EnumType #>.A)), + (value: <#= x.EnumType #>.B, name: nameof(<#= x.EnumType #>.B)), + (value: <#= x.EnumType #>.C, name: nameof(<#= x.EnumType #>.C)), + (value: <#= x.EnumType #>.D, name: nameof(<#= x.EnumType #>.D)), }; foreach (var x in parameters) { + var valueString = ((<#= x.UnderlyingType #>)x.value).ToString(CultureInfo.InvariantCulture); + FastEnum.TryParse<<#= x.EnumType #>>(x.name, ignoreCase, out var r1).Should().BeTrue(); r1.Should().Be(x.value); @@ -222,13 +228,13 @@ public sealed class SameValue<#= x.IsContinuous ? "Continuous" : "Discontinuous" FastEnum.TryParse<<#= x.EnumType #>>(x.name.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r3).Should().BeTrue(); r3.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString, ignoreCase, out var r4).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString, ignoreCase, out var r4).Should().BeTrue(); r4.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToLower(CultureInfo.InvariantCulture), ignoreCase, out var r5).Should().BeTrue(); r5.Should().Be(x.value); - FastEnum.TryParse<<#= x.EnumType #>>(x.valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); + FastEnum.TryParse<<#= x.EnumType #>>(valueString.ToUpper(CultureInfo.InvariantCulture), ignoreCase, out var r6).Should().BeTrue(); r6.Should().Be(x.value); } FastEnum.TryParse<<#= x.EnumType #>>((string?)null, ignoreCase, out var _).Should().BeFalse();