|
5 | 5 | package locationProvider
|
6 | 6 |
|
7 | 7 | import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider
|
| 8 | +import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider |
8 | 9 | import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
|
9 | 10 | import org.jetbrains.dokka.base.resolvers.shared.PackageList
|
10 | 11 | import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
|
11 | 12 | import org.jetbrains.dokka.links.Callable
|
12 | 13 | import org.jetbrains.dokka.links.DRI
|
13 | 14 | import org.jetbrains.dokka.links.TypeConstructor
|
| 15 | +import org.jetbrains.dokka.model.dfs |
| 16 | +import org.jetbrains.dokka.pages.ClasslikePageNode |
14 | 17 | import org.jetbrains.dokka.plugability.DokkaContext
|
| 18 | +import utils.TestOutputWriterPlugin |
15 | 19 | import java.net.URL
|
16 | 20 | import kotlin.test.Test
|
17 | 21 | import kotlin.test.assertEquals
|
| 22 | +import kotlin.test.assertTrue |
18 | 23 |
|
19 | 24 | class DefaultExternalLocationProviderTest : BaseAbstractTest() {
|
20 | 25 | private val testDataDir =
|
@@ -75,4 +80,82 @@ class DefaultExternalLocationProviderTest : BaseAbstractTest() {
|
75 | 80 |
|
76 | 81 | assertEquals(null, locationProvider.resolve(dri))
|
77 | 82 | }
|
| 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 | + } |
78 | 161 | }
|
0 commit comments