Skip to content

Commit

Permalink
Enable Nullable ref types (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 23, 2024
1 parent 987b0eb commit 081f524
Show file tree
Hide file tree
Showing 82 changed files with 417 additions and 364 deletions.
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

0 comments on commit 081f524

Please sign in to comment.