diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-11-10 11:46:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 11:46:54 +0100 |
commit | 8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch) | |
tree | 1b915207b2b9f61951ddbf0ff2e687efd053d555 /dokka-subprojects/plugin-kotlin-as-java/src/test/kotlin/kotlinAsJavaPlugin/DRITranslationTest.kt | |
parent | a44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff) | |
download | dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2 dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip |
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing
* Update Gradle to 8.4
* Refactor and simplify convention plugins and build scripts
Fixes #3132
---------
Co-authored-by: Adam <897017+aSemy@users.noreply.github.com>
Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'dokka-subprojects/plugin-kotlin-as-java/src/test/kotlin/kotlinAsJavaPlugin/DRITranslationTest.kt')
-rw-r--r-- | dokka-subprojects/plugin-kotlin-as-java/src/test/kotlin/kotlinAsJavaPlugin/DRITranslationTest.kt | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/dokka-subprojects/plugin-kotlin-as-java/src/test/kotlin/kotlinAsJavaPlugin/DRITranslationTest.kt b/dokka-subprojects/plugin-kotlin-as-java/src/test/kotlin/kotlinAsJavaPlugin/DRITranslationTest.kt new file mode 100644 index 00000000..bdea1cb4 --- /dev/null +++ b/dokka-subprojects/plugin-kotlin-as-java/src/test/kotlin/kotlinAsJavaPlugin/DRITranslationTest.kt @@ -0,0 +1,129 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package kotlinAsJavaPlugin + + +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.DClass +import org.jetbrains.dokka.model.DEnum +import kotlin.test.Test +import kotlin.test.assertTrue + +class DRITranslationTest : BaseAbstractTest() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + classpath += jvmStdlibPath!! + } + } + } + + @Test + fun `should correctly handle nested classes`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |class A { + | class B(val x: String) + |} + |class C { + | class B(val x: String) + |} + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val nestedClasslikesDRIs = module.packages.flatMap { it.classlikes }.flatMap { it.classlikes }.map { it.dri } + val driRegex = "[AC]\\.B".toRegex() + + nestedClasslikesDRIs.forEach { dri -> + assertTrue(driRegex.matches(dri.classNames.toString())) + } + } + } + } + + @Test + fun `should correctly handle interface methods`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |interface A { + | fun b() + |} + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val nestedFunctionDRI = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.filter { it.name == "b" }.map { it.dri }.single() + + assertTrue(nestedFunctionDRI.classNames == "A") + } + } + } + + @Test + fun `should correctly handle object methods`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |object A { + | fun b() {} + |} + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val nestedFunctionDRI = module.packages.flatMap { it.classlikes }.flatMap { it.functions }.filter { it.name == "b" }.map { it.dri }.single() + + assertTrue(nestedFunctionDRI.classNames == "A") + } + } + } + + @Test + fun `should correctly handle enum functions`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |enum class A(private val x: Int) { + | X(0); + | fun b() = x + |} + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val nestedFunctionDRI = (module.packages.single().classlikes.single() as DEnum).functions.filter { it.name == "b" }.map { it.dri }.single() + + assertTrue(nestedFunctionDRI.classNames == "A") + } + } + } + + @Test + fun `should correctly handle nested classes' constructors`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |class A { + | class B(val x: String) + |} + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val constructorDRI = (module.packages.flatMap { it.classlikes }.flatMap { it.classlikes }.single() as DClass).constructors.single().dri + assertTrue(constructorDRI.classNames == "A.B") + } + } + } +} |