Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Nullable ref types #1437

Merged
merged 44 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8c5af5e
Update ArticlePrefixSort.cs
SimonCropp Feb 22, 2024
cc4b5d3
Update Benchmarks.csproj
SimonCropp Feb 22, 2024
b9d7db5
.
SimonCropp Feb 22, 2024
6130a45
.
SimonCropp Feb 22, 2024
c32ecae
.
SimonCropp Feb 22, 2024
966d0ef
.
SimonCropp Feb 22, 2024
10a5a10
Merge branch 'main' into nullable
SimonCropp Feb 22, 2024
a7d9740
.
SimonCropp Feb 22, 2024
8569ce2
.
SimonCropp Feb 22, 2024
a06be6c
.
SimonCropp Feb 22, 2024
776ae08
.
SimonCropp Feb 22, 2024
64cf66e
.
SimonCropp Feb 22, 2024
b4360ea
Merge branch 'main' into nullable
SimonCropp Feb 22, 2024
a82c56e
.
SimonCropp Feb 22, 2024
e20ca2e
.
SimonCropp Feb 22, 2024
aa83c9c
.
SimonCropp Feb 22, 2024
4abeb7a
.
SimonCropp Feb 22, 2024
42c4361
.
SimonCropp Feb 22, 2024
cb72216
Merge branch 'main' into nullable
SimonCropp Feb 22, 2024
eacb34a
.
SimonCropp Feb 22, 2024
f00b237
.
SimonCropp Feb 22, 2024
05a03dc
.
SimonCropp Feb 22, 2024
0a45b8e
.
SimonCropp Feb 22, 2024
9be3145
.
SimonCropp Feb 22, 2024
4fc3d81
.
SimonCropp Feb 22, 2024
6e3a272
Merge branch 'main' into nullable
SimonCropp Feb 22, 2024
6a761ae
.
SimonCropp Feb 22, 2024
6bf9fd2
.
SimonCropp Feb 22, 2024
f5d913d
.
SimonCropp Feb 22, 2024
8ab984f
.
SimonCropp Feb 22, 2024
7554861
.
SimonCropp Feb 22, 2024
5589486
.
SimonCropp Feb 22, 2024
6c4c12f
Update Vocabulary.cs
SimonCropp Feb 22, 2024
cc4a84d
Update RomanianCardinalNumberConverter.cs
SimonCropp Feb 22, 2024
81a08e9
Update IndianNumberToWordsConverter.cs
SimonCropp Feb 22, 2024
8cfe3ad
Update NorwegianBokmalNumberToWordsConverter.cs
SimonCropp Feb 22, 2024
508cb80
Update EnumCache.cs
SimonCropp Feb 22, 2024
9e7d770
.
SimonCropp Feb 22, 2024
4954080
.
SimonCropp Feb 22, 2024
6401df4
.
SimonCropp Feb 22, 2024
6df6649
Merge branch 'main' into nullable
SimonCropp Feb 22, 2024
b87e36f
Update HeadingExtensions.cs
SimonCropp Feb 22, 2024
ee7d4f3
.
SimonCropp Feb 22, 2024
02a964b
.
SimonCropp Feb 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(SolutionDir)Humanizer.snk</AssemblyOriginatorKeyFile>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Using Include="System.ReadOnlySpan&lt;System.Char&gt;" Alias="CharSpan" />
Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim
[Theory]
[InlineData(19854651984, 1, TimeUnit.Second, null, "18.49 GB/s")]
[InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18.49 GB/s")]
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue)
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string? format, string expectedValue)
{
var size = ByteSize.FromBytes(bytes);
var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds);
Expand Down
12 changes: 6 additions & 6 deletions src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void LongTerabytes()
[InlineData(2.123, "#.#", "en", "2.1 TB")]
[InlineData(2.1, null, "ru-RU", "2,1 TB")]
[InlineData(2.123, "#.#", "ru-RU", "2,1 TB")]
public void HumanizesTerabytes(double input, string format, string cultureName, string expectedValue)
public void HumanizesTerabytes(double input, string? format, string cultureName, string expectedValue)
{
var culture = new CultureInfo(cultureName);

Expand Down Expand Up @@ -137,7 +137,7 @@ public void LongGigabytes()
[InlineData(2, null, "fr", "2 Go")]
[InlineData(2, "MB", "en", "2048 MB")]
[InlineData(2.123, "#.##", "en", "2.12 GB")]
public void HumanizesGigabytes(double input, string format, string cultureName, string expectedValue)
public void HumanizesGigabytes(double input, string? format, string cultureName, string expectedValue)
{
var cultureInfo = new CultureInfo(cultureName);

Expand Down Expand Up @@ -207,7 +207,7 @@ public void LongMegabytes()
[InlineData(2, null, "fr", "2 Mo")]
[InlineData(2, "KB", "en", "2048 KB")]
[InlineData(2.123, "#", "en", "2 MB")]
public void HumanizesMegabytes(double input, string format, string cultureName, string expectedValue)
public void HumanizesMegabytes(double input, string? format, string cultureName, string expectedValue)
{
var cultureInfo = new CultureInfo(cultureName);

Expand Down Expand Up @@ -277,7 +277,7 @@ public void LongKilobytes()
[InlineData(2, null, "fr", "2 Ko")]
[InlineData(2, "B", "en", "2048 B")]
[InlineData(2.123, "#.####", "en", "2.123 KB")]
public void HumanizesKilobytes(double input, string format, string cultureName, string expectedValue)
public void HumanizesKilobytes(double input, string? format, string cultureName, string expectedValue)
{
var cultureInfo = new CultureInfo(cultureName);

Expand Down Expand Up @@ -352,7 +352,7 @@ public void LongBytes()
[InlineData(10000000, "KB", "en", "9765.63 KB")]
[InlineData(10000000, "#,##0 KB", "en", "9,766 KB")]
[InlineData(10000000, "#,##0.# KB", "en", "9,765.6 KB")]
public void HumanizesBytes(double input, string format, string cultureName, string expectedValue)
public void HumanizesBytes(double input, string? format, string cultureName, string expectedValue)
{
var cultureInfo = new CultureInfo(cultureName);

Expand Down Expand Up @@ -415,7 +415,7 @@ public void LongBits()
[InlineData(2, null, "fr", "2 b")]
[InlineData(12, "B", "en", "1.5 B")]
[InlineData(10000, "#.# KB", "en", "1.2 KB")]
public void HumanizesBits(long input, string format, string cultureName, string expectedValue)
public void HumanizesBits(long input, string? format, string cultureName, string expectedValue)
{
var cultureInfo = new CultureInfo(cultureName);

Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void TryParseWorksWithLotsOfSpaces() =>

[Fact]
public void ParseThrowsOnNull() =>
Assert.Throws<ArgumentNullException>(() => { ByteSize.Parse(null); });
Assert.Throws<ArgumentNullException>(() => { ByteSize.Parse(null!); });

[Fact]
public void ParseBits() =>
Expand Down
8 changes: 4 additions & 4 deletions src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class SomeClass
{
public string SomeString;
public string? SomeString;
public int SomeInt;
public override string ToString() =>
"ToString";
Expand Down Expand Up @@ -97,15 +97,15 @@ public void HumanizeUsesObjectDisplayFormatterWhenSeparatorIsProvided()

[Fact]
public void HumanizeHandlesNullItemsWithoutAnException() =>
Assert.Null(Record.Exception(() => new object[] { null, null }.Humanize()));
Assert.Null(Record.Exception(() => new object?[] { null, null }.Humanize()));

[Fact]
public void HumanizeHandlesNullStringDisplayFormatterReturnsWithoutAnException() =>
Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => null)));
Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => null!)));

[Fact]
public void HumanizeHandlesNullObjectDisplayFormatterReturnsWithoutAnException() =>
Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => (object)null)));
Assert.Null(Record.Exception(() => new[] { "A", "B", "C" }.Humanize(_ => (object)null!)));

