Skip to content

Commit

Permalink
Merge pull request #2084 from bjaglin/support-rc
Browse files Browse the repository at this point in the history
improvement: Allow to use RC versions in arguments
  • Loading branch information
bjaglin authored Sep 27, 2024
2 parents 7f471d0 + 72ae371 commit 590db62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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

0 comments on commit 590db62

Please sign in to comment.