Skip to content

Commit

Permalink
Add unit tests for KDoc links to Java
Browse files Browse the repository at this point in the history
Two new tests have been added in `LinkTest.kt`. One is to verify that a KDoc link correctly points to Java annotation methods, and the second test is for Java synthetic properties.
  • Loading branch information
vmishenev committed Apr 25, 2024
1 parent f5d7f60 commit 33473a1
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 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 @@ -1040,6 +1040,65 @@ class LinkTest : BaseAbstractTest() {
}
}

@Test
fun `KDoc link should lead to java annotation methods`() {
testInline(
"""
|/src/main/kotlin/Testing.kt
|package example
|
|/**
| * [Storage.value]
| */
|val usage = 0
|/src/example/Storage.java
|package example;
|@interface Storage {
| String value() default "";
|}
""".trimMargin(),
configuration
) {
documentablesMergingStage = { module ->
assertEquals(DRI("example", "Storage", Callable("value", null, emptyList())), module.getLinkDRIFrom("usage"))
}
}
}

@Test
fun `KDoc link should lead to java synthetic properties`() {
testInline(
"""
|/src/main/kotlin/Testing.kt
|package example
|
|/**
| * value: [Storage.value] is unresolved
| * setValue: [Storage.setValue]
| * prop: [Storage.prop]
| */
|val usage = 0
|/src/example/Storage.java
|package example;
|class Storage {
| void prop() {}
| void setValue(String value) {}
| String getProp() { return null; }
|}
""".trimMargin(),
configuration
) {
documentablesMergingStage = { module ->
assertEquals(
listOf(
"Storage.setValue" to DRI("example", "Storage", Callable("setValue", null, listOf(TypeConstructor("kotlin.String", emptyList())))),
"Storage.prop" to DRI("example", "Storage", Callable("prop", null, emptyList()))
),
module.getAllLinkDRIFrom("usage"))
}
}
}

private fun DModule.getLinkDRIFrom(name: String): DRI? {
val link = this.dfs { it.name == name }?.documentation?.values?.single()?.firstMemberOfTypeOrNull<DocumentationLink>()
return link?.dri
Expand Down

0 comments on commit 33473a1

Please sign in to comment.