Skip to content

Commit

Permalink
Add tests for overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Jan 19, 2024
1 parent bdb685b commit cf89e6a
Showing 1 changed file with 149 additions and 0 deletions.
149 changes: 149 additions & 0 deletions dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.pages.ClasslikePageNode
import org.jetbrains.dokka.pages.ContentDRILink
import org.jetbrains.dokka.pages.MemberPageNode
import utils.OnlyDescriptors
import utils.OnlySymbols
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -697,4 +698,152 @@ class LinkTest : BaseAbstractTest() {
}
}
}

@Test
fun `link should be stable for overloads`() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}

testInline(
"""
|/src/main/kotlin/Testing.kt
|package example
|
|/**
| * refs to the overload [f] and [f2]
| */
|val x = 0
|
|fun f(i: Int) {}
|fun f(s: String) {}
|
|fun f2(i: String) {}
|fun f2(s: Int) {}
""".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 overload "),
DocumentationLink(
dri = DRI(
packageName = "example",
classNames = null,
target = PointingToDeclaration,
callable = Callable(
"f",
params = listOf(TypeConstructor("kotlin.Int", emptyList()))
)
),
children = listOf(
Text("f")
),
params = mapOf("href" to "[f]")
),

Text(" and "),
DocumentationLink(
dri = DRI(
packageName = "example",
classNames = null,
target = PointingToDeclaration,
callable = Callable(
"f2",
params = listOf(TypeConstructor("kotlin.String", emptyList()))
)
),
children = listOf(
Text("f2")
),
params = mapOf("href" to "[f2]")
),
)
)
),
name = "MARKDOWN_FILE"
)
)
assertEquals(expected, propDocs.children.first())
}
}
}
@Test
@OnlyDescriptors("due to #3250 a result DRI is unstable")
fun `K1 - link should be stable for overloads in different files`() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}

testInline(
"""
|/src/main/kotlin/Testing.kt
|package example
|
|/**
| * refs to the overload [f]
| */
|val x = 0
|
|fun f(i: String) {}
|
|/src/main/kotlin/Testing2.kt
|package example
|
|fun f(s: Int) {}
""".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 overload "),
DocumentationLink(
dri = DRI(
packageName = "example",
classNames = null,
target = PointingToDeclaration,
callable = Callable(
"f",
params = listOf(TypeConstructor("kotlin.String", emptyList()))
)
),
children = listOf(
Text("f")
),
params = mapOf("href" to "[f]")
),
)
)
),
name = "MARKDOWN_FILE"
)
)
assertEquals(expected, propDocs.children.first())
}
}
}
}

0 comments on commit cf89e6a

Please sign in to comment.