From 2ab6e97775abc7bda32bdaa6630b70f1ff211947 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpovich Date: Mon, 20 Nov 2023 13:59:10 +0100 Subject: [PATCH] Add tests cases for Composable functions returning null value (#3953) Co-authored-by: Oleksandr Karpovich --- .../composable-test-cases/gradle.properties | 7 +++-- .../lib/src/commonMain/kotlin/Dependencies.kt | 18 ++++++++++++ .../main/src/commonTest/kotlin/Tests.kt | 29 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/compose/integrations/composable-test-cases/gradle.properties b/compose/integrations/composable-test-cases/gradle.properties index f563fbc462..dad43d287f 100644 --- a/compose/integrations/composable-test-cases/gradle.properties +++ b/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 diff --git a/compose/integrations/composable-test-cases/testcases/lambdas/lib/src/commonMain/kotlin/Dependencies.kt b/compose/integrations/composable-test-cases/testcases/lambdas/lib/src/commonMain/kotlin/Dependencies.kt index cd8e8d2136..50d3313e2c 100644 --- a/compose/integrations/composable-test-cases/testcases/lambdas/lib/src/commonMain/kotlin/Dependencies.kt +++ b/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 +} \ No newline at end of file diff --git a/compose/integrations/composable-test-cases/testcases/lambdas/main/src/commonTest/kotlin/Tests.kt b/compose/integrations/composable-test-cases/testcases/lambdas/main/src/commonTest/kotlin/Tests.kt index b7002a1999..a8a9eb71c9 100644 --- a/compose/integrations/composable-test-cases/testcases/lambdas/main/src/commonTest/kotlin/Tests.kt +++ b/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 {