From 4a628239188c0df6821235a119e0adea0e49ff18 Mon Sep 17 00:00:00 2001 From: vmishenev Date: Wed, 4 Dec 2024 12:19:29 +0200 Subject: [PATCH 1/2] Add new tests for KDoc links --- .../src/test/kotlin/markdown/LinkTest.kt | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt index 83c0ab9531..2de40d6076 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt @@ -1099,6 +1099,78 @@ class LinkTest : BaseAbstractTest() { } } + @Test + fun `KDoc link should be unresolved to non-existed property with the name of Kotlin getter #3681`() { + testInline( + """ + |/src/main/kotlin/Testing.kt + |fun getProperty() = 0 + |/** + |* [property] is unresolved + | */ + | usage() = 0 + |} + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + assertEquals(null, module.getLinkDRIFrom("usage")) + } + } + } + + @Test + fun `KDoc link should be resolved to two extensions with the same name #3631`() { + testInline( + """ + |/src/main/kotlin/Testing.kt + |class C + |public fun C.ensureActive() {} + |/** + | * [C.ensureActive] + | */ + |class B + |/** + | * [C.ensureActive] + | */ + |public fun B.ensureActive() {} + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val DRItoBensureActive = DRI( + "", + classNames = null, + callable = Callable( + name = "ensureActive", + receiver = TypeConstructor(fullyQualifiedName = "B", params = emptyList()), + params = emptyList() + ) + ) + val link1 = module.dfs { + it.dri == DRItoBensureActive + }?.documentation?.values?.single()?.firstMemberOfTypeOrNull()?.dri + val link2 = module.getLinkDRIFrom("B") + + + assertEquals( + link1, + DRI( + "", + classNames = null, + callable = Callable( + name = "ensureActive", + receiver = TypeConstructor(fullyQualifiedName = "C", params = emptyList()), + params = emptyList() + ) + ) + ) + + assertEquals(link1, link2) + } + } + } + private fun DModule.getLinkDRIFrom(name: String): DRI? { val link = this.dfs { it.name == name }?.documentation?.values?.single()?.firstMemberOfTypeOrNull() return link?.dri From 0036be86ad26b04135d7a6fbab88fa90a48ee888 Mon Sep 17 00:00:00 2001 From: vmishenev Date: Wed, 4 Dec 2024 13:47:00 +0200 Subject: [PATCH 2/2] Fix test --- .../plugin-base/src/test/kotlin/markdown/LinkTest.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt index 2de40d6076..d41a16ac3f 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt @@ -1108,7 +1108,7 @@ class LinkTest : BaseAbstractTest() { |/** |* [property] is unresolved | */ - | usage() = 0 + |fun usage() = 0 |} """.trimMargin(), configuration @@ -1172,7 +1172,9 @@ class LinkTest : BaseAbstractTest() { } private fun DModule.getLinkDRIFrom(name: String): DRI? { - val link = this.dfs { it.name == name }?.documentation?.values?.single()?.firstMemberOfTypeOrNull() + val doc = this.dfs { it.name == name }?.documentation?.values?.single() + ?: throw IllegalStateException("Can't find documentation for declaration '$name'") + val link = doc.firstMemberOfTypeOrNull() return link?.dri }