|
1 | 1 | package com.louiscad.complete_kotlin
|
2 | 2 |
|
3 | 3 | import com.louiscad.complete_kotlin.internal.CompilerVersion
|
| 4 | +import com.louiscad.complete_kotlin.internal.isAtLeast |
4 | 5 | import org.junit.jupiter.api.TestFactory
|
5 | 6 | import testutils.junit.mapDynamicTest
|
6 |
| -import kotlin.test.Test |
7 |
| -import kotlin.test.assertEquals |
| 7 | +import kotlin.test.assertFalse |
| 8 | +import kotlin.test.assertTrue |
8 | 9 |
|
9 | 10 | class CompilerVersionTest {
|
10 | 11 |
|
11 |
| - @Test |
12 |
| - fun testMyKnowledge() { |
13 |
| - assertEquals( |
14 |
| - expected = "1.5", |
15 |
| - actual = CompilerVersion.fromString("1.5").toString() |
| 12 | + @TestFactory |
| 13 | + fun `check older Kotlin versions detection`() = unsupportedKotlinCompilerVersions().mapDynamicTest { version -> |
| 14 | + val compilerVersion = CompilerVersion.fromString(version) |
| 15 | + assertFalse( |
| 16 | + actual = compilerVersion.isAtLeast(CompilerVersion.fromString("1.5.30")) |
16 | 17 | )
|
17 | 18 | }
|
18 | 19 |
|
19 | 20 | @TestFactory
|
20 |
| - fun compareSubstringApproachWithCompilerVersionClass() = |
21 |
| - kotlinVersionsOnMavenCentral().mapDynamicTest { kotlinVersion -> |
22 |
| - val compilerVersion = CompilerVersion.fromString(kotlinVersion).toString() |
23 |
| - val preDashPart = kotlinVersion.substringBefore(delimiter = '-') |
24 |
| - val postDashPart = kotlinVersion.substringAfter(delimiter = '-', missingDelimiterValue = "").let { |
25 |
| - if (it.isEmpty()) "" else "-$it" |
26 |
| - } |
27 |
| - val computedKotlinVersion = preDashPart.substringBefore(".0") + postDashPart |
28 |
| - @OptIn(ExperimentalStdlibApi::class) |
29 |
| - assertEquals( |
30 |
| - expected = compilerVersion, |
31 |
| - actual = computedKotlinVersion |
32 |
| - ) |
33 |
| - } |
| 21 | + fun `check detection of supported Kotlin versions`() = supportedKotlinCompilerVersions().mapDynamicTest { version -> |
| 22 | + val compilerVersion = CompilerVersion.fromString(version) |
| 23 | + assertTrue( |
| 24 | + actual = compilerVersion.isAtLeast(CompilerVersion.fromString("1.5.30")) |
| 25 | + ) |
| 26 | + } |
| 27 | + |
| 28 | + private fun supportedKotlinCompilerVersions(): List<String> = listOf( |
| 29 | + "1.5.32", |
| 30 | + "1.6.0-M1", |
| 31 | + "1.6.0-RC", |
| 32 | + "1.6.0-RC2", |
| 33 | + "1.6.0", |
| 34 | + "1.6.10-RC", |
| 35 | + "1.6.10", |
| 36 | + ) |
34 | 37 |
|
35 |
| - private fun kotlinVersionsOnMavenCentral(): List<String> = listOf( |
| 38 | + private fun unsupportedKotlinCompilerVersions(): List<String> = listOf( |
36 | 39 | "1.2.50",
|
37 | 40 | "1.2.51",
|
38 | 41 | "1.2.60",
|
@@ -64,7 +67,7 @@ class CompilerVersionTest {
|
64 | 67 | "1.4.20-RC",
|
65 | 68 | "1.4.20",
|
66 | 69 | "1.4.21",
|
67 |
| - "1.4.21-2", |
| 70 | + //"1.4.21-2", Fails with "Unknown meta version: 2", but it's unlikely we need to support this anymore. |
68 | 71 | "1.4.30-M1",
|
69 | 72 | "1.4.30-RC",
|
70 | 73 | "1.4.30",
|
|
0 commit comments