[Fact]
public void HumanizeRunsStringDisplayFormatterOnNulls() =>
Expand Down
10 changes: 5 additions & 5 deletions src/Humanizer.Tests.Shared/DateHumanize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class DateHumanize
{
static readonly object LockObject = new();

static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow, CultureInfo culture)
static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow, CultureInfo? culture)
{
var utcNow = DateTime.UtcNow;
var localNow = DateTime.Now;
Expand All @@ -13,15 +13,15 @@ static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow,
VerifyWithDate(expectedString, deltaFromNow, culture, localNow, utcNow);
}

static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow, CultureInfo culture)
static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow, CultureInfo? culture)
{
var utcNow = new DateTime(2013, 6, 20, 9, 58, 22, DateTimeKind.Utc);
var now = new DateTime(2013, 6, 20, 11, 58, 22, DateTimeKind.Local);

VerifyWithDate(expectedString, deltaFromNow, culture, now, utcNow);
}

static void VerifyWithDate(string expectedString, TimeSpan deltaFromBase, CultureInfo culture, DateTime baseDate, DateTime baseDateUtc)
static void VerifyWithDate(string expectedString, TimeSpan deltaFromBase, CultureInfo? culture, DateTime baseDate, DateTime baseDateUtc)
{
Assert.Equal(expectedString, baseDateUtc.Add(deltaFromBase).Humanize(utcDate: true, dateToCompareAgainst: baseDateUtc, culture: culture));
Assert.Equal(expectedString, baseDate.Add(deltaFromBase).Humanize(false, baseDate, culture: culture));
Expand All @@ -31,7 +31,7 @@ static void VerifyWithDate(string expectedString, TimeSpan deltaFromBase, Cultur
Assert.Equal(expectedString, baseDate.Add(deltaFromBase).Humanize(null, baseDate, culture: culture));
}

public static void Verify(string expectedString, int unit, TimeUnit timeUnit, Tense tense, double? precision = null, CultureInfo culture = null, DateTime? baseDate = null, DateTime? baseDateUtc = null)
public static void Verify(string expectedString, int unit, TimeUnit timeUnit, Tense tense, double? precision = null, CultureInfo? culture = null, DateTime? baseDate = null, DateTime? baseDateUtc = null)
{
// We lock this as these tests can be multi-threaded and we're setting a static
lock (LockObject)
Expand Down Expand Up @@ -85,7 +85,7 @@ public static void Verify(string expectedString, int unit, TimeUnit timeUnit, Te
}
else
{
VerifyWithDate(expectedString, deltaFromNow, culture, baseDate.Value, baseDateUtc.Value);
VerifyWithDate(expectedString, deltaFromNow, culture, baseDate.Value, baseDateUtc!.Value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim
[Theory]
[InlineData(19854651984, 1, TimeUnit.Second, null, "18,49 GB/s")]
[InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18,49 GB/s")]
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue)
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string? format, string expectedValue)
{
var size = ByteSize.FromBytes(bytes);
var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ByteSizeExtensionsTests
[InlineData(2, null, "2 TB")]
[InlineData(2, "GB", "2048 GB")]
[InlineData(2.123, "#.#", "2,1 TB")]
public void HumanizesTerabytes(double input, string format, string expectedValue) =>
public void HumanizesTerabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Terabytes().Humanize(format));

[Theory]
Expand All @@ -16,7 +16,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 GB")]
[InlineData(2, "MB", "2048 MB")]
[InlineData(2.123, "#.##", "2,12 GB")]
public void HumanizesGigabytes(double input, string format, string expectedValue) =>
public void HumanizesGigabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Gigabytes().Humanize(format));

[Theory]
Expand All @@ -25,7 +25,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 MB")]
[InlineData(2, "KB", "2048 kB")]
[InlineData(2.123, "#", "2 MB")]
public void HumanizesMegabytes(double input, string format, string expectedValue) =>
public void HumanizesMegabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Megabytes().Humanize(format));

[Theory]
Expand All @@ -34,7 +34,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 kB")]
[InlineData(2, "B", "2048 B")]
[InlineData(2.123, "#.####", "2,123 kB")]
public void HumanizesKilobytes(double input, string format, string expectedValue) =>
public void HumanizesKilobytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Kilobytes().Humanize(format));

