-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4d790f
commit 1651758
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Funcky.Test/Extensions/ParseExtensions/ParseExtensionsTest.Generic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<double> expected, string input) | ||
{ | ||
Assert.Equal(expected, input.ParseNumberOrNone<double>(NumberStyles.Number, null)); | ||
Assert.Equal(expected, input.ParseOrNone<double>(null)); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(ParseableDoubleNumbers))] | ||
public void ParseGenericSpanReturnsTheExpectedDouble(Option<double> expected, string input) | ||
{ | ||
Assert.Equal(expected, input.AsSpan().ParseNumberOrNone<double>(NumberStyles.Number, null)); | ||
Assert.Equal(expected, input.AsSpan().ParseOrNone<double>(null)); | ||
} | ||
|
||
public static TheoryData<Option<double>, 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<double>.None, string.Empty }, | ||
{ Option<double>.None, "no-number" }, | ||
}; | ||
} | ||
#endif |