1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
package content.annotations
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Annotations
import org.jetbrains.dokka.model.StringValue
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import kotlin.test.assertEquals
class FileLevelJvmNameTest : BaseAbstractTest() {
private val testConfiguration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
analysisPlatform = "jvm"
classpath += jvmStdlibPath!!
}
}
}
companion object {
private const val functionTest =
"""
|/src/main/kotlin/test/source.kt
|@file:JvmName("CustomJvmName")
|package test
|
|fun function(abc: String): String {
| return "Hello, " + abc
|}
"""
private const val extensionFunctionTest =
"""
|/src/main/kotlin/test/source.kt
|@file:JvmName("CustomJvmName")
|package test
|
|fun String.function(abc: String): String {
| return "Hello, " + abc
|}
"""
private const val propertyTest =
"""
|/src/main/kotlin/test/source.kt
|@file:JvmName("CustomJvmName")
|package test
|
|val property: String
| get() = ""
"""
private const val extensionPropertyTest =
"""
|/src/main/kotlin/test/source.kt
|@file:JvmName("CustomJvmName")
|package test
|
|val String.property: String
| get() = ""
"""
}
@ParameterizedTest
@ValueSource(strings = [functionTest, extensionFunctionTest])
fun `jvm name should be included in functions extra`(query: String) {
testInline(
query.trimIndent(), testConfiguration
) {
documentablesCreationStage = { modules ->
val expectedAnnotation = Annotations.Annotation(
dri = DRI("kotlin.jvm", "JvmName"),
params = mapOf("name" to StringValue("CustomJvmName")),
scope = Annotations.AnnotationScope.FILE,
mustBeDocumented = false
)
val function = modules.flatMap { it.packages }.first().functions.first()
val annotation = function.extra[Annotations]?.fileLevelAnnotations?.entries?.first()?.value?.single()
assertEquals(emptyMap(), function.extra[Annotations]?.directAnnotations)
assertEquals(expectedAnnotation, annotation)
assertEquals(expectedAnnotation.scope, annotation?.scope)
assertEquals(expectedAnnotation.mustBeDocumented, annotation?.mustBeDocumented)
}
}
}
@ParameterizedTest
@ValueSource(strings = [propertyTest, extensionPropertyTest])
fun `jvm name should be included in properties extra`(query: String) {
testInline(
query.trimIndent(), testConfiguration
) {
documentablesCreationStage = { modules ->
val expectedAnnotation = Annotations.Annotation(
dri = DRI("kotlin.jvm", "JvmName"),
params = mapOf("name" to StringValue("CustomJvmName")),
scope = Annotations.AnnotationScope.FILE,
mustBeDocumented = false
)
val properties = modules.flatMap { it.packages }.first().properties.first()
val annotation = properties.extra[Annotations]?.fileLevelAnnotations?.entries?.first()?.value?.single()
assertEquals(emptyMap(), properties.extra[Annotations]?.directAnnotations)
assertEquals(expectedAnnotation, annotation)
assertEquals(expectedAnnotation.scope, annotation?.scope)
assertEquals(expectedAnnotation.mustBeDocumented, annotation?.mustBeDocumented)
}
}
}
}
|