[Theory]
Expand All @@ -48,7 +48,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue
[InlineData(10000000, "KB", "9765,63 kB")]
[InlineData(10000000, "#,##0 KB", "9.766 kB")]
[InlineData(10000000, "#,##0.# KB", "9.765,6 kB")]
public void HumanizesBytes(double input, string format, string expectedValue) =>
public void HumanizesBytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Bytes().Humanize(format));

[Theory]
Expand All @@ -57,7 +57,7 @@ public void HumanizesBytes(double input, string format, string expectedValue) =>
[InlineData(2, null, "2 bit")]
[InlineData(12, "B", "1,5 B")]
[InlineData(10000, "#.# KB", "1,2 kB")]
public void HumanizesBits(long input, string format, string expectedValue) =>
public void HumanizesBits(long input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Bits().Humanize(format));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ByteSizeExtensionsTests
[InlineData(2, null, "2 To")]
[InlineData(2, "GB", "2048 Go")]
[InlineData(2.123, "#.#", "2,1 To")]
public void HumanizesTerabytes(double input, string format, string expectedValue) =>
public void HumanizesTerabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Terabytes().Humanize(format));

[Theory]
Expand All @@ -16,7 +16,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 Go")]
[InlineData(2, "MB", "2048 Mo")]
[InlineData(2.123, "#.##", "2,12 Go")]
public void HumanizesGigabytes(double input, string format, string expectedValue) =>
public void HumanizesGigabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Gigabytes().Humanize(format));

