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

allow to use RC versions in arguments #2084

Merged
merged 1 commit into from
Sep 27, 2024
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 @@ -17,6 +17,7 @@ sealed trait ScalaVersion {
val major: MajorVersion
val minor: Option[Int]
val patch: Option[Int]
val rc: Option[Int]

def binary: Try[ScalaVersion] = (major, minor) match {
case (Major.Scala2, None) =>
Expand Down Expand Up @@ -46,6 +47,8 @@ sealed trait ScalaVersion {
case Minor(major, minorVersion) => s"${major.value}.${minorVersion}"
case Patch(major, minorVersion, patchVersion) =>
s"${major.value}.${minorVersion}.$patchVersion"
case RC(major, minorVersion, patchVersion, rc) =>
s"${major.value}.${minorVersion}.$patchVersion-RC$rc"
}
}

Expand All @@ -56,17 +59,31 @@ object ScalaVersion {
case class Major(major: MajorVersion) extends ScalaVersion {
override val minor = None
override val patch = None
override val rc = None
}
case class Minor(major: MajorVersion, minorVersion: Int)
extends ScalaVersion {
override val minor: Some[Int] = Some(minorVersion)
override val patch = None
override val rc = None

}
case class Patch(major: MajorVersion, minorVersion: Int, patchVersion: Int)
extends ScalaVersion {
override val minor: Some[Int] = Some(minorVersion)
override val patch: Some[Int] = Some(patchVersion)
override val rc = None
}

case class RC(
major: MajorVersion,
minorVersion: Int,
patchVersion: Int,
rcVersion: Int
) extends ScalaVersion {
override val minor: Some[Int] = Some(minorVersion)
override val patch: Some[Int] = Some(patchVersion)
override val rc: Some[Int] = Some(rcVersion)
}

sealed trait MajorVersion {
Expand Down Expand Up @@ -97,12 +114,17 @@ object ScalaVersion {
private val intPattern = """\d{1,2}"""
private val FullVersion =
raw"""($intPattern)\.($intPattern)\.($intPattern)""".r
private val RcVersion =
raw"""($intPattern)\.($intPattern)\.($intPattern)-RC($intPattern)""".r
private val MajorPattern = raw"""($intPattern)""".r
private val PartialVersion = raw"""($intPattern)\.($intPattern)""".r

def from(s: String): Try[ScalaVersion] = {
val version = s.split("-").head
def from(version: String): Try[ScalaVersion] = {
version match {
case RcVersion(major, minor, patch, rc) =>
MajorVersion.from(major.toLong).flatMap { major =>
Success(RC(major, minor.toInt, patch.toInt, rc.toInt))
}
case FullVersion(major, minor, patch) =>
MajorVersion.from(major.toLong).flatMap { major =>
Success(Patch(major, minor.toInt, patch.toInt))
Expand All @@ -113,7 +135,7 @@ object ScalaVersion {
}
case MajorPattern(major) =>
MajorVersion.from(major.toLong).flatMap(major => Success(Major(major)))
case _ => Failure(new Exception(s"$s not a valid Scala Version."))
case _ => Failure(new Exception(s"$version not a valid Scala Version."))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ScalaVersionSuite extends munit.FunSuite {

test("parse: 3.0.0-RC3") {
val scala2 = ScalaVersion.from("3.0.0-RC3")
assert(scala2.get == Patch(Major.Scala3, 0, 0))
assert(scala2.get == RC(Major.Scala3, 0, 0, 3))
}

test("parse failure: 3.0.0RC3") {
Expand Down