Skip to content

Commit

Permalink
target typed new. and collection expressions (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 16, 2024
1 parent 65e261f commit 743729c
Show file tree
Hide file tree
Showing 58 changed files with 714 additions and 724 deletions.
2 changes: 1 addition & 1 deletion src/Humanizer.Tests.Shared/ArticlePrefixSortTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void SortStringArrayIgnoringArticlePrefixes(string[] input, string[] expe
[Fact]
public void An_Empty_String_Array_Throws_ArgumentOutOfRangeException()
{
string[] items = { };
string[] items = [];
void action() => EnglishArticle.AppendArticlePrefix(items);
Assert.Throws<ArgumentOutOfRangeException>(action);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public void HumanizeUsesOxfordComma()
Assert.Equal("A String, Another String, or A Third String", collection.Humanize("or"));
}

private readonly List<SomeClass> _testCollection = new List<SomeClass>
{
new SomeClass { SomeInt = 1, SomeString = "One" },
new SomeClass { SomeInt = 2, SomeString = "Two" },
new SomeClass { SomeInt = 3, SomeString = "Three" }
};
private readonly List<SomeClass> _testCollection =
[
new() { SomeInt = 1, SomeString = "One" },
new() { SomeInt = 2, SomeString = "Two" },
new() { SomeInt = 3, SomeString = "Three" }
];

[Fact]
public void HumanizeDefaultsToToString() =>
Expand Down Expand Up @@ -128,4 +128,4 @@ public void HumanizeTrimsItemsByDefault() =>
/// </summary>
private static readonly Func<string, string> dummyFormatter = input => input;
}
}
}
2 changes: 1 addition & 1 deletion src/Humanizer.Tests.Shared/DateHumanize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class DateHumanize
{
private static readonly object LockObject = new object();
private static readonly object LockObject = new();

private static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow, CultureInfo culture)
{
Expand Down
442 changes: 221 additions & 221 deletions src/Humanizer.Tests.Shared/InflectorTests.cs

Large diffs are not rendered by default.

129 changes: 63 additions & 66 deletions src/Humanizer.Tests.Shared/ResourceKeyTests.cs

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/Humanizer/HeadingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public enum HeadingStyle
/// </summary>
public static class HeadingExtensions
{
internal static readonly string[] Headings = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
internal static readonly char[] HeadingArrows = { '↑', '↗', '→', '↘', '↓', '↙', '←', '↖' };
internal static readonly string[] Headings = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
internal static readonly char[] HeadingArrows = ['↑', '↗', '→', '↘', '↓', '↙', '←', '↖'];

// https://stackoverflow.com/a/7490772/1720761
/// <summary>
Expand All @@ -46,8 +46,7 @@ public static string ToHeading(this double heading, HeadingStyle style = Heading
return Resources.GetResource($"{result}_Short", culture);
}

result = Resources.GetResource(result, culture);
return result;
return Resources.GetResource(result, culture);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Humanizer/Localisation/Formatters/MalteseFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ internal class MalteseFormatter(string localeCode) :
{
private const string DualPostfix = "_Dual";

private static readonly string[] DualResourceKeys = new[]
{
private static readonly string[] DualResourceKeys =
[
"DateHumanize_MultipleDaysAgo", "DateHumanize_MultipleDaysFromNow", "DateHumanize_MultipleHoursAgo", "DateHumanize_MultipleHoursFromNow" ,
"DateHumanize_MultipleMonthsAgo", "DateHumanize_MultipleMonthsFromNow", "DateHumanize_MultipleYearsAgo", "DateHumanize_MultipleYearsFromNow",
"TimeSpanHumanize_MultipleDays", "TimeSpanHumanize_MultipleYears", "TimeSpanHumanize_MultipleMonths", "TimeSpanHumanize_MultipleHours",
"TimeSpanHumanize_MultipleWeeks"
};
];

protected override string GetResourceKey(string resourceKey, int number)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace Humanizer
{
internal class AfrikaansNumberToWordsConverter : GenderlessNumberToWordsConverter
internal class AfrikaansNumberToWordsConverter :
GenderlessNumberToWordsConverter
{
private static readonly string[] UnitsMap = { "nul", "een", "twee", "drie", "vier", "vyf", "ses", "sewe", "agt", "nege", "tien", "elf", "twaalf", "dertien", "veertien", "vyftien", "sestien", "sewentien", "agtien", "negentien" };
private static readonly string[] TensMap = { "nul", "tien", "twintig", "dertig", "veertig", "vyftig", "sestig", "sewentig", "tagtig", "negentig" };
private static readonly string[] UnitsMap = ["nul", "een", "twee", "drie", "vier", "vyf", "ses", "sewe", "agt", "nege", "tien", "elf", "twaalf", "dertien", "veertien", "vyftien", "sestien", "sewentien", "agtien", "negentien"];
private static readonly string[] TensMap = ["nul", "tien", "twintig", "dertig", "veertig", "vyftig", "sestig", "sewentig", "tagtig", "negentig"];

private static readonly Dictionary<int, string> OrdinalExceptions = new Dictionary<int, string>
private static readonly Dictionary<int, string> OrdinalExceptions = new()
{
{0, "nulste"},
{1, "eerste"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
namespace Humanizer
{
internal class ArabicNumberToWordsConverter : GenderedNumberToWordsConverter
internal class ArabicNumberToWordsConverter :
GenderedNumberToWordsConverter
{
private static readonly string[] Groups = { "مئة", "ألف", "مليون", "مليار", "تريليون", "كوادريليون", "كوينتليون", "سكستيليون" };
private static readonly string[] AppendedGroups = { "", "ألفاً", "مليوناً", "ملياراً", "تريليوناً", "كوادريليوناً", "كوينتليوناً", "سكستيليوناً" };
private static readonly string[] PluralGroups = { "", "آلاف", "ملايين", "مليارات", "تريليونات", "كوادريليونات", "كوينتليونات", "سكستيليونات" };
private static readonly string[] OnesGroup = { "", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة", "عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر" };
private static readonly string[] TensGroup = { "", "عشرة", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون" };
private static readonly string[] HundredsGroup = { "", "مئة", "مئتان", "ثلاث مئة", "أربع مئة", "خمس مئة", "ست مئة", "سبع مئة", "ثمان مئة", "تسع مئة" };
private static readonly string[] AppendedTwos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونلن" };
private static readonly string[] Twos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونان" };
private static readonly string[] Groups = ["مئة", "ألف", "مليون", "مليار", "تريليون", "كوادريليون", "كوينتليون", "سكستيليون"];
private static readonly string[] AppendedGroups = ["", "ألفاً", "مليوناً", "ملياراً", "تريليوناً", "كوادريليوناً", "كوينتليوناً", "سكستيليوناً"];
private static readonly string[] PluralGroups = ["", "آلاف", "ملايين", "مليارات", "تريليونات", "كوادريليونات", "كوينتليونات", "سكستيليونات"];
private static readonly string[] OnesGroup = ["", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة", "عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر"];
private static readonly string[] TensGroup = ["", "عشرة", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون"];
private static readonly string[] HundredsGroup = ["", "مئة", "مئتان", "ثلاث مئة", "أربع مئة", "خمس مئة", "ست مئة", "سبع مئة", "ثمان مئة", "تسع مئة"];
private static readonly string[] AppendedTwos = ["مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونلن"];
private static readonly string[] Twos = ["مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونان"];

private static readonly string[] FeminineOnesGroup = { "", "واحدة", "اثنتان", "ثلاث", "أربع", "خمس", "ست", "سبع", "ثمان", "تسع", "عشر", "إحدى عشرة", "اثنتا عشرة", "ثلاث عشرة", "أربع عشرة", "خمس عشرة", "ست عشرة", "سبع عشرة", "ثمان عشرة", "تسع عشرة" };
private static readonly string[] FeminineOnesGroup = ["", "واحدة", "اثنتان", "ثلاث", "أربع", "خمس", "ست", "سبع", "ثمان", "تسع", "عشر", "إحدى عشرة", "اثنتا عشرة", "ثلاث عشرة", "أربع عشرة", "خمس عشرة", "ست عشرة", "سبع عشرة", "ثمان عشرة", "تسع عشرة"];

public override string Convert(long number, GrammaticalGender gender, bool addAnd = true)
{
Expand Down Expand Up @@ -143,7 +144,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn
return result.Trim();
}

private static readonly Dictionary<string, string> OrdinalExceptions = new Dictionary<string, string>
private static readonly Dictionary<string, string> OrdinalExceptions = new()
{
{"واحد", "الحادي"},
{"أحد", "الحادي"},
Expand All @@ -159,7 +160,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn
{"عشرة", "العاشر"},
};

private static readonly Dictionary<string, string> FeminineOrdinalExceptions = new Dictionary<string, string>
private static readonly Dictionary<string, string> FeminineOrdinalExceptions = new()
{
{"واحدة", "الحادية"},
{"إحدى", "الحادية"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace Humanizer
{
internal class ArmenianNumberToWordsConverter : GenderlessNumberToWordsConverter
internal class ArmenianNumberToWordsConverter :
GenderlessNumberToWordsConverter
{
private static readonly string[] UnitsMap = { "զրո", "մեկ", "երկու", "երեք", "չորս", "հինգ", "վեց", "յոթ", "ութ", "ինը", "տաս", "տասնմեկ", "տասներկու", "տասներեք", "տասնչորս", "տասնհինգ", "տասնվեց", "տասնյոթ", "տասնութ", "տասնինը" };
private static readonly string[] TensMap = { "զրո", "տաս", "քսան", "երեսուն", "քառասուն", "հիսուն", "վաթսուն", "յոթանասուն", "ութսուն", "իննսուն" };
private static readonly string[] UnitsMap = ["զրո", "մեկ", "երկու", "երեք", "չորս", "հինգ", "վեց", "յոթ", "ութ", "ինը", "տաս", "տասնմեկ", "տասներկու", "տասներեք", "տասնչորս", "տասնհինգ", "տասնվեց", "տասնյոթ", "տասնութ", "տասնինը"];
private static readonly string[] TensMap = ["զրո", "տաս", "քսան", "երեսուն", "քառասուն", "հիսուն", "վաթսուն", "յոթանասուն", "ութսուն", "իննսուն"];

private static readonly Dictionary<long, string> OrdinalExceptions = new Dictionary<long, string>
private static readonly Dictionary<long, string> OrdinalExceptions = new()
{
{0, "զրոյական"},
{1, "առաջին"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace Humanizer
{
internal class AzerbaijaniNumberToWordsConverter : GenderlessNumberToWordsConverter
internal class AzerbaijaniNumberToWordsConverter :
GenderlessNumberToWordsConverter
{
private static readonly string[] UnitsMap = { "sıfır", "bir", "iki", "üç", "dörd", "beş", "altı", "yeddi", "səkkiz", "doqquz" };
private static readonly string[] TensMap = { "sıfır", "on", "iyirmi", "otuz", "qırx", "əlli", "altmış", "yetmiş", "səksən", "doxsan" };
private static readonly string[] UnitsMap = ["sıfır", "bir", "iki", "üç", "dörd", "beş", "altı", "yeddi", "səkkiz", "doqquz"];
private static readonly string[] TensMap = ["sıfır", "on", "iyirmi", "otuz", "qırx", "əlli", "altmış", "yetmiş", "səksən", "doxsan"];

private static readonly Dictionary<char, string> OrdinalSuffix = new Dictionary<char, string>
private static readonly Dictionary<char, string> OrdinalSuffix = new()
{
{'ı', "ıncı"},
{'i', "inci"},
Expand Down
Loading

0 comments on commit 743729c

Please sign in to comment.