aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt
blob: 4a8a81f2fb7e3a41b4fce356b239e1117ae0ccff (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 transformers

import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.jetbrains.dokka.utilities.LoggingLevel
import org.jetbrains.kotlin.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import testApi.testRunner.TestDokkaConfigurationBuilder
import testApi.testRunner.dPackage
import kotlin.test.assertEquals

class ContextModuleAndPackageDocumentationReaderTest3 : AbstractContextModuleAndPackageDocumentationReaderTest() {

    private val include by lazy { temporaryDirectory.resolve("include.md").toFile() }

    @BeforeEach
    fun materializeInclude() {
        include.writeText(
            """
            # Package
            This is the root package
            
            # Package [root]
            This is also the root package
            """.trimIndent()
        )
    }

    private val configurationBuilder = TestDokkaConfigurationBuilder()

    private val sourceSet by configurationBuilder.sourceSet {
        includes = listOf(include.canonicalPath)
    }

    private val context by lazy {
        DokkaContext.create(
            configuration = configurationBuilder.build(),
            logger = DokkaConsoleLogger(LoggingLevel.DEBUG),
            pluginOverrides = emptyList()
        )
    }

    private val reader by lazy { context.plugin<InternalKotlinAnalysisPlugin>().querySingle { moduleAndPackageDocumentationReader } }


    @Test
    fun `root package is matched by empty string and the root keyword`() {
        val documentation = reader.read(dPackage(DRI(""), sourceSets = setOf(sourceSet)))
        assertEquals(
            listOf("This is the root package", "This is also the root package"), documentation.texts
        )
    }
}