diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2020-12-29 14:38:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-29 14:38:19 +0100 |
commit | f5e7cffbebb66b989c64bdda61e1f7809ddc6068 (patch) | |
tree | ea0ef4b550f9a55681a915d5cb4d9f1beca22041 /plugins/kotlin-as-java/src/test/kotlin | |
parent | e55f3b015faec3f62e829a2aa5984e4bd6d5037e (diff) | |
download | dokka-f5e7cffbebb66b989c64bdda61e1f7809ddc6068.tar.gz dokka-f5e7cffbebb66b989c64bdda61e1f7809ddc6068.tar.bz2 dokka-f5e7cffbebb66b989c64bdda61e1f7809ddc6068.zip |
Parsing of JvmName (#1675)
* Parsing of JvmName
* Make JvmName processor run after KaJ
Diffstat (limited to 'plugins/kotlin-as-java/src/test/kotlin')
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt | 158 | ||||
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 4 |
2 files changed, 160 insertions, 2 deletions
diff --git a/plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt b/plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt new file mode 100644 index 00000000..4c7e2445 --- /dev/null +++ b/plugins/kotlin-as-java/src/test/kotlin/JvmNameTest.kt @@ -0,0 +1,158 @@ +package kotlinAsJavaPlugin + +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.links.Callable +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.TypeConstructor +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class JvmNameTest : BaseAbstractTest() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + classpath += jvmStdlibPath!! + } + } + } + + @Test + fun `should change name for class containing top level function`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |@file:JvmName("CustomJvmName") + |package kotlinAsJavaPlugin + |fun sample(): String = "" + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val expectedClassLikeDri = DRI( + packageName = "kotlinAsJavaPlugin", + classNames = "CustomJvmName", + ) + val classLike = module.packages.flatMap { it.classlikes }.first() + assertEquals(expectedClassLikeDri, classLike.dri) + assertEquals("CustomJvmName", classLike.name) + } + } + } + + @Test + fun `should change name for top level function`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |@file:JvmName("CustomJvmName") + |package kotlinAsJavaPlugin + |@JvmName("jvmSample") + |fun sample(): String = "" + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val expectedFunctionDri = DRI( + packageName = "kotlinAsJavaPlugin", + classNames = "CustomJvmName", + callable = Callable( + "jvmSample", + receiver = null, + params = emptyList() + ) + ) + val function = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.first() + assertEquals(expectedFunctionDri, function.dri) + assertEquals("jvmSample", function.name) + } + } + } + + @Test + fun `should change name of a setter for top level property`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |@file:JvmName("CustomJvmName") + |package kotlinAsJavaPlugin + |@get:JvmName("xd") + |@set:JvmName("asd") + |var property: String + | get() = "" + | set(value) {} + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val expectedSetterDri = DRI( + packageName = "kotlinAsJavaPlugin", + classNames = "CustomJvmName", + callable = Callable( + "asd", + receiver = null, + //Todo this is bad, this should be a type in java, look at the bytecode + params = listOf(TypeConstructor("kotlin.String", emptyList())) + ) + ) + val function = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.first { it.name == "asd"} + assertEquals(expectedSetterDri, function.dri) + assertEquals("asd", function.name) + } + } + } + + @Test + fun `should change name of a getter for top level property`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |@file:JvmName("CustomJvmName") + |package kotlinAsJavaPlugin + |@get:JvmName("xd") + |@set:JvmName("asd") + |var property: String + | get() = "" + | set(value) {} + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val expectedGetterDri = DRI( + packageName = "kotlinAsJavaPlugin", + classNames = "CustomJvmName", + callable = Callable( + "xd", + receiver = null, + params = emptyList() + ) + ) + val function = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.first { it.name == "xd"} + assertEquals(expectedGetterDri, function.dri) + assertEquals("xd", function.name) + } + } + } + + @Test + fun `should leave the name as default if annotation is not provided`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |fun sample(): String = "" + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val expectedClassLikeDri = DRI( + packageName = "kotlinAsJavaPlugin", + classNames = "SampleKt", + ) + val classLike = module.packages.flatMap { it.classlikes }.first() + assertEquals(expectedClassLikeDri, classLike.dri) + assertEquals("SampleKt", classLike.name) + } + } + } +}
\ No newline at end of file diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 5430ea88..8e7b798a 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -330,7 +330,7 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() { ) { renderingStage = { _, _ -> writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first().match( - "final ", A("Integer"), A("someFun"), "(", A("Integer"), A("xd"), ")", Span() + "final ", A("Integer"), A("someFun"), "(", A("Integer"), "xd)", Span() ) } } @@ -368,7 +368,7 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() { renderingStage = { _, _ -> writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first().match( "final ", A("Integer"), A("someFun"), "(", A("Map"), "<", A("String"), - ", ", A("Integer"), ">", A("xd"), ")", Span() + ", ", A("Integer"), "> xd)", Span() ) } } |