blob: 257b17ffc8d77e2bb727011b5d8911a54adc2ccb (
plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
package kotlinAsJavaPlugin
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.DClass
import org.jetbrains.dokka.model.DEnum
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
class DRITranslationTest : BaseAbstractTest() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
classpath += jvmStdlibPath!!
}
}
}
@Test
fun `should correctly handle nested classes`() {
testInline(
"""
|/src/main/kotlin/kotlinAsJavaPlugin/sample.kt
|package kotlinAsJavaPlugin
|class A {
| class B(val x: String)
|}
|class C {
| class B(val x: String)
|}
""".trimMargin(),
configuration,
) {
documentablesTransformationStage = { module ->
val nestedClasslikesDRIs = module.packages.flatMap { it.classlikes }.flatMap { it.classlikes }.map { it.dri }
val driRegex = "[AC]\\.B".toRegex()
nestedClasslikesDRIs.forEach { dri ->
assertTrue(driRegex.matches(dri.classNames.toString()))
}
}
}
}
@Test
fun `should correctly handle interface methods`() {
testInline(
"""
|/src/main/kotlin/kotlinAsJavaPlugin/sample.kt
|package kotlinAsJavaPlugin
|interface A {
| fun b()
|}
""".trimMargin(),
configuration,
) {
documentablesTransformationStage = { module ->
val nestedFunctionDRI = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.filter { it.name == "b" }.map { it.dri }.single()
assertTrue(nestedFunctionDRI.classNames == "A")
}
}
}
@Test
fun `should correctly handle object methods`() {
testInline(
"""
|/src/main/kotlin/kotlinAsJavaPlugin/sample.kt
|package kotlinAsJavaPlugin
|object A {
| fun b() {}
|}
""".trimMargin(),
configuration,
) {
documentablesTransformationStage = { module ->
val nestedFunctionDRI = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.filter { it.name == "b" }.map { it.dri }.single()
assertTrue(nestedFunctionDRI.classNames == "A")
}
}
}
@Test
fun `should correctly handle enum functions`() {
testInline(
"""
|/src/main/kotlin/kotlinAsJavaPlugin/sample.kt
|package kotlinAsJavaPlugin
|enum class A(private val x: Int) {
| X(0);
| fun b() = x
|}
""".trimMargin(),
configuration,
) {
documentablesTransformationStage = { module ->
val nestedFunctionDRI = (module.packages.single().classlikes.single() as DEnum).functions.filter { it.name == "b" }.map { it.dri }.single()
assertTrue(nestedFunctionDRI.classNames == "A")
}
}
}
@Test
fun `should correctly handle nested classes' constructors`() {
testInline(
"""
|/src/main/kotlin/kotlinAsJavaPlugin/sample.kt
|package kotlinAsJavaPlugin
|class A {
| class B(val x: String)
|}
""".trimMargin(),
configuration,
) {
documentablesTransformationStage = { module ->
val constructorDRI = (module.packages.flatMap { it.classlikes }.flatMap { it.classlikes }.single() as DClass).constructors.single().dri
assertTrue(constructorDRI.classNames == "A.B")
}
}
}
}
|