Browse Source

Add tests cases for Composable functions returning null value (#3953)

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
pull/3956/head v1.6.0-dev1282
Oleksandr Karpovich 1 year ago committed by GitHub
parent
commit
2ab6e97775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      compose/integrations/composable-test-cases/gradle.properties
  2. 18
      compose/integrations/composable-test-cases/testcases/lambdas/lib/src/commonMain/kotlin/Dependencies.kt
  3. 29
      compose/integrations/composable-test-cases/testcases/lambdas/main/src/commonTest/kotlin/Tests.kt

7
compose/integrations/composable-test-cases/gradle.properties

@ -1,12 +1,13 @@
org.gradle.jvmargs=-Xmx2048M -XX:MaxMetaspaceSize=512m
kotlin.code.style=official
android.useAndroidX=true
kotlin.version=1.9.20-RC
kotlin.version=1.9.20
agp.version=7.3.0
compose.version=1.5.10-rc01
compose.version=1.5.10
#empty by default - a default version will be used
compose.kotlinCompilerPluginVersion=1.5.2.1-rc01
#compose.kotlinCompilerPluginVersion=23.11.20
compose.kotlinCompilerPluginVersion=1.5.3
# default|failingJs - see enum class CasesToRun
tests.casesToRun=default

18
compose/integrations/composable-test-cases/testcases/lambdas/lib/src/commonMain/kotlin/Dependencies.kt

@ -1,4 +1,5 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.cache
import androidx.compose.runtime.currentComposer
import com.example.common.TextLeafNode
@ -12,3 +13,20 @@ fun ComposableSomeText(someText : () -> String) {
val composableInt: Int
@Composable
get() = currentComposer.cache(false) { 100 }
@Composable
fun ComposableAlwaysReturnsNull(): String? {
return null
}
@Composable
fun ComposableAlwaysReturnsNullUnit(): Unit? {
val u: Unit? = null
return u
}
@Composable
fun ComposableAlwaysReturnsUnit(): Unit? {
return Unit
}

29
compose/integrations/composable-test-cases/testcases/lambdas/main/src/commonTest/kotlin/Tests.kt

@ -113,6 +113,35 @@ class Tests {
}
assertEquals("root:{Value = 100}", root.dump())
}
@Test
fun testComposableAlwaysReturnsNull() {
val root = composeText {
val v = ComposableAlwaysReturnsNull()
TextLeafNode("Value = ${v ?: "null"}")
}
assertEquals("root:{Value = null}", root.dump())
}
@Test
fun testComposableAlwaysReturnsNullUnit() {
val root = composeText {
val v = ComposableAlwaysReturnsNullUnit()
TextLeafNode("Value = ${v ?: "null"}")
}
assertEquals("root:{Value = null}", root.dump())
}
@Test
fun testComposableAlwaysReturnsUnit() {
val root = composeText {
val v = ComposableAlwaysReturnsUnit().let {
if (it == Unit) "Unit" else it.toString()
}
TextLeafNode("Value = $v")
}
assertEquals("root:{Value = Unit}", root.dump())
}
}
private fun someText(): String {

Loading…
Cancel
Save