aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2021-01-21 14:22:10 +0100
committerKamil Doległo <9080183+kamildoleglo@users.noreply.github.com>2021-01-22 10:38:05 +0100
commit2b224e220091ef3c8ed0446c4493f0d4c3a9541e (patch)
tree53a8d9f0bfda70ed4211a02bf066b4906159a6d8 /plugins/kotlin-as-java
parent88303321abb91b73a03fa62f44152e82fef0dc3a (diff)
downloaddokka-2b224e220091ef3c8ed0446c4493f0d4c3a9541e.tar.gz
dokka-2b224e220091ef3c8ed0446c4493f0d4c3a9541e.tar.bz2
dokka-2b224e220091ef3c8ed0446c4493f0d4c3a9541e.zip
Add tests for nested classes in Kotlin as Java
Diffstat (limited to 'plugins/kotlin-as-java')
-rw-r--r--plugins/kotlin-as-java/src/test/kotlin/DRITranslationTest.kt125
1 files changed, 125 insertions, 0 deletions
diff --git a/plugins/kotlin-as-java/src/test/kotlin/DRITranslationTest.kt b/plugins/kotlin-as-java/src/test/kotlin/DRITranslationTest.kt
new file mode 100644
index 00000000..257b17ff
--- /dev/null
+++ b/plugins/kotlin-as-java/src/test/kotlin/DRITranslationTest.kt
@@ -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")
+ }
+ }
+ }
+}