From d937a1e58e63adb032666bcfe7597e2c8e1c3572 Mon Sep 17 00:00:00 2001 From: "Vadim.Mishenev" Date: Tue, 19 Mar 2024 18:35:31 +0200 Subject: [PATCH] Add tests --- .../linkableContent/LinkableContentTest.kt | 36 -------- .../DefaultExternalLocationProviderTest.kt | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+), 36 deletions(-) diff --git a/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt index 2129c482d6..e0df2caabe 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -421,40 +421,4 @@ class LinkableContentTest : BaseAbstractTest() { } } - @Test - fun `should have a correct url to an external inherited member #2879`() { - val writerPlugin = TestOutputWriterPlugin() - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - classpath = listOfNotNull(jvmStdlibPath) - } - } - } - - testInline( - """ - /src/kotlin/main.kt - open interface C : Collection - interface A : C() - interface B : C() - """.trimIndent() - , - pluginOverrides = listOf(writerPlugin), - configuration = configuration - ) { - renderingStage = { rootPage, ctx -> - val location = DokkaLocationProvider(rootPage, ctx, ".html") - val classA = rootPage.dfs { it is ClasslikePageNode && it.name == "A" } - val classB = rootPage.dfs { it is ClasslikePageNode && it.name == "B" } - val classC = rootPage.dfs { it is ClasslikePageNode && it.name == "C" } - val sourceSet = (classA as ClasslikePageNode).content.sourceSets - val dri = org.jetbrains.dokka.links.DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList())) - assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classA)) - assertEquals("index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classB)) - assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classC)) - } - } - } } diff --git a/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt b/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt index aaf63e7eef..4f7732f114 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt @@ -5,16 +5,21 @@ package locationProvider import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider +import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.PackageList import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.TypeConstructor +import org.jetbrains.dokka.model.dfs +import org.jetbrains.dokka.pages.ClasslikePageNode import org.jetbrains.dokka.plugability.DokkaContext +import utils.TestOutputWriterPlugin import java.net.URL import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue class DefaultExternalLocationProviderTest : BaseAbstractTest() { private val testDataDir = @@ -75,4 +80,82 @@ class DefaultExternalLocationProviderTest : BaseAbstractTest() { assertEquals(null, locationProvider.resolve(dri)) } + + @Test + fun `should have a correct url to an external inherited member #2879`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + + + sourceSets { + sourceSet { + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + sourceRoots = listOf("src/") + classpath = listOfNotNull(jvmStdlibPath) + } + } + } + + testInline( + """ + /src/kotlin/main.kt + open interface C : Collection + interface A : C() + interface B : C() + """.trimIndent() + , + pluginOverrides = listOf(writerPlugin), + configuration = configuration + ) { + renderingStage = { rootPage, ctx -> + val location = DokkaLocationProvider(rootPage, ctx, ".html") + val classA = rootPage.dfs { it is ClasslikePageNode && it.name == "A" } + val classB = rootPage.dfs { it is ClasslikePageNode && it.name == "B" } + val classC = rootPage.dfs { it is ClasslikePageNode && it.name == "C" } + val sourceSet = (classA as ClasslikePageNode).content.sourceSets + val dri = DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList())) + assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classA)) + assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classB)) + assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classC)) + } + } + } + + @Test + fun `should have external links for external inherited members`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + sourceRoots = listOf("src/") + classpath = listOfNotNull(jvmStdlibPath) + } + } + } + + testInline( + """ + /src/kotlin/main.kt + interface MyCharSequence: CharSequence + """.trimIndent() + , + pluginOverrides = listOf(writerPlugin), + configuration = configuration + ) { + renderingStage = { _, _ -> + "".chars() + val content = writerPlugin.writer.contents["root/[root]/-my-char-sequence/index.html"] ?: "" + assertTrue(content.contains("length")) + assertTrue(content.contains("get")) + assertTrue(content.contains("subSequence")) + // TODO #3542 + // these links are invalid + // chars() and codePoints() are absent in https://kotlinlang.org/ since they come from mapping Kotlin to Java + // see https://kotlinlang.org/docs/java-interop.html#mapped-types + assertTrue(content.contains("chars")) + assertTrue(content.contains("codePoints")) + } + } + } }