-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Decouple scala version checks from exact version list (#826)
- Loading branch information
Showing
4 changed files
with
39 additions
and
15 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
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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package com.sksamuel | ||
|
||
import scala.util.Try | ||
|
||
package object scapegoat { | ||
val scalaVersion: String = util.Properties.versionNumberString | ||
private val shortScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".") | ||
private val scalaVersion: String = util.Properties.versionNumberString | ||
private val (major, minor, patch) = extractComponents(scalaVersion) | ||
|
||
val isScala213: Boolean = major == 2 && minor == 13 | ||
val isScala21312OrLater: Boolean = isScala213 && patch >= 12 | ||
|
||
val isScala213: Boolean = shortScalaVersion == "2.13" | ||
val isScala21312: Boolean = scalaVersion == "2.13.12" | ||
private[scapegoat] def extractComponents(version: String) = { | ||
def parseInt(s: String) = Try(s.toInt).getOrElse(0) | ||
version.split('.').toList.map(parseInt) match { | ||
case List(major, minor, patch) => (major, minor, patch) | ||
case _ => (1, 0, 0) | ||
} | ||
} | ||
} |
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,14 @@ | ||
package com.sksamuel.scapegoat | ||
|
||
import com.sksamuel.scapegoat._ | ||
import org.scalatest.freespec.AnyFreeSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class ScapegoatTest extends AnyFreeSpec with Matchers { | ||
|
||
"ScalaVersionPattern" - { | ||
"shoud extract components" in { | ||
extractComponents("2.13.12") shouldBe (2, 13, 12) | ||
} | ||
} | ||
} |
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