11package love.forte.plugin.suspendtrans.test
22
33import love.forte.plugin.suspendtrans.CliOptions
4+ import love.forte.plugin.suspendtrans.ICliOption
45import love.forte.plugin.suspendtrans.SuspendTransformConfiguration
6+ import kotlin.reflect.KMutableProperty1
57import kotlin.test.Test
68import kotlin.test.assertEquals
79
@@ -12,25 +14,29 @@ import kotlin.test.assertEquals
1214 */
1315class 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