Skip to content

Commit

Permalink
fix: compare null as lower than not null
Browse files Browse the repository at this point in the history
Reverts the logic in compare so that null is compared as lower than an existing value
  • Loading branch information
Kampfmoehre committed Feb 22, 2023
1 parent ce6cd1f commit f25ffc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public int Compare(ISemanticVersion? x, ISemanticVersion? y)
return 0;
}

var nullCompare = CheckOneIsNull(x, y);
int nullCompare = CheckOneIsNull(x, y);
if (nullCompare != 0)
{
return nullCompare;
Expand Down Expand Up @@ -62,12 +62,12 @@ private static int CheckOneIsNull(ISemanticVersion? x, ISemanticVersion? y)
{
if (x == null && y != null)
{
return 1;
return -1;
}

if (x != null && y == null)
{
return -1;
return 1;
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void Compare_Returns_Expected(string x, string y, int expected)
}

[Theory]
[InlineData(null, "1.0.0", 1)]
[InlineData("1.0.0", null, -1)]
[InlineData(null, "1.0.0", -1)]
[InlineData("1.0.0", null, 1)]
[InlineData(null, null, 0)]
public void Compare_HandlesNullValues(string x, string y, int expected)
{
Expand Down

0 comments on commit f25ffc6

Please sign in to comment.