[Theory]
Expand All @@ -25,7 +25,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 Mo")]
[InlineData(2, "KB", "2048 Ko")]
[InlineData(2.123, "#", "2 Mo")]
public void HumanizesMegabytes(double input, string format, string expectedValue) =>
public void HumanizesMegabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Megabytes().Humanize(format));

[Theory]
Expand All @@ -34,7 +34,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 Ko")]
[InlineData(2, "B", "2048 o")]
[InlineData(2.123, "#.####", "2,123 Ko")]
public void HumanizesKilobytes(double input, string format, string expectedValue) =>
public void HumanizesKilobytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Kilobytes().Humanize(format));

[Theory]
Expand All @@ -48,7 +48,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue
[InlineData(10000000, "KB", "9765,63 Ko")]
[InlineData(10000000, "#,##0 KB", "9 766 Ko")]
[InlineData(10000000, "#,##0.# KB", "9 765,6 Ko")]
public void HumanizesBytes(double input, string format, string expectedValue)
public void HumanizesBytes(double input, string? format, string expectedValue)
{
expectedValue = expectedValue.Replace(" ", NumberFormatInfo.CurrentInfo.NumberGroupSeparator);
Assert.Equal(
Expand All @@ -64,7 +64,7 @@ public void HumanizesBytes(double input, string format, string expectedValue)
[InlineData(2, null, "2 b")]
[InlineData(12, "B", "1,5 o")]
[InlineData(10000, "#.# KB", "1,2 Ko")]
public void HumanizesBits(long input, string format, string expectedValue) =>
public void HumanizesBits(long input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Bits().Humanize(format));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ByteSizeExtensionsTests
[InlineData(2, null, "2 TB")]
[InlineData(2, "GB", "2048 GB")]
[InlineData(2.123, "#.#", "2,1 TB")]
public void HumanizesTerabytes(double input, string format, string expectedValue) =>
public void HumanizesTerabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Terabytes().Humanize(format));

[Theory]
Expand All @@ -16,7 +16,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 GB")]
[InlineData(2, "MB", "2048 MB")]
[InlineData(2.123, "#.##", "2,12 GB")]
public void HumanizesGigabytes(double input, string format, string expectedValue) =>
public void HumanizesGigabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Gigabytes().Humanize(format));

[Theory]
Expand All @@ -25,7 +25,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 MB")]
[InlineData(2, "KB", "2048 kB")]
[InlineData(2.123, "#", "2 MB")]
public void HumanizesMegabytes(double input, string format, string expectedValue) =>
public void HumanizesMegabytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Megabytes().Humanize(format));

[Theory]
Expand All @@ -34,7 +34,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue
[InlineData(2, null, "2 kB")]
[InlineData(2, "B", "2048 B")]
[InlineData(2.123, "#.####", "2,123 kB")]
public void HumanizesKilobytes(double input, string format, string expectedValue) =>
public void HumanizesKilobytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Kilobytes().Humanize(format));

[Theory]
Expand All @@ -48,7 +48,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue
[InlineData(10000000, "KB", "9765,63 kB")]
[InlineData(10000000, "#,##0 KB", "9.766 kB")]
[InlineData(10000000, "#,##0.# KB", "9.765,6 kB")]
public void HumanizesBytes(double input, string format, string expectedValue) =>
public void HumanizesBytes(double input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Bytes().Humanize(format));

[Theory]
Expand All @@ -57,7 +57,7 @@ public void HumanizesBytes(double input, string format, string expectedValue) =>
[InlineData(2, null, "2 b")]
[InlineData(12, "B", "1,5 B")]
[InlineData(10000, "#.# KB", "1,2 kB")]
public void HumanizesBits(long input, string format, string expectedValue) =>
public void HumanizesBits(long input, string? format, string expectedValue) =>
Assert.Equal(expectedValue, input.Bits().Humanize(format));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim
[Theory]
[InlineData(19854651984, 1, TimeUnit.Second, null, "18,49 GB/s")]
[InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18,49 GB/s")]
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue)
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string? format, string expectedValue)
{
var size = ByteSize.FromBytes(bytes);
var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds);
Expand Down
Loading