diff options
author | Valentin Rocher <valentin.rocher@webedia-group.com> | 2021-02-04 08:20:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-04 08:20:18 +0100 |
commit | 47682aee8b32f9e01940e962978cc2c6c7f38e86 (patch) | |
tree | f7782bcb1915c3dc9716a6feb1a45110330df652 /plugins/kotlin-as-java/src/test | |
parent | f8b741b0a3c78160af7e632011c39186fc259c0c (diff) | |
download | dokka-47682aee8b32f9e01940e962978cc2c6c7f38e86.tar.gz dokka-47682aee8b32f9e01940e962978cc2c6c7f38e86.tar.bz2 dokka-47682aee8b32f9e01940e962978cc2c6c7f38e86.zip |
JvmOverloads (#1712)
* add JvmOverloads support and static modifier for top-level functions
* apply requested changed
* revert auto-imports
Diffstat (limited to 'plugins/kotlin-as-java/src/test')
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/JvmOverloadsTest.kt | 56 | ||||
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 33 |
2 files changed, 89 insertions, 0 deletions
diff --git a/plugins/kotlin-as-java/src/test/kotlin/JvmOverloadsTest.kt b/plugins/kotlin-as-java/src/test/kotlin/JvmOverloadsTest.kt new file mode 100644 index 00000000..79619215 --- /dev/null +++ b/plugins/kotlin-as-java/src/test/kotlin/JvmOverloadsTest.kt @@ -0,0 +1,56 @@ +package kotlinAsJavaPlugin + +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class JvmOverloadsTest : BaseAbstractTest() { + private val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + classpath += jvmStdlibPath!! + } + } + } + + @Test + fun `should generate multiple functions`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |@JvmOverloads + |fun sample(a: Int = 0, b: String, c: Int = 0): String = "" + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val functions = module.packages.flatMap { it.classlikes }.flatMap { it.functions } + assertEquals(3, functions.size) + assertEquals(3, functions[0].parameters.size) + assertEquals(2, functions[1].parameters.size) + assertEquals(1, functions[2].parameters.size) + } + } + } + + @Test + fun `should do nothing if there is no default values`() { + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/sample.kt + |package kotlinAsJavaPlugin + |@JvmOverloads + |fun sample(a: Int, b: String, c: Int): String = "" + """.trimMargin(), + configuration, + ) { + documentablesTransformationStage = { module -> + val functions = module.packages.flatMap { it.classlikes }.flatMap { it.functions } + assertEquals(1, functions.size) + assertEquals(3, functions[0].parameters.size) + } + } + } +}
\ 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 8e7b798a..760bfcff 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -404,6 +404,39 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() { } } } + + @Test + fun `function in top level`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + externalDocumentationLinks = listOf( + DokkaConfiguration.ExternalDocumentationLink.jdk(8), + stdlibExternalDocumentationLink + ) + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |fun sample(a: Int) = "" + """.trimMargin(), + configuration, + pluginOverrides = listOf(writerPlugin), + cleanupOutput = true + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-test-kt/sample.html").signature().first().match( + "final static ", A("String"), A("sample"), "(", A("Integer"), "a)", Span() + ) + } + } + } } private val ContentNode.mainContents: List<ContentNode> |