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

Use BigInt instead of Long for the numeric parts of Version #579

Merged
merged 1 commit into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import org.scalasteward.core.util
import scala.util.Try

final case class Version(value: String) {
def numericComponents: List[Long] =
def numericComponents: List[BigInt] =
value
.split(Array('.', '-'))
.split(Array('.', '-', '+'))
.flatMap(util.string.splitNumericAndNonNumeric)
.map {
case "SNAP" | "SNAPSHOT" => -3L
case "M" => -2L
case "RC" => -1L
case s => Try(s.toLong).getOrElse(0L)
case "SNAP" | "SNAPSHOT" => BigInt(-3)
case "M" => BigInt(-2)
case "RC" => BigInt(-1)
case s => Try(BigInt(s)).getOrElse(BigInt(0))
}
.toList
}
Expand All @@ -41,8 +41,8 @@ object Version {
val c1 = v1.numericComponents
val c2 = v2.numericComponents
val maxLength = math.max(c1.length, c2.length)
val padded1 = c1.padTo(maxLength, 0L)
val padded2 = c2.padTo(maxLength, 0L)
val padded1 = c1.padTo(maxLength, BigInt(0))
val padded2 = c2.padTo(maxLength, BigInt(0))
padded1.compare(padded2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class VersionTest extends FunSuite with Discipline with Matchers {
("2.13.0-M2", "2.13.0", LessThan),
("2.13.0-M2", "2.13.0-RC1", LessThan),
("5.3.2.201906051522-r", "5.4.0.201906121030-r", LessThan),
("105", "104", GreaterThan)
("105", "104", GreaterThan),
("1.0.0+20130313", "1.0.0+20130320", LessThan)
)

forAll(versions) { (x, y, result) =>
Expand Down