diff --git a/Funcky.Test/Extensions/ParseExtensions/ParseExtensionsTest.Generic.cs b/Funcky.Test/Extensions/ParseExtensions/ParseExtensionsTest.Generic.cs new file mode 100644 index 00000000..d6277843 --- /dev/null +++ b/Funcky.Test/Extensions/ParseExtensions/ParseExtensionsTest.Generic.cs @@ -0,0 +1,36 @@ +#if GENERIC_PARSEABLE +using System.Globalization; + +namespace Funcky.Test.Extensions.ParseExtensions; + +public sealed partial class ParseExtensionsTest +{ + [Theory] + [MemberData(nameof(ParseableDoubleNumbers))] + public void ParseGenericStringReturnsTheExpectedDouble(Option expected, string input) + { + Assert.Equal(expected, input.ParseNumberOrNone(NumberStyles.Number, null)); + Assert.Equal(expected, input.ParseOrNone(null)); + } + + [Theory] + [MemberData(nameof(ParseableDoubleNumbers))] + public void ParseGenericSpanReturnsTheExpectedDouble(Option expected, string input) + { + Assert.Equal(expected, input.AsSpan().ParseNumberOrNone(NumberStyles.Number, null)); + Assert.Equal(expected, input.AsSpan().ParseOrNone(null)); + } + + public static TheoryData, string> ParseableDoubleNumbers() + => new() + { + { Option.Some(1.0), "1.0" }, + { Option.Some(3.145), "3.145" }, + { Option.Some(0.5), ".5" }, + { Option.Some(1.0), "1.0" }, + { Option.Some(42.0), "42" }, + { Option.None, string.Empty }, + { Option.None, "no-number" }, + }; +} +#endif