Forbid handling dashed in KotlinToolingVersion parsing

This commit is contained in:
Nikolay Krasko
2022-09-07 11:34:26 +02:00
committed by Space
parent ff04918125
commit 496058c7e1
2 changed files with 15 additions and 6 deletions
@@ -50,10 +50,10 @@ class KotlinToolingVersion(
when { when {
classifier == null || classifier.matches(Regex("""(release-)?\d+""")) -> Maturity.STABLE classifier == null || classifier.matches(Regex("""(release-)?\d+""")) -> Maturity.STABLE
classifier == "snapshot" -> Maturity.SNAPSHOT classifier == "snapshot" -> Maturity.SNAPSHOT
classifier.matches(Regex("""(rc)(\d*)?(-release)?-?\d*""")) -> Maturity.RC classifier.matches(Regex("""(rc)(\d*)?(-release)?(-?\d+)?""")) -> Maturity.RC
classifier.matches(Regex("""beta(\d*)?(-release)?-?\d*""")) -> Maturity.BETA classifier.matches(Regex("""beta(\d*)?(-release)?(-?\d+)?""")) -> Maturity.BETA
classifier.matches(Regex("""alpha(\d*)?(-release)?-?\d*""")) -> Maturity.ALPHA classifier.matches(Regex("""alpha(\d*)?(-release)?(-?\d+)?""")) -> Maturity.ALPHA
classifier.matches(Regex("""m\d+(-release)?(-\d*)?""")) -> Maturity.MILESTONE classifier.matches(Regex("""m\d+(-release)?(-\d+)?""")) -> Maturity.MILESTONE
classifier.matches(Regex("""([a-zA-Z]{3,})(-[a-zA-Z]\w*)*(-\d+)?""")) -> Maturity.DEV classifier.matches(Regex("""([a-zA-Z]{3,})(-[a-zA-Z]\w*)*(-\d+)?""")) -> Maturity.DEV
else -> throw IllegalArgumentException("Can't infer maturity of KotlinVersion $this") else -> throw IllegalArgumentException("Can't infer maturity of KotlinVersion $this")
} }
@@ -178,17 +178,26 @@ class KotlinToolingVersionTest {
@Test @Test
fun maturityWithAdditionalReleaseSuffix() { fun maturityWithAdditionalReleaseSuffix() {
assertMaturity(MILESTONE, "1.6.20-M1-release") assertMaturity(MILESTONE, "1.6.20-M1-release")
assertMaturity(null, "1.6.20-M1-release1")
assertMaturity(MILESTONE, "1.6.20-M1-release-22") assertMaturity(MILESTONE, "1.6.20-M1-release-22")
assertMaturity(null, "1.6.20-M1-release-", "Forbid handling dash")
assertMaturity(ALPHA, "1.6.20-alpha-release") assertMaturity(ALPHA, "1.6.20-alpha-release")
assertMaturity(ALPHA, "1.6.20-alpha-release1")
assertMaturity(ALPHA, "1.6.20-alpha-release39") assertMaturity(ALPHA, "1.6.20-alpha-release39")
assertMaturity(null, "1.6.20-alpha-release-", "Forbid handling dash")
assertMaturity(BETA, "1.6.20-beta2-release") assertMaturity(BETA, "1.6.20-beta2-release")
assertMaturity(BETA, "1.6.20-beta2-release1")
assertMaturity(BETA, "1.6.20-beta2-release-1")
assertMaturity(null, "1.6.20-beta2-release-", "Forbid handling dash")
assertMaturity(RC, "1.6.20-rc1-release") assertMaturity(RC, "1.6.20-rc1-release")
assertMaturity(RC, "1.6.20-rc1-release1")
assertMaturity(RC, "1.6.20-rc1-release-1")
assertMaturity(null, "1.6.20-rc1-release-", "Forbid handling dash")
} }
@Test @Test
fun invalidMilestoneVersion() { fun invalidMilestoneVersion() {
val exception = assertFailsWith<IllegalArgumentException> { KotlinToolingVersion("1.6.20-M") } assertMaturity(null, "1.6.20-M")
assertTrue("maturity" in exception.message.orEmpty().toLowerCase(), "Expected 'maturity' issue mentioned in error message")
} }
@Test @Test