-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for nested classes in Kotlin as Java
- Loading branch information
1 parent
8830332
commit 2b224e2
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
plugins/kotlin-as-java/src/test/kotlin/DRITranslationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package kotlinAsJavaPlugin | ||
|
||
|
||
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest | ||
import org.jetbrains.dokka.model.DClass | ||
import org.jetbrains.dokka.model.DEnum | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
|
||
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") | ||
} | ||
} | ||
} | ||
} |