Skip to content

Commit d937a1e

Browse files
committed
Add tests
1 parent 31da651 commit d937a1e

File tree

2 files changed

+83
-36
lines changed

2 files changed

+83
-36
lines changed

dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -421,40 +421,4 @@ class LinkableContentTest : BaseAbstractTest() {
421421
}
422422
}
423423

424-
@Test
425-
fun `should have a correct url to an external inherited member #2879`() {
426-
val writerPlugin = TestOutputWriterPlugin()
427-
val configuration = dokkaConfiguration {
428-
sourceSets {
429-
sourceSet {
430-
sourceRoots = listOf("src/")
431-
classpath = listOfNotNull(jvmStdlibPath)
432-
}
433-
}
434-
}
435-
436-
testInline(
437-
"""
438-
/src/kotlin/main.kt
439-
open interface C : Collection<C>
440-
interface A : C()
441-
interface B : C()
442-
""".trimIndent()
443-
,
444-
pluginOverrides = listOf(writerPlugin),
445-
configuration = configuration
446-
) {
447-
renderingStage = { rootPage, ctx ->
448-
val location = DokkaLocationProvider(rootPage, ctx, ".html")
449-
val classA = rootPage.dfs { it is ClasslikePageNode && it.name == "A" }
450-
val classB = rootPage.dfs { it is ClasslikePageNode && it.name == "B" }
451-
val classC = rootPage.dfs { it is ClasslikePageNode && it.name == "C" }
452-
val sourceSet = (classA as ClasslikePageNode).content.sourceSets
453-
val dri = org.jetbrains.dokka.links.DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList()))
454-
assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classA))
455-
assertEquals("index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classB))
456-
assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classC))
457-
}
458-
}
459-
}
460424
}

dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
package locationProvider
66

77
import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider
8+
import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider
89
import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
910
import org.jetbrains.dokka.base.resolvers.shared.PackageList
1011
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
1112
import org.jetbrains.dokka.links.Callable
1213
import org.jetbrains.dokka.links.DRI
1314
import org.jetbrains.dokka.links.TypeConstructor
15+
import org.jetbrains.dokka.model.dfs
16+
import org.jetbrains.dokka.pages.ClasslikePageNode
1417
import org.jetbrains.dokka.plugability.DokkaContext
18+
import utils.TestOutputWriterPlugin
1519
import java.net.URL
1620
import kotlin.test.Test
1721
import kotlin.test.assertEquals
22+
import kotlin.test.assertTrue
1823

1924
class DefaultExternalLocationProviderTest : BaseAbstractTest() {
2025
private val testDataDir =
@@ -75,4 +80,82 @@ class DefaultExternalLocationProviderTest : BaseAbstractTest() {
7580

7681
assertEquals(null, locationProvider.resolve(dri))
7782
}
83+
84+
@Test
85+
fun `should have a correct url to an external inherited member #2879`() {
86+
val writerPlugin = TestOutputWriterPlugin()
87+
val configuration = dokkaConfiguration {
88+
89+
90+
sourceSets {
91+
sourceSet {
92+
externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
93+
sourceRoots = listOf("src/")
94+
classpath = listOfNotNull(jvmStdlibPath)
95+
}
96+
}
97+
}
98+
99+
testInline(
100+
"""
101+
/src/kotlin/main.kt
102+
open interface C : Collection<C>
103+
interface A : C()
104+
interface B : C()
105+
""".trimIndent()
106+
,
107+
pluginOverrides = listOf(writerPlugin),
108+
configuration = configuration
109+
) {
110+
renderingStage = { rootPage, ctx ->
111+
val location = DokkaLocationProvider(rootPage, ctx, ".html")
112+
val classA = rootPage.dfs { it is ClasslikePageNode && it.name == "A" }
113+
val classB = rootPage.dfs { it is ClasslikePageNode && it.name == "B" }
114+
val classC = rootPage.dfs { it is ClasslikePageNode && it.name == "C" }
115+
val sourceSet = (classA as ClasslikePageNode).content.sourceSets
116+
val dri = DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList()))
117+
assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classA))
118+
assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classB))
119+
assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classC))
120+
}
121+
}
122+
}
123+
124+
@Test
125+
fun `should have external links for external inherited members`() {
126+
val writerPlugin = TestOutputWriterPlugin()
127+
val configuration = dokkaConfiguration {
128+
sourceSets {
129+
sourceSet {
130+
externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
131+
sourceRoots = listOf("src/")
132+
classpath = listOfNotNull(jvmStdlibPath)
133+
}
134+
}
135+
}
136+
137+
testInline(
138+
"""
139+
/src/kotlin/main.kt
140+
interface MyCharSequence: CharSequence
141+
""".trimIndent()
142+
,
143+
pluginOverrides = listOf(writerPlugin),
144+
configuration = configuration
145+
) {
146+
renderingStage = { _, _ ->
147+
"".chars()
148+
val content = writerPlugin.writer.contents["root/[root]/-my-char-sequence/index.html"] ?: ""
149+
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/length.html\"><span><span>length</span></span></a>"))
150+
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/get.html\"><span><span>get</span></span></a>"))
151+
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/sub-sequence.html\"><span>sub</span><wbr></wbr><span><span>Sequence</span></span></a>"))
152+
// TODO #3542
153+
// these links are invalid
154+
// chars() and codePoints() are absent in https://kotlinlang.org/ since they come from mapping Kotlin to Java
155+
// see https://kotlinlang.org/docs/java-interop.html#mapped-types
156+
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/chars.html\"><span><span>chars</span></span></a>"))
157+
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/code-points.html\"><span>code</span><wbr></wbr><span><span>Points</span></span></a>"))
158+
}
159+
}
160+
}
78161
}

0 commit comments

Comments
 (0)