From 9d48857d9bc78cafdde18efcc0d8093674e8c6fd Mon Sep 17 00:00:00 2001 From: hangy Date: Mon, 23 Aug 2021 10:09:08 +0200 Subject: [PATCH] refactor: Re-add FromAbbreviatedHeading overload without culture --- src/Humanizer.Tests.Shared/HeadingTests.cs | 13 ++++++++++++- ...cApiApprovalTest.approve_public_api.approved.txt | 1 + src/Humanizer/HeadingExtensions.cs | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Humanizer.Tests.Shared/HeadingTests.cs b/src/Humanizer.Tests.Shared/HeadingTests.cs index 3ba6b0ad5..55d3775c2 100644 --- a/src/Humanizer.Tests.Shared/HeadingTests.cs +++ b/src/Humanizer.Tests.Shared/HeadingTests.cs @@ -1,4 +1,6 @@ -using Xunit; +using System.Globalization; + +using Xunit; namespace Humanizer.Tests { @@ -189,5 +191,14 @@ public void FromHeadingArrow_Also_Works_With_Strings(string heading, double expe { Assert.Equal(expected, heading.FromHeadingArrow()); } + + [InlineData("NNW", "en-US", 337.5)] + [InlineData("ØNØ", "da", 67.5)] + [InlineData("O", "de-DE", 90.0)] + [Theory] + public void FromShortHeading_CanSpecifyCultureExplicitly(string heading, string culture, double expected) + { + Assert.Equal(expected, heading.FromAbbreviatedHeading(new CultureInfo(culture))); + } } } diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt index 91e266757..7b7e1d0a8 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt @@ -126,6 +126,7 @@ namespace Humanizer } public class static HeadingExtensions { + public static double FromAbbreviatedHeading(this string heading) { } public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo culture = null) { } public static double FromHeadingArrow(this char heading) { } public static double FromHeadingArrow(this string heading) { } diff --git a/src/Humanizer/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs index 760a4bb52..5a1621b32 100644 --- a/src/Humanizer/HeadingExtensions.cs +++ b/src/Humanizer/HeadingExtensions.cs @@ -68,6 +68,15 @@ public static char ToHeadingArrow(this double heading) return headingArrows[val % 8]; } + /// + /// Returns a heading based on the short textual representation of the heading. + /// + /// The heading. -1 if the heading could not be parsed. + public static double FromAbbreviatedHeading(this string heading) + { + return heading.FromAbbreviatedHeading(null); + } + /// /// Returns a heading based on the short textual representation of the heading. ///