aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/markdown/KDocTest.kt
blob: 218f72443a3dee4865ce100f576134d4a9fffbdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package markdown

import org.jetbrains.dokka.model.DPackage
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.pages.ModulePageNode
import org.junit.jupiter.api.Assertions.*
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest

abstract class KDocTest : AbstractCoreTest() {

    private val configuration = dokkaConfiguration {
        passes {
            pass {
                sourceRoots = listOf("src/main/kotlin/example/Test.kt")
            }
        }
    }

    private fun interpolateKdoc(kdoc: String) = """
            |/src/main/kotlin/example/Test.kt
            |package example
            | /**
            ${kdoc.split("\n").joinToString("") { "| *$it\n" } }
            | */
            |class Test
        """.trimMargin()

    private fun actualDocumentationNode(modulePageNode: ModulePageNode) =
        (modulePageNode.documentable?.children?.first() as DPackage)
            .classlikes.single()
            .documentation.values.single()


    protected fun executeTest(kdoc: String, expectedDocumentationNode: DocumentationNode) {
        testInline(
            interpolateKdoc(kdoc),
            configuration
        ) {
            pagesGenerationStage = {
                assertEquals(
                    expectedDocumentationNode,
                    actualDocumentationNode(it as ModulePageNode)
                )
            }
        }
    }
}