-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: adjust testes for 3.2.0-NIGHTLY
Also, exnteded the `compat` inn tests cases. Now it's possible to specify matching version not only as starts with but as greater or equal. For example: ``` check( "input ... ", "default expected ...", compat = Map( ">=3.1.0" -> "expected for version gte than 3.1.0", "3" -> "any otherversion that starts from 3" ) ) ```
- Loading branch information
Showing
9 changed files
with
130 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 36 additions & 49 deletions
85
mtags/src/main/scala/scala/meta/internal/semver/SemVer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package tests | ||
|
||
import scala.meta.internal.semver.SemVer | ||
|
||
object Compat { | ||
|
||
/** | ||
* Cases might be described as: | ||
* - Starts swith: "3.0.1" -> value | "3.0" -> value | "3" | ||
* - Greater or equal: ">=3.0.0" -> value | ||
*/ | ||
def forScalaVersion[A]( | ||
scalaVersion: String, | ||
cases: Map[String, A] | ||
): Option[A] = { | ||
val (startsWith, gt) = | ||
cases.partition({ case (v, _) => !v.startsWith(">=") }) | ||
|
||
val fromStartWith = startsWith.collectFirst({ | ||
case (v, a) if scalaVersion.startsWith(v) => a | ||
}) | ||
matchesGte(scalaVersion, gt) orElse fromStartWith | ||
} | ||
|
||
private def matchesGte[A]( | ||
version: String, | ||
gtCases: Map[String, A] | ||
): Option[A] = { | ||
val parsed = SemVer.Version.fromString(version) | ||
val less = gtCases | ||
.map { case (v, a) => | ||
(SemVer.Version.fromString(v.stripPrefix(">=")), a) | ||
} | ||
.filter({ case (v, _) => parsed >= v }) | ||
|
||
less.toList.sortWith(_._1 < _._1).lastOption.map(_._2) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package tests | ||
|
||
import scala.meta.internal.semver.SemVer | ||
|
||
import munit.FunSuite | ||
|
||
class SemVerSuite extends FunSuite { | ||
|
||
val expected: List[(String, SemVer.Version)] = List( | ||
("3.0.0", SemVer.Version(3, 0, 0)), | ||
("3.0.0-M1", SemVer.Version(3, 0, 0, milestone = Some(1))), | ||
("3.0.0-RC1", SemVer.Version(3, 0, 0, releaseCandidate = Some(1))), | ||
( | ||
"3.2.0-RC1-bin-20220307-6dc591a-NIGHTLY", | ||
SemVer.Version( | ||
3, | ||
2, | ||
0, | ||
releaseCandidate = Some(1), | ||
nightlyDate = Some(20220307) | ||
) | ||
) | ||
) | ||
|
||
test("fromString") { | ||
val incorrect = expected | ||
.map { case (s, e) => (SemVer.Version.fromString(s), e) } | ||
.filter({ case (parsed, expected) => parsed != expected }) | ||
|
||
assert( | ||
incorrect.isEmpty, | ||
incorrect.mkString("Failed to parse versions(expected, got):", "\n", "") | ||
) | ||
} | ||
} |