aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/content
diff options
context:
space:
mode:
authorVadim Mishenev <vad-mishenev@yandex.ru>2022-12-16 01:27:30 +0200
committerGitHub <noreply@github.com>2022-12-16 01:27:30 +0200
commitb7a5eac3fc848501735b3520fc12f6f5d21b9bd4 (patch)
tree42c066549023a3d3ecb953b3c2ba71f07ae22e90 /plugins/base/src/test/kotlin/content
parentf6ea66cf10f399208ba5c8b01ad5bf323350f651 (diff)
downloaddokka-b7a5eac3fc848501735b3520fc12f6f5d21b9bd4.tar.gz
dokka-b7a5eac3fc848501735b3520fc12f6f5d21b9bd4.tar.bz2
dokka-b7a5eac3fc848501735b3520fc12f6f5d21b9bd4.zip
Display `SinceKotlin` everywhere (#2708)
* Introduce `extraOptions` * Make 'SinceKotlin' option * Display 'SinceKotlin' everywhere * Dump API * Fix CLI bug * Show custom tags in property brief * Show custom tags in extension brief * Show `SinceKotlin` for TypeAlias * Fix `stdlib.diff` * Add a test * Display doc for actual typealias * Propagate SinceKotlin * Refactor * Refactor in `SinceKotlinTransformer` * Revert "Introduce `extraOptions`" This reverts commit b83fdf5da31a97e2ae037f46a735d34a2f84d2ec. * Revert "Make 'SinceKotlin' option" This reverts commit 69f4641d1776f3a4bcd361919212c2de7fa2364e. * Introduce `dokka.SinceKotlin` system property instead of extra arg * Fix API * Fix tests * Rename * Spread on extensions * Put doc and rename prop
Diffstat (limited to 'plugins/base/src/test/kotlin/content')
-rw-r--r--plugins/base/src/test/kotlin/content/annotations/SinceKotlinTest.kt221
1 files changed, 216 insertions, 5 deletions
diff --git a/plugins/base/src/test/kotlin/content/annotations/SinceKotlinTest.kt b/plugins/base/src/test/kotlin/content/annotations/SinceKotlinTest.kt
index 84f5b647..d4a17869 100644
--- a/plugins/base/src/test/kotlin/content/annotations/SinceKotlinTest.kt
+++ b/plugins/base/src/test/kotlin/content/annotations/SinceKotlinTest.kt
@@ -1,15 +1,26 @@
package content.annotations
import matchers.content.*
-import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
+import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.base.transformers.pages.annotations.SinceKotlinTransformer
+import org.jetbrains.dokka.base.transformers.pages.annotations.SinceKotlinVersion
+import org.jetbrains.dokka.model.DFunction
+import org.jetbrains.dokka.model.dfs
+import org.jetbrains.dokka.model.doc.CustomTagWrapper
+import org.jetbrains.dokka.model.doc.Text
import org.jetbrains.dokka.pages.ContentPage
-import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.*
+import signatures.AbstractRenderingTest
import utils.ParamAttributes
+import utils.TestOutputWriterPlugin
+import utils.assertNotNull
import utils.bareSignature
+import kotlin.test.assertEquals
-class SinceKotlinTest : BaseAbstractTest() {
- private val testConfiguration = dokkaConfiguration {
+class SinceKotlinTest : AbstractRenderingTest() {
+
+ val testConfiguration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
@@ -18,8 +29,208 @@ class SinceKotlinTest : BaseAbstractTest() {
}
}
+ @BeforeEach
+ fun setSystemProperty() {
+ System.setProperty(SinceKotlinTransformer.SHOULD_DISPLAY_SINCE_KOTLIN_SYS_PROP, "true")
+ }
+ @AfterEach
+ fun clearSystemProperty() {
+ System.clearProperty(SinceKotlinTransformer.SHOULD_DISPLAY_SINCE_KOTLIN_SYS_PROP)
+ }
+
+ @Test
+ fun versionsComparing() {
+ assert(SinceKotlinVersion("1.0").compareTo(SinceKotlinVersion("1.0")) == 0)
+ assert(SinceKotlinVersion("1.0.0").compareTo(SinceKotlinVersion("1")) == 0)
+ assert(SinceKotlinVersion("1.0") >= SinceKotlinVersion("1.0"))
+ assert(SinceKotlinVersion("1.1") > SinceKotlinVersion("1"))
+ assert(SinceKotlinVersion("1.0") < SinceKotlinVersion("2.0"))
+ assert(SinceKotlinVersion("1.0") < SinceKotlinVersion("2.2"))
+ }
+
+ @Test
+ fun `rendered SinceKotlin custom tag for typealias, extensions, functions, properties`() {
+ val writerPlugin = TestOutputWriterPlugin()
+
+ testInline(
+ """
+ |/src/main/kotlin/test/source.kt
+ |package test
+ |
+ |@SinceKotlin("1.5")
+ |fun ring(abc: String): String {
+ | return "My precious " + abc
+ |}
+ |@SinceKotlin("1.5")
+ |fun String.extension(abc: String): String {
+ | return "My precious " + abc
+ |}
+ |@SinceKotlin("1.5")
+ |typealias Str = String
+ |@SinceKotlin("1.5")
+ |val str = "str"
+ """.trimIndent(),
+ testConfiguration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ val content = writerPlugin.renderedContent("root/test/index.html")
+ assert(content.getElementsContainingOwnText("Since Kotlin").count() == 4)
+ }
+ }
+ }
+
+ @Test
+ fun `should propagate SinceKotlin`() {
+ testInline(
+ """
+ |/src/main/kotlin/test/source.kt
+ |package test
+ |
+ |@SinceKotlin("1.5")
+ |class A {
+ | fun ring(abc: String): String {
+ | return "My precious " + abc
+ | }
+ |}
+ """.trimIndent(), testConfiguration
+ ) {
+ documentablesTransformationStage = { module ->
+ @Suppress("UNCHECKED_CAST") val funcs = module.children.single { it.name == "test" }
+ .children.single { it.name == "A" }
+ .children.filter { it.name == "ring" && it is DFunction } as List<DFunction>
+ with(funcs) {
+ val sinceKotlin = mapOf(
+ Platform.jvm to SinceKotlinVersion("1.5"),
+ )
+
+ for(i in sinceKotlin) {
+ val tag =
+ find { it.sourceSets.first().analysisPlatform == i.key }?.documentation?.values?.first()
+ ?.dfs { it is CustomTagWrapper && it.name == "Since Kotlin" }
+ .assertNotNull("SinceKotlin[${i.key}]")
+ assertEquals((tag.children.first() as Text).body, i.value.toString())
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ fun `mpp fun without SinceKotlin annotation`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "jvm"
+ }
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "native"
+ }
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "common"
+ }
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "js"
+ }
+ }
+ }
+ testInline(
+ """
+ |/src/main/kotlin/test/source.kt
+ |package test
+ |
+ |fun ring(abc: String): String {
+ | return "My precious " + abc
+ |}
+ """.trimIndent(), configuration
+ ) {
+ documentablesTransformationStage = { module ->
+ @Suppress("UNCHECKED_CAST") val funcs = module.children.single { it.name == "test" }
+ .children.filter { it.name == "ring" && it is DFunction } as List<DFunction>
+ with(funcs) {
+ val sinceKotlin = mapOf(
+ Platform.common to SinceKotlinVersion("1.2"),
+ Platform.jvm to SinceKotlinVersion("1.0"),
+ Platform.js to SinceKotlinVersion("1.1"),
+ Platform.native to SinceKotlinVersion("1.3")
+ )
+
+ for(i in sinceKotlin) {
+ val tag =
+ find { it.sourceSets.first().analysisPlatform == i.key }?.documentation?.values?.first()
+ ?.dfs { it is CustomTagWrapper && it.name == "Since Kotlin" }
+ .assertNotNull("SinceKotlin[${i.key}]")
+ assertEquals((tag.children.first() as Text).body, i.value.toString())
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ fun `mpp fun with SinceKotlin annotation`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "jvm"
+ }
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "native"
+ }
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "common"
+ }
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "js"
+ }
+ }
+ }
+ testInline(
+ """
+ |/src/main/kotlin/test/source.kt
+ |package test
+ |
+ |/** dssdd */
+ |@SinceKotlin("1.3")
+ |fun ring(abc: String): String {
+ | return "My precious " + abc
+ |}
+ """.trimIndent(), configuration
+ ) {
+ documentablesTransformationStage = { module ->
+ @Suppress("UNCHECKED_CAST") val funcs = module.children.single { it.name == "test" }
+ .children.filter { it.name == "ring" && it is DFunction } as List<DFunction>
+ with(funcs) {
+ val sinceKotlin = mapOf(
+ Platform.common to SinceKotlinVersion("1.3"),
+ Platform.jvm to SinceKotlinVersion("1.3"),
+ Platform.js to SinceKotlinVersion("1.3"),
+ Platform.native to SinceKotlinVersion("1.3")
+ )
+
+ for(i in sinceKotlin) {
+ val tag =
+ find { it.sourceSets.first().analysisPlatform == i.key }?.documentation?.values?.first()
+ ?.dfs { it is CustomTagWrapper && it.name == "Since Kotlin" }
+ .assertNotNull("SinceKotlin[${i.key}]")
+ assertEquals((tag.children.first() as Text).body, i.value.toString())
+ }
+ }
+ }
+ }
+ }
+
@Test
- fun `function with since kotlin annotation`() {
+ fun `should do not render since kotlin tag when flag is unset`() {
+ clearSystemProperty()
testInline(
"""
|/src/main/kotlin/test/source.kt