Skip to content

Commit 02bc3f3

Browse files
committed
test: CliOptions test
1 parent fe5b9a9 commit 02bc3f3

File tree

1 file changed

+17
-11
lines changed
  • compiler/suspend-transform-plugin/src/test/kotlin/love/forte/plugin/suspendtrans/test

1 file changed

+17
-11
lines changed

compiler/suspend-transform-plugin/src/test/kotlin/love/forte/plugin/suspendtrans/test/CliOptionsTest.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package love.forte.plugin.suspendtrans.test
22

33
import love.forte.plugin.suspendtrans.CliOptions
4+
import love.forte.plugin.suspendtrans.ICliOption
45
import love.forte.plugin.suspendtrans.SuspendTransformConfiguration
6+
import kotlin.reflect.KMutableProperty1
57
import kotlin.test.Test
68
import kotlin.test.assertEquals
79

@@ -12,25 +14,29 @@ import kotlin.test.assertEquals
1214
*/
1315
class CliOptionsTest {
1416

17+
private fun <T> jvmConfigFormatTest(property: KMutableProperty1<SuspendTransformConfiguration.Jvm, T>, value: T, option: ICliOption) {
18+
val originConfig = SuspendTransformConfiguration().apply {
19+
property.set(jvm, value)
20+
}
21+
22+
val valueString = option.resolveToValue(originConfig)
23+
val newConfig = SuspendTransformConfiguration()
24+
option.resolveFromValue(newConfig, valueString)
25+
assertEquals(value, property.get(newConfig.jvm))
26+
27+
}
28+
1529
@Test
1630
fun formatTest() {
1731
val annotations = listOf(
1832
SuspendTransformConfiguration.IncludeAnnotation("Hello", false),
1933
SuspendTransformConfiguration.IncludeAnnotation("World", true)
2034
)
2135

22-
val config = SuspendTransformConfiguration().apply {
23-
jvm {
24-
syntheticBlockingFunctionIncludeAnnotations = annotations
25-
}
26-
}
36+
jvmConfigFormatTest(SuspendTransformConfiguration.Jvm::syntheticBlockingFunctionIncludeAnnotations, annotations, CliOptions.Jvm.SYNTHETIC_BLOCKING_FUNCTION_INCLUDE_ANNOTATIONS)
37+
jvmConfigFormatTest(SuspendTransformConfiguration.Jvm::syntheticAsyncFunctionIncludeAnnotations, annotations, CliOptions.Jvm.SYNTHETIC_ASYNC_FUNCTION_INCLUDE_ANNOTATIONS)
2738

28-
CliOptions.Jvm.SYNTHETIC_BLOCKING_FUNCTION_INCLUDE_ANNOTATIONS.also { opt ->
29-
val value = opt.resolveToValue(config)
30-
val newConfig = SuspendTransformConfiguration()
31-
opt.resolveFromValue(newConfig, value)
32-
assertEquals(annotations, newConfig.jvm.syntheticBlockingFunctionIncludeAnnotations)
33-
}
39+
jvmConfigFormatTest(SuspendTransformConfiguration.Jvm::originFunctionIncludeAnnotations, annotations, CliOptions.Jvm.ORIGIN_FUNCTION_INCLUDE_ANNOTATIONS)
3440

3541

3642
}

0 commit comments

Comments
 (0)