diff --git a/burst-kotlin-plugin-tests/src/test/kotlin/app/cash/burst/kotlin/BurstKotlinPluginTest.kt b/burst-kotlin-plugin-tests/src/test/kotlin/app/cash/burst/kotlin/BurstKotlinPluginTest.kt index e2efeb7..e29349e 100644 --- a/burst-kotlin-plugin-tests/src/test/kotlin/app/cash/burst/kotlin/BurstKotlinPluginTest.kt +++ b/burst-kotlin-plugin-tests/src/test/kotlin/app/cash/burst/kotlin/BurstKotlinPluginTest.kt @@ -643,7 +643,6 @@ class BurstKotlinPluginTest { "CoffeeTest.kt", """ import app.cash.burst.Burst - import app.cash.burst.burstValues import kotlin.test.Test @Burst @@ -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() + + @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( @@ -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() + + @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 get() = methods.mapNotNull { when {