aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/content/samples
diff options
context:
space:
mode:
authorAndrey Tyrin <andrei.tyrin@jetbrains.com>2023-01-09 13:28:05 +0100
committerGitHub <noreply@github.com>2023-01-09 13:28:05 +0100
commitc3aa879c3c77233c401cf314d736bf20891991ba (patch)
tree8f5ee6cff051069f72f88b6d86c9339ce02d599f /plugins/base/src/test/kotlin/content/samples
parent5ad955f28bde39d2f9e972bd3ec2c341579d9474 (diff)
downloaddokka-c3aa879c3c77233c401cf314d736bf20891991ba.tar.gz
dokka-c3aa879c3c77233c401cf314d736bf20891991ba.tar.bz2
dokka-c3aa879c3c77233c401cf314d736bf20891991ba.zip
Move inheritors, params, see also and samples tabs to description for classlikes (#2749)
Diffstat (limited to 'plugins/base/src/test/kotlin/content/samples')
-rw-r--r--plugins/base/src/test/kotlin/content/samples/ContentForSamplesTest.kt192
1 files changed, 192 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/content/samples/ContentForSamplesTest.kt b/plugins/base/src/test/kotlin/content/samples/ContentForSamplesTest.kt
new file mode 100644
index 00000000..37009e46
--- /dev/null
+++ b/plugins/base/src/test/kotlin/content/samples/ContentForSamplesTest.kt
@@ -0,0 +1,192 @@
+package content.samples
+
+import matchers.content.*
+import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
+import org.jetbrains.dokka.model.DisplaySourceSet
+import org.junit.jupiter.api.Test
+import utils.classSignature
+import utils.findTestType
+import java.nio.file.Paths
+import kotlin.test.assertEquals
+
+class ContentForSamplesTest : BaseAbstractTest() {
+ private val testDataDir = getTestDataDir("content/samples").toAbsolutePath()
+
+ private val testConfiguration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "jvm"
+ samples = listOf(
+ Paths.get("$testDataDir/samples.kt").toString(),
+ )
+ }
+ }
+ }
+
+ private val mppTestConfiguration = dokkaConfiguration {
+ moduleName = "example"
+ sourceSets {
+ val common = sourceSet {
+ name = "common"
+ displayName = "common"
+ analysisPlatform = "common"
+ sourceRoots = listOf("src/commonMain/kotlin/pageMerger/Test.kt")
+ samples = listOf(
+ Paths.get("$testDataDir/samples.kt").toString(),
+ )
+ }
+ sourceSet {
+ name = "jvm"
+ displayName = "jvm"
+ analysisPlatform = "jvm"
+ dependentSourceSets = setOf(common.value.sourceSetID)
+ sourceRoots = listOf("src/jvmMain/kotlin/pageMerger/Test.kt")
+ samples = listOf(
+ Paths.get("$testDataDir/samples.kt").toString(),
+ )
+ }
+ sourceSet {
+ name = "linuxX64"
+ displayName = "linuxX64"
+ analysisPlatform = "native"
+ dependentSourceSets = setOf(common.value.sourceSetID)
+ sourceRoots = listOf("src/linuxX64Main/kotlin/pageMerger/Test.kt")
+ samples = listOf(
+ Paths.get("$testDataDir/samples.kt").toString(),
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `samples block is rendered in the description`() {
+ testInline(
+ """
+ |/src/main/kotlin/test/source.kt
+ |package test
+ |
+ | /**
+ | * @sample [test.sampleForClassDescription]
+ | */
+ |class Foo
+ """.trimIndent(), testConfiguration
+ ) {
+ pagesTransformationStage = { module ->
+ val page = module.findTestType("test", "Foo")
+ page.content.assertNode {
+ group {
+ header(1) { +"Foo" }
+ platformHinted {
+ classSignature(
+ emptyMap(),
+ "",
+ "",
+ emptySet(),
+ "Foo"
+ )
+ header(4) { +"Samples" }
+ group {
+ codeBlock {
+ +"""|
+ |fun main() {
+ | //sampleStart
+ | print("Hello")
+ | //sampleEnd
+ |}""".trimMargin()
+ }
+ }
+ }
+ }
+ skipAllNotMatching()
+ }
+ }
+ }
+ }
+
+ @Test
+ fun `multiplatofrm class with samples in few platforms`() {
+ testInline(
+ """
+ |/src/commonMain/kotlin/pageMerger/Test.kt
+ |package pageMerger
+ |
+ |/**
+ |* @sample [test.sampleForClassDescription]
+ |*/
+ |expect open class Parent
+ |
+ |/src/jvmMain/kotlin/pageMerger/Test.kt
+ |package pageMerger
+ |
+ |/**
+ |* @sample unresolved
+ |*/
+ |actual open class Parent
+ |
+ |/src/linuxX64Main/kotlin/pageMerger/Test.kt
+ |package pageMerger
+ |
+ |actual open class Parent
+ |
+ """.trimMargin(),
+ mppTestConfiguration
+ ) {
+ pagesTransformationStage = { module ->
+ val page = module.findTestType("pageMerger", "Parent")
+ page.content.assertNode {
+ group {
+ header(1) { +"Parent" }
+ platformHinted {
+ group {
+ +"expect open class "
+ link {
+ +"Parent"
+ }
+ }
+ group {
+ +"actual open class "
+ link {
+ +"Parent"
+ }
+ }
+ group {
+ +"actual open class "
+ link {
+ +"Parent"
+ }
+ }
+ header(4) { +"Samples" }
+ group {
+ codeBlock {
+ +"""|
+ |fun main() {
+ | //sampleStart
+ | print("Hello")
+ | //sampleEnd
+ |}""".trimMargin()
+ }
+ check {
+ sourceSets.assertSourceSet("common")
+ }
+ }
+ group {
+ +"unresolved"
+ check {
+ sourceSets.assertSourceSet("jvm")
+ }
+ }
+ }
+ }
+ skipAllNotMatching()
+ }
+ }
+ }
+ }
+}
+
+
+private fun Set<DisplaySourceSet>.assertSourceSet(expectedName: String) {
+ assertEquals(1, this.size)
+ assertEquals(expectedName, this.first().name)
+} \ No newline at end of file