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 24d91cd4c5..116e30458d 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt @@ -437,4 +437,264 @@ class LinkTest : BaseAbstractTest() { } } } + + @Test + fun `link should lead to function rather than property`() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Testing.kt + |package example + | + |fun x(p: Int){} + |val x = 0 + |/** + | * ref to fun [x] + | */ + |val x2 = 0 + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val propDocs = + module.packages.flatMap { it.properties }.first { it.name == "x2" }.documentation.values.first() + val expected = Description( + root = CustomDocTag( + children = listOf( + P( + children = listOf( + Text("ref to fun "), + DocumentationLink( + dri = DRI( + packageName = "example", + classNames = null, + target = PointingToDeclaration, + callable = Callable( + "x", + params = listOf(TypeConstructor("kotlin.Int", emptyList())) + ) + ), + children = listOf( + Text("x") + ), + params = mapOf("href" to "[x]") + ) + ) + ) + ), + name = "MARKDOWN_FILE" + ) + ) + assertEquals(expected, propDocs.children.first()) + } + } + } + + @Test + @OnlySymbols("#3455 - KDoc links to a package are unresolved ") + fun `fully qualified link should lead to package`() { + // for the test case, there is the only one link candidate in K1 and K2 + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Testing.kt + |package example + | + |/** + | * refs to the package [example.fn] and the property [example.x] + | */ + |val x = 0 + | + |/** + | * refs to the package [example.fn] and the property [example.x] + | */ + |fun fn(p: Int){} + | + |/src/main/kotlin/Testing2.kt + |package example.fn + | + |fun fn(p: Int){} + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val propDocs = + module.packages.flatMap { it.properties }.first { it.name == "x" }.documentation.values.first() + + val fnDocs = + module.packages.first { it.name == "example" }.functions.first { it.name == "fn" }.documentation.values.first() + + val expected = Description( + root = CustomDocTag( + children = listOf( + P( + children = listOf( + Text("refs to the package "), + DocumentationLink( + dri = DRI( + packageName = "example.fn", + classNames = null, + target = PointingToDeclaration, + ), + children = listOf( + Text("example.fn") + ), + params = mapOf("href" to "[example.fn]") + ), + Text(" and the property "), + DocumentationLink( + dri = DRI( + packageName = "example", + classNames = null, + target = PointingToDeclaration, + callable = Callable( + "x", + params = emptyList() + ) + ), + children = listOf( + Text("example.x") + ), + params = mapOf("href" to "[example.x]") + ) + ) + ) + ), + name = "MARKDOWN_FILE" + ) + ) + assertEquals(expected, propDocs.children.first()) + assertEquals(expected, fnDocs.children.first()) + } + } + } + + @Test + fun `short link should lead to class rather than package`() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Testing.kt + |package example + | + |/** + | * refs to the class [example] + | */ + |val x = 0 + | + |class example + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val propDocs = + module.packages.flatMap { it.properties }.first { it.name == "x" }.documentation.values.first() + + + val expected = Description( + root = CustomDocTag( + children = listOf( + P( + children = listOf( + Text("refs to the class "), + DocumentationLink( + dri = DRI( + packageName = "example", + classNames = "example", + target = PointingToDeclaration, + ), + children = listOf( + Text("example") + ), + params = mapOf("href" to "[example]") + ), + ) + ) + ), + name = "MARKDOWN_FILE" + ) + ) + assertEquals(expected, propDocs.children.first()) + } + } + } + + @Test + @OnlySymbols("#3455 - KDoc links to a package are unresolved ") + fun `short link should lead to package rather than function`() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Testing.kt + |package example + | + |/** + | * refs to the package [example] + | */ + |val x = 0 + | + |fun example() {} + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val propDocs = + module.packages.flatMap { it.properties }.first { it.name == "x" }.documentation.values.first() + + + val expected = Description( + root = CustomDocTag( + children = listOf( + P( + children = listOf( + Text("refs to the package "), + DocumentationLink( + dri = DRI( + packageName = "example", + classNames = null, + target = PointingToDeclaration, + ), + children = listOf( + Text("example") + ), + params = mapOf("href" to "[example]") + ), + ) + ) + ), + name = "MARKDOWN_FILE" + ) + ) + assertEquals(expected, propDocs.children.first()) + } + } + } }