Igor Demin
10 months ago
3 changed files with 129 additions and 0 deletions
@ -0,0 +1,41 @@
|
||||
package org.jetbrains.compose |
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
||||
|
||||
internal object ComposeKotlinCompatibility { |
||||
fun checkKotlinIsSupported(kotlinVersion: String, kotlinPlatformType: KotlinPlatformType) { |
||||
val kotlinVersion = kotlinVersion.parseVersionOrNull() |
||||
|
||||
when(kotlinPlatformType) { |
||||
KotlinPlatformType.wasm -> check( |
||||
kotlinVersion == null || |
||||
kotlinVersion.major == 0 || |
||||
kotlinVersion > Version(1, 9, 21) |
||||
) { |
||||
"Compose Multiplatform ${ComposeBuildConfig.composeGradlePluginVersion} doesn't support Kotlin " + |
||||
"$kotlinVersion. Minimal supported version is 1.9.22" |
||||
} |
||||
else -> Unit |
||||
} |
||||
} |
||||
} |
||||
|
||||
// parse only simple numbers, as we need only them, not whole semantic versioning checks |
||||
private fun String.parseVersionOrNull(): Version? { |
||||
val parts = split(".") |
||||
return Version( |
||||
parts.getOrNull(0)?.toIntOrNull() ?: return null, |
||||
parts.getOrNull(1)?.toIntOrNull() ?: return null, |
||||
parts.getOrNull(2)?.toIntOrNull() ?: return null, |
||||
) |
||||
} |
||||
|
||||
private class Version(val major: Int, val minor: Int, val patch: Int) : Comparable<Version> { |
||||
override fun compareTo(other: Version) = compareValuesBy( |
||||
this, |
||||
other, |
||||
{ it.major }, |
||||
{ it.minor }, |
||||
{ it.patch }, |
||||
) |
||||
} |
@ -0,0 +1,79 @@
|
||||
package org.jetbrains.compose.test.tests.integration |
||||
|
||||
import org.jetbrains.compose.ComposeKotlinCompatibility |
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
||||
import org.junit.jupiter.api.Test |
||||
import org.junit.jupiter.api.assertThrows |
||||
|
||||
class KotlinCompatibilityUnitTest { |
||||
@Test |
||||
fun jvm() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.21", KotlinPlatformType.jvm) |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.22", KotlinPlatformType.jvm) |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta", KotlinPlatformType.jvm) |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta2", KotlinPlatformType.jvm) |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("fdsfsf", KotlinPlatformType.jvm) |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("fdsfsf", KotlinPlatformType.jvm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasm000() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.0", KotlinPlatformType.wasm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasmabc() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("abc", KotlinPlatformType.wasm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasm000something() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.0-something", KotlinPlatformType.wasm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasm0040() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.40", KotlinPlatformType.wasm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasm000SNAPSHOT() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.0-SNAPSHOT", KotlinPlatformType.wasm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasm1821() { |
||||
assertThrows<IllegalStateException> { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("1.8.21", KotlinPlatformType.wasm) |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
fun wasm1822() { |
||||
assertThrows<IllegalStateException> { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("1.8.22", KotlinPlatformType.wasm) |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
fun wasm1921() { |
||||
assertThrows<IllegalStateException> { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.21", KotlinPlatformType.wasm) |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
fun wasm1922() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.22", KotlinPlatformType.wasm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasm200Beta() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta", KotlinPlatformType.wasm) |
||||
} |
||||
|
||||
@Test |
||||
fun wasm200Beta1() { |
||||
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta1", KotlinPlatformType.wasm) |
||||
} |
||||
} |
Loading…
Reference in new issue