diff --git a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala index cebe00ac5..b9d4cc2dd 100644 --- a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala +++ b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala @@ -13,79 +13,81 @@ object CrossVersionUtil { val TransitionSbtVersion = "0.12" def isFull(s: String): Boolean = (s == trueString) || (s == fullString) + def isDisabled(s: String): Boolean = (s == falseString) || (s == noneString) || (s == disabledString) + def isBinary(s: String): Boolean = (s == binaryString) - private lazy val intPattern = """\d{1,10}""" - private lazy val basicVersion = """(""" + intPattern + """)\.(""" + intPattern + """)\.(""" + intPattern + """)""" + private val longPattern = """\d{1,19}""" + private val basicVersion = raw"""($longPattern)\.($longPattern)\.($longPattern)""" + private val ReleaseV = raw"""$basicVersion(-\d+)?""".r + private val BinCompatV = raw"""$basicVersion-bin(-.*)?""".r + private val CandidateV = raw"""$basicVersion(-RC\d+)""".r + private val NonReleaseV_n = raw"""$basicVersion([-\w]*)""".r // 0-n word suffixes, with leading dashes + private val NonReleaseV_1 = raw"""$basicVersion(-\w+)""".r // 1 word suffix, after a dash + private[sbt] val PartialVersion = raw"""($longPattern)\.($longPattern)(?:\..+)?""".r private[sbt] def isSbtApiCompatible(v: String): Boolean = sbtApiVersion(v).isDefined /** * Returns sbt binary interface x.y API compatible with the given version string v. * RCs for x.y.0 are considered API compatible. - * Compatibile versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). + * Compatible versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). */ - private[sbt] def sbtApiVersion(v: String): Option[(Int, Int)] = { - val ReleaseV = (basicVersion + """(-\d+)?""").r - val CandidateV = (basicVersion + """(-RC\d+)""").r - val NonReleaseV = (basicVersion + """([-\w+]*)""").r - v match { - case ReleaseV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case CandidateV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case NonReleaseV(x, y, z, ht) if z.toInt > 0 => Some((x.toInt, y.toInt)) - case _ => None - } + private[sbt] def sbtApiVersion(v: String): Option[(Long, Long)] = v match { + case ReleaseV(x, y, _, _) => Some(sbtApiVersion(x.toLong, y.toLong)) + case CandidateV(x, y, _, _) => Some(sbtApiVersion(x.toLong, y.toLong)) + case NonReleaseV_n(x, y, z, _) if z.toInt > 0 => Some(sbtApiVersion(x.toLong, y.toLong)) + case _ => None } + + private def sbtApiVersion(x: Long, y: Long) = { + // Prior to sbt 1 the "sbt api version" was the X.Y in the X.Y.Z version. + // For example for sbt 0.13.x releases, the sbt api version is 0.13 + // As of sbt 1 it is now X.0. + // This means, for example, that all versions of sbt 1.x have sbt api version 1.0 + if (x > 0) (x, 0L) else (x, y) + } + private[sbt] def isScalaApiCompatible(v: String): Boolean = scalaApiVersion(v).isDefined /** * Returns Scala binary interface x.y API compatible with the given version string v. - * Compatibile versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. + * Compatible versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. */ - private[sbt] def scalaApiVersion(v: String): Option[(Int, Int)] = { - val ReleaseV = (basicVersion + """(-\d+)?""").r - val BinCompatV = (basicVersion + """-bin(-.*)?""").r - val NonReleaseV = (basicVersion + """(-\w+)""").r - v match { - case ReleaseV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case BinCompatV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case NonReleaseV(x, y, z, ht) if z.toInt > 0 => Some((x.toInt, y.toInt)) - case _ => None - } + private[sbt] def scalaApiVersion(v: String): Option[(Long, Long)] = v match { + case ReleaseV(x, y, _, _) => Some((x.toLong, y.toLong)) + case BinCompatV(x, y, _, _) => Some((x.toLong, y.toLong)) + case NonReleaseV_1(x, y, z, _) if z.toInt > 0 => Some((x.toLong, y.toLong)) + case _ => None } - private[sbt] val PartialVersion = - ("""(""" + intPattern + """)\.(""" + intPattern + """)(?:\..+)?""").r - private[sbt] def partialVersion(s: String): Option[(Int, Int)] = + + private[sbt] def partialVersion(s: String): Option[(Long, Long)] = s match { - case PartialVersion(major, minor) => Some((major.toInt, minor.toInt)) + case PartialVersion(major, minor) => Some((major.toLong, minor.toLong)) case _ => None } - def binaryScalaVersion(full: String): String = { - val cutoff = - if (full.startsWith("0.")) - TransitionDottyVersion - else - TransitionScalaVersion + def binaryScalaVersion(full: String): String = { + val cutoff = if (full.startsWith("0.")) TransitionDottyVersion else TransitionScalaVersion binaryVersionWithApi(full, cutoff)(scalaApiVersion) } + def binarySbtVersion(full: String): String = binaryVersionWithApi(full, TransitionSbtVersion)(sbtApiVersion) - private[sbt] def binaryVersion(full: String, cutoff: String): String = - binaryVersionWithApi(full, cutoff)(scalaApiVersion) - private[this] def isNewer(major: Int, minor: Int, minMajor: Int, minMinor: Int): Boolean = + + private[this] def isNewer(major: Long, minor: Long, minMajor: Long, minMinor: Long): Boolean = major > minMajor || (major == minMajor && minor >= minMinor) + private[this] def binaryVersionWithApi(full: String, cutoff: String)( - apiVersion: String => Option[(Int, Int)] + apiVersion: String => Option[(Long, Long)] ): String = { - def sub(major: Int, minor: Int) = major + "." + minor (apiVersion(full), partialVersion(cutoff)) match { - case (Some((major, minor)), None) => sub(major, minor) + case (Some((major, minor)), None) => s"$major.$minor" case (Some((major, minor)), Some((minMajor, minMinor))) if isNewer(major, minor, minMajor, minMinor) => - sub(major, minor) + s"$major.$minor" case _ => full } } diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala index 29ef28327..c7e8fecc8 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala @@ -76,8 +76,8 @@ abstract class CrossVersionFunctions { cross: Option[String => String] ): Vector[Artifact] = cross match { - case None => artifacts - case Some(is) => substituteCrossA(artifacts, cross) + case None => artifacts + case Some(_) => substituteCrossA(artifacts, cross) } private[sbt] def applyCross(s: String, fopt: Option[String => String]): String = @@ -124,34 +124,28 @@ abstract class CrossVersionFunctions { m } - @deprecated("Use CrossVersion.isScalaApiCompatible or CrossVersion.isSbtApiCompatible", "0.13.0") - def isStable(v: String): Boolean = isScalaApiCompatible(v) - - @deprecated("Use CrossVersion.scalaApiVersion or CrossVersion.sbtApiVersion", "0.13.0") - def selectVersion(full: String, binary: String): String = if (isStable(full)) binary else full - def isSbtApiCompatible(v: String): Boolean = CrossVersionUtil.isSbtApiCompatible(v) /** * Returns sbt binary interface x.y API compatible with the given version string v. * RCs for x.y.0 are considered API compatible. - * Compatibile versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). + * Compatible versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). */ - def sbtApiVersion(v: String): Option[(Int, Int)] = CrossVersionUtil.sbtApiVersion(v) + def sbtApiVersion(v: String): Option[(Long, Long)] = CrossVersionUtil.sbtApiVersion(v) def isScalaApiCompatible(v: String): Boolean = CrossVersionUtil.isScalaApiCompatible(v) /** * Returns Scala binary interface x.y API compatible with the given version string v. - * Compatibile versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. + * Compatible versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. */ - def scalaApiVersion(v: String): Option[(Int, Int)] = CrossVersionUtil.scalaApiVersion(v) + def scalaApiVersion(v: String): Option[(Long, Long)] = CrossVersionUtil.scalaApiVersion(v) /** Regular expression that extracts the major and minor components of a version into matched groups 1 and 2.*/ val PartialVersion = CrossVersionUtil.PartialVersion /** Extracts the major and minor components of a version string `s` or returns `None` if the version is improperly formatted. */ - def partialVersion(s: String): Option[(Int, Int)] = CrossVersionUtil.partialVersion(s) + def partialVersion(s: String): Option[(Long, Long)] = CrossVersionUtil.partialVersion(s) /** * Computes the binary Scala version from the `full` version. @@ -164,9 +158,4 @@ abstract class CrossVersionFunctions { * Full sbt versions earlier than [[sbt.librarymanagement.CrossVersion.TransitionSbtVersion]] are returned as is. */ def binarySbtVersion(full: String): String = CrossVersionUtil.binarySbtVersion(full) - - @deprecated("Use CrossVersion.scalaApiVersion or CrossVersion.sbtApiVersion", "0.13.0") - def binaryVersion(full: String, cutoff: String): String = - CrossVersionUtil.binaryVersion(full, cutoff) - } diff --git a/librarymanagement/src/test/scala/CrossVersionTest.scala b/librarymanagement/src/test/scala/CrossVersionTest.scala index 835ad1058..b65c9a11b 100644 --- a/librarymanagement/src/test/scala/CrossVersionTest.scala +++ b/librarymanagement/src/test/scala/CrossVersionTest.scala @@ -1,156 +1,242 @@ package sbt.librarymanagement import sbt.internal.util.UnitSpec +import CrossVersion._ class CrossVersionTest extends UnitSpec { - "Cross version" should "return sbt API for xyz as None" in { - CrossVersion.sbtApiVersion("xyz") shouldBe None + "sbtApiVersion" should "for xyz return None" in { + sbtApiVersion("xyz") shouldBe None } - it should "return sbt API for 0.12 as None" in { - CrossVersion.sbtApiVersion("0.12") shouldBe None + it should "for 0.12 return None" in { + sbtApiVersion("0.12") shouldBe None } - it should "return sbt API for 0.12.0-SNAPSHOT as None" in { - CrossVersion.sbtApiVersion("0.12.0-SNAPSHOT") shouldBe None + it should "for 0.12.0-SNAPSHOT return None" in { + sbtApiVersion("0.12.0-SNAPSHOT") shouldBe None } - it should "return sbt API for 0.12.0-RC1 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.0-RC1") shouldBe Some((0, 12)) + it should "for 0.12.0-RC1 return Some((0, 12))" in { + sbtApiVersion("0.12.0-RC1") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.0 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.0") shouldBe Some((0, 12)) + it should "for 0.12.0 return Some((0, 12))" in { + sbtApiVersion("0.12.0") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.1-SNAPSHOT as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.1-SNAPSHOT") shouldBe Some((0, 12)) + it should "for 0.12.1-SNAPSHOT return Some((0, 12))" in { + sbtApiVersion("0.12.1-SNAPSHOT") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.1-RC1 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.1-RC1") shouldBe Some((0, 12)) + it should "for 0.12.1-RC1 return Some((0, 12))" in { + sbtApiVersion("0.12.1-RC1") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.1 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.1") shouldBe Some((0, 12)) + it should "for 0.12.1 return Some((0, 12))" in { + sbtApiVersion("0.12.1") shouldBe Some((0, 12)) } - it should "return sbt API compatibility for 0.12.0-M1 as false" in { - CrossVersion.isSbtApiCompatible("0.12.0-M1") shouldBe false + it should "for 1.0.0-M6 return None" in { + sbtApiVersion("1.0.0-M6") shouldBe None } - it should "return sbt API compatibility for 0.12.0-RC1 as true" in { - CrossVersion.isSbtApiCompatible("0.12.0-RC1") shouldBe true + it should "for 1.0.0-RC1 return Some((1, 0))" in { + sbtApiVersion("1.0.0-RC1") shouldBe Some((1, 0)) } - it should "return sbt API compatibility for 0.12.1-RC1 as true" in { - CrossVersion.isSbtApiCompatible("0.12.1-RC1") shouldBe true + it should "for 1.0.0 return Some((1, 0))" in { + sbtApiVersion("1.0.0") shouldBe Some((1, 0)) } - it should "return binary sbt version for 0.11.3 as 0.11.3" in { - CrossVersion.binarySbtVersion("0.11.3") shouldBe "0.11.3" + it should "for 1.0.2-M1 return Some((1, 0))" in { + sbtApiVersion("1.0.2-M1") shouldBe Some((1, 0)) } - it should "return binary sbt version for 0.12.0-M1 as 0.12.0-M1" in { - CrossVersion.binarySbtVersion("0.12.0-M1") shouldBe "0.12.0-M1" + it should "for 1.0.2-RC1 return Some((1, 0))" in { + sbtApiVersion("1.0.2-RC1") shouldBe Some((1, 0)) } - it should "return binary sbt version for 0.12.0-RC1 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.0-RC1") shouldBe "0.12" + it should "for 1.0.2 return Some((1, 0))" in { + sbtApiVersion("1.0.2") shouldBe Some((1, 0)) } - it should "return binary sbt version for 0.12.0 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.0") shouldBe "0.12" + it should "for 1.3.0 return Some((1, 0))" in { + sbtApiVersion("1.3.0") shouldBe Some((1, 0)) } - it should "return binary sbt version for 0.12.1-SNAPSHOT as 0.12" in { - CrossVersion.binarySbtVersion("0.12.1-SNAPSHOT") shouldBe "0.12" + it should "for 1.10.0 return Some((1, 0))" in { + sbtApiVersion("1.10.0") shouldBe Some((1, 0)) } - it should "return binary sbt version for 0.12.1-RC1 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.1-RC1") shouldBe "0.12" + it should "for 2.0.0 return Some((2, 0))" in { + sbtApiVersion("2.0.0") shouldBe Some((2, 0)) } - it should "return binary sbt version for 0.12.1 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.1") shouldBe "0.12" + + "isSbtApiCompatible" should "for 0.12.0-M1 return false" in { + isSbtApiCompatible("0.12.0-M1") shouldBe false } - it should "return Scala API for xyz as None" in { - CrossVersion.scalaApiVersion("xyz") shouldBe None + it should "for 0.12.0-RC1 return true" in { + isSbtApiCompatible("0.12.0-RC1") shouldBe true } - it should "return Scala API for 2.10 as None" in { - CrossVersion.scalaApiVersion("2.10") shouldBe None + it should "for 0.12.1-RC1 return true" in { + isSbtApiCompatible("0.12.1-RC1") shouldBe true } - it should "return Scala API for 2.10.0-SNAPSHOT as None" in { - CrossVersion.scalaApiVersion("2.10.0-SNAPSHOT") shouldBe None + it should "for 1.0.0-M6 return false" in { + isSbtApiCompatible("1.0.0-M6") shouldBe false } - it should "return Scala API for 2.10.0-RC1 as None" in { - CrossVersion.scalaApiVersion("2.10.0-RC1") shouldBe None + it should "for 1.0.0-RC1 return true" in { + isSbtApiCompatible("1.0.0-RC1") shouldBe true } - it should "return Scala API for 2.10.0 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.0") shouldBe Some((2, 10)) + it should "for 1.0.0 return true" in { + isSbtApiCompatible("1.0.0") shouldBe true } - it should "return Scala API for 2.10.0-1 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.0-1") shouldBe Some((2, 10)) + it should "for 1.0.2-M1 return true" in { + isSbtApiCompatible("1.0.2-M1") shouldBe true } - it should "return Scala API for 2.10.1-SNAPSHOT as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.1-SNAPSHOT") shouldBe Some((2, 10)) + it should "for 1.0.2-RC1 return true" in { + isSbtApiCompatible("1.0.2-RC1") shouldBe true } - it should "return Scala API for 2.10.1-RC1 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.1-RC1") shouldBe Some((2, 10)) + it should "for 1.0.2 return true" in { + isSbtApiCompatible("1.0.2") shouldBe true } - it should "return Scala API for 2.10.1 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.1") shouldBe Some((2, 10)) + it should "for 1.3.0 return true" in { + isSbtApiCompatible("1.3.0") shouldBe true } - it should "return Scala API compatibility for 2.10.0-M1 as false" in { - CrossVersion.isScalaApiCompatible("2.10.0-M1") shouldBe false + it should "for 1.10.0 return true" in { + isSbtApiCompatible("1.10.0") shouldBe true } - it should "return Scala API compatibility for 2.10.0-RC1 as false" in { - CrossVersion.isScalaApiCompatible("2.10.0-RC1") shouldBe false + it should "for 2.0.0 return true" in { + isSbtApiCompatible("2.0.0") shouldBe true } - it should "return Scala API compatibility for 2.10.1-RC1 as false" in { - CrossVersion.isScalaApiCompatible("2.10.1-RC1") shouldBe true + + "binarySbtVersion" should "for 0.11.3 return 0.11.3" in { + binarySbtVersion("0.11.3") shouldBe "0.11.3" } - it should "return binary Scala version for 2.9.2 as 2.9.2" in { - CrossVersion.binaryScalaVersion("2.9.2") shouldBe "2.9.2" + it should "for 0.12.0-M1 return 0.12.0-M1" in { + binarySbtVersion("0.12.0-M1") shouldBe "0.12.0-M1" } - it should "return binary Scala version for 2.10.0-M1 as 2.10.0-M1" in { - CrossVersion.binaryScalaVersion("2.10.0-M1") shouldBe "2.10.0-M1" + it should "for 0.12.0-RC1 return 0.12" in { + binarySbtVersion("0.12.0-RC1") shouldBe "0.12" } - it should "return binary Scala version for 2.10.0-RC1 as 2.10.0-RC1" in { - CrossVersion.binaryScalaVersion("2.10.0-RC1") shouldBe "2.10.0-RC1" + it should "for 0.12.0 return 0.12" in { + binarySbtVersion("0.12.0") shouldBe "0.12" } - it should "return binary Scala version for 2.10.0 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.0") shouldBe "2.10" + it should "for 0.12.1-SNAPSHOT return 0.12" in { + binarySbtVersion("0.12.1-SNAPSHOT") shouldBe "0.12" } - it should "return binary Scala version for 2.10.1-M1 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.1-M1") shouldBe "2.10" + it should "for 0.12.1-RC1 return 0.12" in { + binarySbtVersion("0.12.1-RC1") shouldBe "0.12" } - it should "return binary Scala version for 2.10.1-RC1 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.1-RC1") shouldBe "2.10" + it should "for 0.12.1 return 0.12" in { + binarySbtVersion("0.12.1") shouldBe "0.12" } - it should "return binary Scala version for 2.10.1 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.1") shouldBe "2.10" + it should "for 1.0.0-M6 return 1.0.0-M6" in { + binarySbtVersion("1.0.0-M6") shouldBe "1.0.0-M6" } - it should "return binary Scala version for 2.20170314093845.0-87654321 as 2.20170314093845.0-87654321" in { - CrossVersion.binaryScalaVersion("2.20170314093845.0-87654321") shouldBe "2.20170314093845.0-87654321" + it should "for 1.0.0-RC1 return 1.0" in { + binarySbtVersion("1.0.0-RC1") shouldBe "1.0" } - it should "return binary Scala version for Dotty 0.1.1 as 0.1" in { - CrossVersion.binaryScalaVersion("0.1.1") shouldBe "0.1" + it should "for 1.0.0 return 1.0" in { + binarySbtVersion("1.0.0") shouldBe "1.0" } - it should "return patch Scala version for 2.11.8 as 2.11.8" in { - CrossVersion(CrossVersion.patch, "2.11.8", "dummy").map(_("artefact")) shouldBe Some( - "artefact_2.11.8") + it should "for 1.0.2-M1 return 1.0" in { + binarySbtVersion("1.0.2-M1") shouldBe "1.0" } - it should "return patch Scala version for 2.11.8-M1 as 2.11.8-M1" in { - CrossVersion(CrossVersion.patch, "2.11.8-M1", "dummy").map(_("artefact")) shouldBe Some( - "artefact_2.11.8-M1") + it should "for 1.0.2-RC1 return 1.0" in { + binarySbtVersion("1.0.2-RC1") shouldBe "1.0" } - it should "return patch Scala version for 2.11.8-RC1 as 2.11.8-RC1" in { - CrossVersion(CrossVersion.patch, "2.11.8-RC1", "dummy").map(_("artefact")) shouldBe Some( - "artefact_2.11.8-RC1") + it should "for 1.0.2 return 1.0" in { + binarySbtVersion("1.0.2") shouldBe "1.0" } - it should "return patch Scala version for 2.11.8-bin-extra as 2.11.8" in { - CrossVersion(CrossVersion.patch, "2.11.8-bin-extra", "dummy").map(_("artefact")) shouldBe Some( - "artefact_2.11.8") + it should "for 1.3.0 return 1.0" in { + binarySbtVersion("1.3.0") shouldBe "1.0" } - it should "return patch Scala version for 2.11.8-M1-bin-extra as 2.11.8-M1" in { - CrossVersion(CrossVersion.patch, "2.11.8-M1-bin-extra", "dummy") - .map(_("artefact")) shouldBe Some("artefact_2.11.8-M1") + it should "for 1.10.0 return 1.0" in { + binarySbtVersion("1.10.0") shouldBe "1.0" } - it should "return patch Scala version for 2.11.8-RC1-bin-extra as 2.11.8-RC1" in { - CrossVersion(CrossVersion.patch, "2.11.8-RC1-bin-extra", "dummy") - .map(_("artefact")) shouldBe Some("artefact_2.11.8-RC1") + it should "for 2.0.0 return 2.0" in { + binarySbtVersion("2.0.0") shouldBe "2.0" } - it should "return disabled cross version as equal to a copy" in { + + "scalaApiVersion" should "for xyz return None" in { + scalaApiVersion("xyz") shouldBe None + } + it should "for 2.10 return None" in { + scalaApiVersion("2.10") shouldBe None + } + it should "for 2.10.0-SNAPSHOT return None" in { + scalaApiVersion("2.10.0-SNAPSHOT") shouldBe None + } + it should "for 2.10.0-RC1 return None" in { + scalaApiVersion("2.10.0-RC1") shouldBe None + } + it should "for 2.10.0 return Some((2, 10))" in { + scalaApiVersion("2.10.0") shouldBe Some((2, 10)) + } + it should "for 2.10.0-1 return Some((2, 10))" in { + scalaApiVersion("2.10.0-1") shouldBe Some((2, 10)) + } + it should "for 2.10.1-SNAPSHOT return Some((2, 10))" in { + scalaApiVersion("2.10.1-SNAPSHOT") shouldBe Some((2, 10)) + } + it should "for 2.10.1-RC1 return Some((2, 10))" in { + scalaApiVersion("2.10.1-RC1") shouldBe Some((2, 10)) + } + it should "for 2.10.1 return Some((2, 10))" in { + scalaApiVersion("2.10.1") shouldBe Some((2, 10)) + } + + "isScalaApiCompatible" should "for 2.10.0-M1 return false" in { + isScalaApiCompatible("2.10.0-M1") shouldBe false + } + it should "for 2.10.0-RC1 return false" in { + isScalaApiCompatible("2.10.0-RC1") shouldBe false + } + it should "for 2.10.1-RC1 return false" in { + isScalaApiCompatible("2.10.1-RC1") shouldBe true + } + + "binaryScalaVersion" should "for 2.9.2 return 2.9.2" in { + binaryScalaVersion("2.9.2") shouldBe "2.9.2" + } + it should "for 2.10.0-M1 return 2.10.0-M1" in { + binaryScalaVersion("2.10.0-M1") shouldBe "2.10.0-M1" + } + it should "for 2.10.0-RC1 return 2.10.0-RC1" in { + binaryScalaVersion("2.10.0-RC1") shouldBe "2.10.0-RC1" + } + it should "for 2.10.0 return 2.10" in { + binaryScalaVersion("2.10.0") shouldBe "2.10" + } + it should "for 2.10.1-M1 return 2.10" in { + binaryScalaVersion("2.10.1-M1") shouldBe "2.10" + } + it should "for 2.10.1-RC1 return 2.10" in { + binaryScalaVersion("2.10.1-RC1") shouldBe "2.10" + } + it should "for 2.10.1 return 2.10" in { + binaryScalaVersion("2.10.1") shouldBe "2.10" + } + it should "for 2.20170314093845.0-87654321 return 2.20170314093845" in { + binaryScalaVersion("2.20170314093845.0-87654321") shouldBe "2.20170314093845" + } + it should "for Dotty 0.1.1 return 0.1" in { + binaryScalaVersion("0.1.1") shouldBe "0.1" + } + + private def patchVersion(fullVersion: String) = + CrossVersion(CrossVersion.patch, fullVersion, "dummy") map (fn => fn("artefact")) + + "CrossVersion.patch" should "for 2.11.8 return 2.11.8" in { + patchVersion("2.11.8") shouldBe Some("artefact_2.11.8") + } + it should "for 2.11.8-M1 return 2.11.8-M1" in { + patchVersion("2.11.8-M1") shouldBe Some("artefact_2.11.8-M1") + } + it should "for 2.11.8-RC1 return 2.11.8-RC1" in { + patchVersion("2.11.8-RC1") shouldBe Some("artefact_2.11.8-RC1") + } + it should "for 2.11.8-bin-extra return 2.11.8" in { + patchVersion("2.11.8-bin-extra") shouldBe Some("artefact_2.11.8") + } + it should "for 2.11.8-M1-bin-extra return 2.11.8-M1" in { + patchVersion("2.11.8-M1-bin-extra") shouldBe Some("artefact_2.11.8-M1") + } + it should "for 2.11.8-RC1-bin-extra return 2.11.8-RC1" in { + patchVersion("2.11.8-RC1-bin-extra") shouldBe Some("artefact_2.11.8-RC1") + } + + "Disabled" should "have structural equality" in { Disabled() shouldBe Disabled() } - it should "return full cross version as equal to a copy" in { + "CrossVersion.full" should "have structural equality" in { CrossVersion.full shouldBe CrossVersion.full } - it should "return binary cross version as equal to a copy" in { + "CrossVersion.binary" should "have structural equality" in { CrossVersion.binary shouldBe CrossVersion.binary } }