From 50e711d24b517bc93c37d89f258c9dafaa038ad1 Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Mon, 20 Jan 2020 14:55:42 +0100 Subject: kotlin-as-java plugin --- .../src/test/kotlin/KotlinAsJavaPluginTest.kt | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt new file mode 100644 index 00000000..c0833293 --- /dev/null +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -0,0 +1,98 @@ +package kotlinAsJavaPlugin + +import junit.framework.Assert.fail +import org.jetbrains.dokka.pages.ContentGroup +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.ContentTable +import org.jetbrains.dokka.pages.children +import org.junit.Test +import testApi.testRunner.AbstractCoreTest + +class KotlinAsJavaPluginTest : AbstractCoreTest() { + + @Test + fun topLevelTest() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |object TestObj {} + | + |fun testFL(l: List) = l + |fun testF() {} + |fun testF2(i: Int) = i + |fun testF3(to: TestObj) = to + |fun testF4(t: T) = listOf(t) + |val testV = 1 + """, + configuration, + cleanupOutput = true + ) { + pagesGenerationStage = { root -> + val content = (root.children.firstOrNull()?.children?.firstOrNull() as? ContentPage )?.content ?: run { + fail("Either children or content is null") + } + + val children = + if (content is ContentGroup) + content.children.filterIsInstance().filter { it.children.isNotEmpty() } + else emptyList() + + children.assertCount(2) + } + } + } + + @Test + fun topLevelWithClassTest() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |class Test { + | fun testFC() {} + | val testVC = 1 + |} + | + |fun testF(i: Int) = i + |val testV = 1 + """, + configuration, + cleanupOutput = true + ) { + pagesGenerationStage = { root -> + val contentList = root.children + .flatMap { it.children() } + .map { it.content } + + val children = contentList.flatMap { content -> + if (content is ContentGroup) + content.children.filterIsInstance().filter { it.children.isNotEmpty() } + else emptyList() + }.filterNot { it.toString().contains("") } + + children.assertCount(4) + } + } + } + + private fun Collection.assertCount(n: Int) = + assert(count() == n) { "Expected $n, got ${count()}" } + +} \ No newline at end of file -- cgit From af9697cbd2eb1a26c8a07d191ca6360d416a1666 Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Tue, 11 Feb 2020 15:57:29 +0100 Subject: kotlin-as-java fixed --- .../src/test/kotlin/KotlinAsJavaPluginTest.kt | 53 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index c0833293..6186283f 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -1,6 +1,5 @@ package kotlinAsJavaPlugin -import junit.framework.Assert.fail import org.jetbrains.dokka.pages.ContentGroup import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.ContentTable @@ -10,6 +9,8 @@ import testApi.testRunner.AbstractCoreTest class KotlinAsJavaPluginTest : AbstractCoreTest() { + fun fail(msg: String) = assert(false) { msg } + @Test fun topLevelTest() { val configuration = dokkaConfiguration { @@ -37,7 +38,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { cleanupOutput = true ) { pagesGenerationStage = { root -> - val content = (root.children.firstOrNull()?.children?.firstOrNull() as? ContentPage )?.content ?: run { + val content = (root.children.firstOrNull()?.children?.firstOrNull() as? ContentPage)?.content ?: run { fail("Either children or content is null") } @@ -92,7 +93,51 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { } } - private fun Collection.assertCount(n: Int) = - assert(count() == n) { "Expected $n, got ${count()}" } + @Test + fun kotlinAndJavaTest() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |fun testF(i: Int) = i + |/src/main/kotlin/kotlinAsJavaPlugin/TestJ.java + |package kotlinAsJavaPlugin + | + |class TestJ { + | int testF(int i) { return i; } + |} + """, + configuration, + cleanupOutput = true + ) { + pagesGenerationStage = { root -> + val classes = root.children.first().children.associateBy { it.name } + classes.values.assertCount(2, "Class count: ") + + classes["TestKt"].let { + it?.children.orEmpty().assertCount(1, "(Kotlin) TestKt members: ") + it!!.children.first() + .let { assert(it.name == "testF") { "(Kotlin) Expected method name: testF, got: ${it.name}" } } + } + + classes["TestJ"].let { + it?.children.orEmpty().assertCount(1, "(Java) TestJ members: ") + it!!.children.first() + .let { assert(it.name == "testF") { "(Java) Expected method name: testF, got: ${it.name}" } } + } + } + } + } + + private fun Collection.assertCount(n: Int, prefix: String = "") = + assert(count() == n) { "${prefix}Expected $n, got ${count()}" } } \ No newline at end of file -- cgit From ac590359174995a16a116a96dbb9df5dafa042f5 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Fri, 28 Feb 2020 16:30:17 +0100 Subject: Test api moved to sensible package --- plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 6186283f..780f326a 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -5,7 +5,7 @@ import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.ContentTable import org.jetbrains.dokka.pages.children import org.junit.Test -import testApi.testRunner.AbstractCoreTest +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest class KotlinAsJavaPluginTest : AbstractCoreTest() { -- cgit From 4002c4e91cb42ef77e93cac57ac49823629d33da Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Thu, 27 Feb 2020 14:50:27 +0100 Subject: Add expect with generation --- plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 780f326a..2a9ddf0e 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -4,8 +4,8 @@ import org.jetbrains.dokka.pages.ContentGroup import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.ContentTable import org.jetbrains.dokka.pages.children -import org.junit.Test import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Test class KotlinAsJavaPluginTest : AbstractCoreTest() { -- cgit From ec5990f948647c245a5f7996bb8a9f62ccc6a3c5 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Mon, 23 Mar 2020 08:51:16 +0100 Subject: Add extracting Main content group from kotlin-as-java tests --- .../src/test/kotlin/KotlinAsJavaPluginTest.kt | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 2a9ddf0e..968ab65a 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -1,9 +1,6 @@ package kotlinAsJavaPlugin -import org.jetbrains.dokka.pages.ContentGroup -import org.jetbrains.dokka.pages.ContentPage -import org.jetbrains.dokka.pages.ContentTable -import org.jetbrains.dokka.pages.children +import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Test @@ -38,14 +35,11 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { cleanupOutput = true ) { pagesGenerationStage = { root -> - val content = (root.children.firstOrNull()?.children?.firstOrNull() as? ContentPage)?.content ?: run { - fail("Either children or content is null") - } + val content = (root.children.single().children.first { it.name == "TestKt" } as ContentPage).content - val children = - if (content is ContentGroup) - content.children.filterIsInstance().filter { it.children.isNotEmpty() } - else emptyList() + val children = content.mainContents + .filterIsInstance() + .filter { it.children.isNotEmpty() } children.assertCount(2) } @@ -83,9 +77,9 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { .map { it.content } val children = contentList.flatMap { content -> - if (content is ContentGroup) - content.children.filterIsInstance().filter { it.children.isNotEmpty() } - else emptyList() + content.mainContents + .filterIsInstance() + .filter { it.children.isNotEmpty() } }.filterNot { it.toString().contains("") } children.assertCount(4) @@ -140,4 +134,9 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { private fun Collection.assertCount(n: Int, prefix: String = "") = assert(count() == n) { "${prefix}Expected $n, got ${count()}" } -} \ No newline at end of file +} + +private val ContentNode.mainContents: List + get() = (this as ContentGroup).children + .filterIsInstance() + .single { it.dci.kind == ContentKind.Main }.children -- cgit From 091294c5a920521df1b4bf61c2492b78f3559321 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 20 May 2020 17:58:31 +0200 Subject: Tabs for sections - update tests --- .../kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 968ab65a..db87051b 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -2,12 +2,12 @@ package kotlinAsJavaPlugin import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jetbrains.kotlin.utils.addToStdlib.cast +import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.junit.jupiter.api.Test class KotlinAsJavaPluginTest : AbstractCoreTest() { - fun fail(msg: String) = assert(false) { msg } - @Test fun topLevelTest() { val configuration = dokkaConfiguration { @@ -37,8 +37,8 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { pagesGenerationStage = { root -> val content = (root.children.single().children.first { it.name == "TestKt" } as ContentPage).content - val children = content.mainContents - .filterIsInstance() + val children = content.mainContents.first().cast() + .children.filterIsInstance() .filter { it.children.isNotEmpty() } children.assertCount(2) @@ -77,7 +77,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { .map { it.content } val children = contentList.flatMap { content -> - content.mainContents + content.mainContents.first().cast().children .filterIsInstance() .filter { it.children.isNotEmpty() } }.filterNot { it.toString().contains("") } -- cgit From b0e8622f374f6499058b0f083367b4a54512b702 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 30 Jun 2020 23:06:03 +0200 Subject: Enforce workspace unique SourceSetID --- .../src/test/kotlin/KotlinAsJavaPluginTest.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index db87051b..96446201 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -3,7 +3,6 @@ package kotlinAsJavaPlugin import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jetbrains.kotlin.utils.addToStdlib.cast -import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.junit.jupiter.api.Test class KotlinAsJavaPluginTest : AbstractCoreTest() { @@ -11,8 +10,8 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { @Test fun topLevelTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -49,8 +48,8 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { @Test fun topLevelWithClassTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -90,8 +89,8 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { @Test fun kotlinAndJavaTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } -- cgit From 6377d964819f937bd4a7633488d69edc327542d8 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Mon, 6 Jul 2020 17:00:13 +0200 Subject: Java sources in Kotlin-As-Java plugin should have original property visibilites --- .../src/test/kotlin/KotlinAsJavaPluginTest.kt | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 96446201..ba513bf2 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -1,9 +1,11 @@ package kotlinAsJavaPlugin +import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jetbrains.kotlin.utils.addToStdlib.cast import org.junit.jupiter.api.Test +import matchers.content.* class KotlinAsJavaPluginTest : AbstractCoreTest() { @@ -130,6 +132,111 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { } } + @Test + fun `public kotlin properties should have a getter with same visibilities`(){ + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |class Test { + | public val publicProperty: String = "" + |} + """, + configuration, + cleanupOutput = true + ) { + pagesTransformationStage = { rootPageNode -> + val propertyGetter = rootPageNode.dfs { it is MemberPageNode && it.name == "getPublicProperty" } as? MemberPageNode + assert(propertyGetter != null) + propertyGetter!!.content.assertNode { + group { + header(1) { + +"getPublicProperty" + } + } + divergentGroup { + divergentInstance { + divergent { + group { + +"final" + group { + link { + +" String" + } + } + group { + link { + +"getPublicProperty" + } + +"()" + } + } + } + } + } + } + } + } + } + + @Test + fun `java properties should keep its modifiers`(){ + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/TestJ.java + |package kotlinAsJavaPlugin + | + |class TestJ { + | public Int publicProperty = 1; + |} + """, + configuration, + cleanupOutput = true + ) { + pagesGenerationStage = { root -> + val testClass = root.dfs { it.name == "TestJ" } as? ClasslikePageNode + assert(testClass != null) + (testClass!!.content as ContentGroup).children.last().assertNode { + group { + header(2){ + +"Properties" + } + table { + group { + link { + +"publicProperty" + } + platformHinted { + group { + +"public Int" + link { + +"publicProperty" + } + } + } + } + } + } + } + } + } + } + private fun Collection.assertCount(n: Int, prefix: String = "") = assert(count() == n) { "${prefix}Expected $n, got ${count()}" } -- cgit From 0104134b4891ccc97c27d4fee9846a9f74d46d0a Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Mon, 13 Jul 2020 16:46:36 +0200 Subject: Kotlin as Java should translate class kinds --- .../src/test/kotlin/KotlinAsJavaPluginTest.kt | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index ba513bf2..e12ec6cb 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -237,6 +237,58 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { } } + @Test + fun `koltin interfaces and classes should be split to extends and implements`(){ + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + | open class A { } + | interface B + | class C : A(), B + """, + configuration, + cleanupOutput = true + ) { + pagesGenerationStage = { root -> + val testClass = root.dfs { it.name == "C" } as? ClasslikePageNode + assert(testClass != null) + testClass!!.content.assertNode { + group { + header(expectedLevel = 1) { + +"C" + } + platformHinted { + group { + +"public final class" + link { + +"C" + } + +" extends " + link { + +"A" + } + +" implements " + link { + +"B" + } + } + } + } + skipAllNotMatching() + } + } + } + } + private fun Collection.assertCount(n: Int, prefix: String = "") = assert(count() == n) { "${prefix}Expected $n, got ${count()}" } -- cgit From f3dd48a464bbefcfdfc5c90f6c46453c67e803dd Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Mon, 13 Jul 2020 17:07:27 +0200 Subject: Remove unnecessary grouping in Java Signature Provider that caused signature to be in 2 lines --- plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'plugins/kotlin-as-java/src/test') diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index e12ec6cb..af66a48e 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -172,12 +172,10 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { +" String" } } - group { - link { - +"getPublicProperty" - } - +"()" + link { + +"getPublicProperty" } + +"()" } } } -- cgit