Skip to content

Commit

Permalink
Add tests cases for Composable functions returning null value (#3953)
Browse files Browse the repository at this point in the history
Co-authored-by: Oleksandr Karpovich <[email protected]>
  • Loading branch information
eymar and Oleksandr Karpovich authored Nov 20, 2023
1 parent 4a020e9 commit 2ab6e97
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compose/integrations/composable-test-cases/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2ab6e97

Please sign in to comment.