Skip to content

Commit

Permalink
Test nullable burstValues
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Oct 30, 2024
1 parent fcf0fdc commit bf17478
Showing 1 changed file with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ class BurstKotlinPluginTest {
"CoffeeTest.kt",
"""
import app.cash.burst.Burst
import app.cash.burst.burstValues
import kotlin.test.Test
@Burst
Expand Down Expand Up @@ -761,6 +760,46 @@ class BurstKotlinPluginTest {
)
}

@Test
fun nullableBurstValuesNotDefault() {
val result = compile(
sourceFile = SourceFile.kotlin(
"CoffeeTest.kt",
"""
import app.cash.burst.Burst
import app.cash.burst.burstValues
import kotlin.test.Test
@Burst
class CoffeeTest {
val log = mutableListOf<String>()
@Test
fun test(volume: Int? = burstValues(12, 16, 20, null)) {
log += "running ${'$'}volume"
}
}
""",
),
)
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages)

val baseClass = result.classLoader.loadClass("CoffeeTest")
val baseInstance = baseClass.constructors.single().newInstance()
val baseLog = baseClass.getMethod("getLog").invoke(baseInstance) as MutableList<*>

baseClass.getMethod("test").invoke(baseInstance)
baseClass.getMethod("test_16").invoke(baseInstance)
baseClass.getMethod("test_20").invoke(baseInstance)
baseClass.getMethod("test_null").invoke(baseInstance)
assertThat(baseLog).containsExactly(
"running 12",
"running 16",
"running 20",
"running null",
)
}

@Test
fun nullableEnumAsDefault() {
val result = compile(
Expand Down Expand Up @@ -841,6 +880,46 @@ class BurstKotlinPluginTest {
)
}

@Test
fun nullableBurstValuesAsDefault() {
val result = compile(
sourceFile = SourceFile.kotlin(
"CoffeeTest.kt",
"""
import app.cash.burst.Burst
import app.cash.burst.burstValues
import kotlin.test.Test
@Burst
class CoffeeTest {
val log = mutableListOf<String>()
@Test
fun test(volume: Int? = burstValues(null, 12, 16, 20)) {
log += "running ${'$'}volume"
}
}
""",
),
)
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages)

val baseClass = result.classLoader.loadClass("CoffeeTest")
val baseInstance = baseClass.constructors.single().newInstance()
val baseLog = baseClass.getMethod("getLog").invoke(baseInstance) as MutableList<*>

baseClass.getMethod("test_12").invoke(baseInstance)
baseClass.getMethod("test_16").invoke(baseInstance)
baseClass.getMethod("test_20").invoke(baseInstance)
baseClass.getMethod("test").invoke(baseInstance)
assertThat(baseLog).containsExactly(
"running 12",
"running 16",
"running 20",
"running null",
)
}

private val Class<*>.testSuffixes: List<String>
get() = methods.mapNotNull {
when {
Expand Down

0 comments on commit bf17478

Please sign in to comment.