Skip to content

Commit

Permalink
fix: fix version comparison between versions with different part count (
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire authored Feb 24, 2025
1 parent bb270d4 commit f7c8d20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ data class Version(
return -1
} else if (otherIntPart == null) {
return 1
} else {
val comparison = intPart.compareTo(otherIntPart)
if (comparison != 0) return comparison
}
}
if (versionParts.size < other.versionParts.size) return -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class VersionTest :
Triple("alpha", "beta", false),
Triple("1.2.3", "1.2.3.4", false),
Triple("3.2.1", "v3", true),
Triple("v1.2.1", "v2", false),
Triple("v1.2", "v2", false),
Triple("v1.2.1", "v1.3", false),
).forEach { (left, right, leftIsGreater) ->
test("compareTo works correctly for $left vs. $right") {
if (leftIsGreater) {
Expand Down

0 comments on commit f7c8d20

Please sign in to comment.