aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/content/receiver/ContentForReceiverTest.kt
blob: d739991427220ca68d37a9e63773b08c050d6954 (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
48
49
50
51
52
53
54
55
56
57
package content.receiver

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.model.doc.Receiver
import org.jetbrains.dokka.model.doc.Text
import org.jetbrains.dokka.pages.ContentHeader
import org.jetbrains.dokka.pages.ContentText
import org.jetbrains.dokka.pages.MemberPageNode
import org.junit.jupiter.api.Test
import utils.docs
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

class ContentForReceiverTest: BaseAbstractTest() {
    private val testConfiguration = dokkaConfiguration {
        sourceSets {
            sourceSet {
                sourceRoots = listOf("src/")
                analysisPlatform = "jvm"
            }
        }
    }

    @Test
    fun `should have docs for receiver`(){
        testInline(
            """
            |/src/main/kotlin/test/source.kt
            |package test
            |/**
            | * docs
            | * @receiver docs for string
            | */
            |fun String.asd2(): String = this
            """.trimIndent(),
            testConfiguration
        ){
            documentablesTransformationStage = { module ->
                with(module.packages.flatMap { it.functions }.first()){
                    val receiver = docs().firstOrNull { it is Receiver }
                    assertNotNull(receiver)
                    val content = receiver.dfs { it is Text } as Text
                    assertEquals("docs for string", content.body)
                }
            }
            pagesTransformationStage = { rootPageNode ->
                val functionPage = rootPageNode.dfs { it is MemberPageNode } as MemberPageNode
                val header = functionPage.content.dfs { it is ContentHeader && it.children.firstOrNull() is ContentText }
                val text = functionPage.content.dfs { it is ContentText && it.text == "docs for string" }

                assertNotNull(header)
                assertNotNull(text)
            }
        }
    }
}