From d6c9fc8b434d01d61077e8eba464196cf04a94ef Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Thu, 25 Apr 2024 23:11:33 +0300 Subject: [PATCH] Add unit tests for KDoc links to Java (#3584) 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. --- .../src/test/kotlin/markdown/LinkTest.kt | 59 +++++++++++++++++++ 1 file changed, 59 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 f70e6aa7d5..83c0ab9531 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt @@ -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() return link?.dri