Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Mar 14, 2024
1 parent 6b5ad9a commit 2c01325
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 96 deletions.
22 changes: 19 additions & 3 deletions starsky/starsky.foundation.platform/VersionHelpers/SemVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static SemVersion Parse(string? version, bool throwException = true)
{
version = version.Remove(0, 1);
}

var match = ParseEx.Match(version);
switch ( match.Success )
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public int CompareTo(SemVersion? other)
if ( r != 0 ) return r;

// If other is null, CompareByPrecedence() returns 1
return CompareComponent(Build, other.Build);
return CompareComponent(Build, other?.Build);
}

/// <summary>
Expand Down Expand Up @@ -172,7 +172,7 @@ private int CompareByPrecedence(SemVersion? other)
return CompareComponent(Prerelease, other.Prerelease, true);
}

private static int CompareComponent(string a, string b, bool nonemptyIsLower = false)
private static int CompareComponent(string a, string? b, bool nonemptyIsLower = false)
{
var aEmpty = string.IsNullOrEmpty(a);
var bEmpty = string.IsNullOrEmpty(b);
Expand Down Expand Up @@ -263,6 +263,22 @@ public override bool Equals(object? obj)
&& string.Equals(Build, other.Build, StringComparison.Ordinal);
}

public static bool operator ==(SemVersion? left, SemVersion? right)
{
if ( ReferenceEquals(left, right) )
return true;

if ( left is null || right is null )
return false;

return left.Equals(right);
}

public static bool operator !=(SemVersion left, SemVersion right)
{
return !( left == right );
}

/// <summary>
/// Checks whether two semantic versions are equal.
/// </summary>
Expand Down
Loading

0 comments on commit 2c01325

Please sign in to comment.