blob: 6ef38aa9ab0d94fc5bf5b2d3416677e6f7213860 (
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
126
|
package pageMerger
import org.jetbrains.dokka.pages.ContentPage
import org.jetbrains.dokka.pages.PageNode
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
class PageNodeMergerTest : AbstractCoreTest() {
/* object SameNameStrategy : DokkaPlugin() {
val strategy by extending { CoreExtensions.pageMergerStrategy with SameMethodNamePageMergerStrategy }
}
class DefaultStrategy(val strList: MutableList<String> = mutableListOf()) : DokkaPlugin(), DokkaLogger {
val strategy by extending { CoreExtensions.pageMergerStrategy with DefaultPageMergerStrategy(this@DefaultStrategy) }
override var warningsCount: Int = 0
override var errorsCount: Int = 0
override fun debug(message: String) = TODO()
override fun info(message: String) = TODO()
override fun progress(message: String) = TODO()
override fun warn(message: String) {
strList += message
}
override fun error(message: String) = TODO()
override fun report() = TODO()
}
*/
@Test
fun sameNameStrategyTest() {
val configuration = dokkaConfiguration {
passes {
pass {
sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
}
}
}
testInline(
"""
|/src/main/kotlin/pageMerger/Test.kt
|package pageMerger
|
|fun testT(): Int = 1
|fun testT(i: Int): Int = i
|
|object Test {
| fun test(): String = ""
| fun test(str: String): String = str
|}
""".trimMargin(),
configuration/*,
pluginOverrides = listOf(SameNameStrategy)*/
) {
pagesTransformationStage = {
val allChildren = it.childrenRec().filterIsInstance<ContentPage>()
val testT = allChildren.filter { it.name == "testT" }
val test = allChildren.filter { it.name == "test" }
assertTrue(testT.size == 1) { "There can be only one testT page" }
assertTrue(testT.first().dri.size == 2) { "testT page should have 2 DRI, but has ${testT.first().dri.size}" }
assertTrue(test.size == 1) { "There can be only one test page" }
assertTrue(test.first().dri.size == 2) { "test page should have 2 DRI, but has ${test.first().dri.size}" }
}
}
}
@Disabled("TODO: reenable when we have infrastructure for turning off extensions")
@Test
fun defaultStrategyTest() {
val strList: MutableList<String> = mutableListOf()
val configuration = dokkaConfiguration {
passes {
pass {
sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
}
}
}
testInline(
"""
|/src/main/kotlin/pageMerger/Test.kt
|package pageMerger
|
|fun testT(): Int = 1
|fun testT(i: Int): Int = i
|
|object Test {
| fun test(): String = ""
| fun test(str: String): String = str
|}
""".trimMargin(),
configuration/*,
pluginOverrides = listOf(DefaultStrategy(strList)) */
) {
pagesTransformationStage = { root ->
val allChildren = root.childrenRec().filterIsInstance<ContentPage>()
val testT = allChildren.filter { it.name == "testT" }
val test = allChildren.filter { it.name == "test" }
assertTrue(testT.size == 1) { "There can be only one testT page" }
assertTrue(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" }
assertTrue(test.size == 1) { "There can be only one test page" }
assertTrue(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" }
assertTrue(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" }
}
}
}
fun PageNode.childrenRec(): List<PageNode> = listOf(this) + children.flatMap { it.childrenRec() }
}
|