Skip to content

Commit

Permalink
Add some minimal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeApophis committed Sep 4, 2023
1 parent c4d790f commit 1651758
Showing 1 changed file with 36 additions and 0 deletions.
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

0 comments on commit 1651758

Please sign in to comment.