1
1
package love.forte.plugin.suspendtrans.test
2
2
3
3
import love.forte.plugin.suspendtrans.CliOptions
4
+ import love.forte.plugin.suspendtrans.ICliOption
4
5
import love.forte.plugin.suspendtrans.SuspendTransformConfiguration
6
+ import kotlin.reflect.KMutableProperty1
5
7
import kotlin.test.Test
6
8
import kotlin.test.assertEquals
7
9
@@ -12,25 +14,29 @@ import kotlin.test.assertEquals
12
14
*/
13
15
class CliOptionsTest {
14
16
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
+
15
29
@Test
16
30
fun formatTest () {
17
31
val annotations = listOf (
18
32
SuspendTransformConfiguration .IncludeAnnotation (" Hello" , false ),
19
33
SuspendTransformConfiguration .IncludeAnnotation (" World" , true )
20
34
)
21
35
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 )
27
38
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 )
34
40
35
41
36
42
}
0 commit comments