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
|
package locationProvider
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider
import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
class DefaultLocationProviderTest : AbstractCoreTest() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
@Test
fun `#644 same directory for module and package`() {
testInline(
"""
|/src/main/kotlin/basic/Test.kt
|
|class Test {
| val x = 1
|}
""".trimMargin(),
configuration
) {
var context: DokkaContext? = null
pluginsSetupStage = {
context = it
}
pagesGenerationStage = { module ->
val lp = DokkaLocationProvider(module, context!!)
assertNotEquals(lp.resolve(module.children.single()).removePrefix("/"), lp.resolve(module))
}
}
}
@Test
fun `should escape illegal pipe character in file name`() {
/*
Currently even kotlin doesn't escape pipe characters in file names so it is impossible to have a
class named || on windows
*/
testInline(
"""
|/src/main/kotlin/basic/Test.kt
|
|class Test {
| fun `||`() { }
|}
""".trimMargin(),
configuration
) {
var context: DokkaContext? = null
pluginsSetupStage = {
context = it
}
pagesGenerationStage = { module ->
val lp = DokkaLocationProvider(module, context!!)
val functionWithPipes = module.dfs { it.name == "||" }
assertNotNull(functionWithPipes, "Failed to find a page for a function named ||")
assertEquals(lp.resolve(functionWithPipes), "[root]/-test/[124][124].html")
}
}
}
@ParameterizedTest
@MethodSource
fun runEscapeTestForCharacter(data: TestData) {
testInline(
"""
|/src/main/kotlin/basic/Test.kt
|
|class Test {
| fun `${data.tested}`() { }
|}
""".trimMargin(),
configuration
) {
var context: DokkaContext? = null
pluginsSetupStage = {
context = it
}
pagesGenerationStage = { module ->
val lp = DokkaLocationProvider(module, context!!)
val functionWithPipes = module.dfs { it.name == "${data.tested}" }
assertNotNull(functionWithPipes, "Failed to find a page for a function named ${data.tested}")
assertEquals(lp.resolve(functionWithPipes), "[root]/-test/${data.expectedReplacement}.html")
}
}
}
data class TestData(val tested: Char, val expectedReplacement: String)
companion object TestDataSources {
@JvmStatic
fun runEscapeTestForCharacter(): List<TestData> = listOf(
'|' to "[124]",
'>' to "[62]",
'<' to "[60]",
'*' to "[42]",
':' to "[58]",
'"' to "[34]",
'?' to "[63]",
'%' to "[37]"
).map {
TestData(it.first, it.second)
}
}
}
|