aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt
blob: 51a5e85ab4d3aa380e5ff307f92c564f456f8b71 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package transformers

import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
import org.jetbrains.dokka.base.transformers.documentables.ModuleAndPackageDocumentationReader
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.model.DPackage
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.testApi.logger.TestLogger
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import testApi.testRunner.TestDokkaConfigurationBuilder

class ContextModuleAndPackageDocumentationReaderTest1 : AbstractContextModuleAndPackageDocumentationReaderTest() {


    private val includeSourceSetA by lazy { temporaryDirectory.resolve("includeA.md").toFile() }
    private val includeSourceSetB by lazy { temporaryDirectory.resolve("includeB.md").toFile() }

    @BeforeEach
    fun materializeIncludes() {
        includeSourceSetA.writeText(
            """
            # Module moduleA
            This is moduleA
            
            # Package sample.a
            This is package sample.a
            
            # Package noise.b
            This will just add some noise
            """.trimIndent()
        )

        includeSourceSetB.writeText(
            """
            # Module moduleB
            This is moduleB
            
            # Package sample.b
            This is package sample.b
            
            # Package noise.b
            This will just add some more noise
            """.trimIndent()
        )
    }

    private val configurationBuilder = TestDokkaConfigurationBuilder().apply {
        moduleName = "moduleA"
    }

    private val sourceSetA by configurationBuilder.sourceSet {
        name = "sourceSetA"
        includes = listOf(includeSourceSetA.canonicalPath)
    }


    private val sourceSetB by configurationBuilder.sourceSet {
        name = "sourceSetB"
        includes = listOf(includeSourceSetB.canonicalPath)
    }


    private val sourceSetB2 by configurationBuilder.sourceSet {
        name = "sourceSetB2"
        includes = emptyList()
    }


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

    private val reader by lazy { ModuleAndPackageDocumentationReader(context) }

    @Test
    fun `assert moduleA with sourceSetA`() {
        val documentation = reader[DModule(name = "moduleA", sourceSets = setOf(sourceSetA))]
        assertEquals(
            1, documentation.keys.size,
            "Expected moduleA only containing documentation in a single source set"
        )
        assertEquals(
            "sourceSetA", documentation.keys.single().sourceSetID.sourceSetName,
            "Expected moduleA documentation coming from sourceSetA"
        )

        assertEquals(
            "This is moduleA", documentation.texts.single(),
            "Expected moduleA documentation being present"
        )
    }

    @Test
    fun `assert moduleA with no source sets`() {
        val documentation = reader[DModule("moduleA")]
        assertEquals(
            emptyMap<DokkaSourceSet, DocumentationNode>(), documentation,
            "Expected no documentation received for module not declaring a matching sourceSet"
        )
    }

    @Test
    fun `assert moduleA with unknown source set`() {
        val documentation = reader[
                DModule("moduleA", sourceSets = setOf(configurationBuilder.unattachedSourceSet { name = "unknown" }))
        ]
        assertEquals(
            emptyMap<DokkaSourceSet, DocumentationNode>(), documentation,
            "Expected no documentation received for module with unknown sourceSet"
        )
    }

    @Test
    fun `assert moduleA with all sourceSets`() {
        val documentation = reader[DModule("moduleA", sourceSets = setOf(sourceSetA, sourceSetB, sourceSetB2))]
        assertEquals(1, documentation.entries.size, "Expected only one entry from sourceSetA")
        assertEquals(sourceSetA, documentation.keys.single(), "Expected only one entry from sourceSetA")
        assertEquals("This is moduleA", documentation.texts.single())
    }

    @Test
    fun `assert moduleB with sourceSetB and sourceSetB2`() {
        val documentation = reader[DModule("moduleB", sourceSets = setOf(sourceSetB, sourceSetB2))]
        assertEquals(1, documentation.keys.size, "Expected only one entry from sourceSetB")
        assertEquals(sourceSetB, documentation.keys.single(), "Expected only one entry from sourceSetB")
        assertEquals("This is moduleB", documentation.texts.single())
    }

    @Test
    fun `assert sample_A in sourceSetA`() {
        val documentation = reader[DPackage(DRI("sample.a"), sourceSets = setOf(sourceSetA))]
        assertEquals(1, documentation.keys.size, "Expected only one entry from sourceSetA")
        assertEquals(sourceSetA, documentation.keys.single(), "Expected only one entry from sourceSetA")
        assertEquals("This is package sample.a", documentation.texts.single())
    }

    @Test
    fun `assert sample_a_sub in sourceSetA`() {
        val documentation = reader[DPackage(DRI("sample.a.sub"), sourceSets = setOf(sourceSetA))]
        assertEquals(
            emptyMap<DokkaSourceSet, DocumentationNode>(), documentation,
            "Expected no documentation found for different package"
        )
    }

    @Test
    fun `assert sample_a in sourceSetB`() {
        val documentation = reader[DPackage(DRI("sample.a"), sourceSets = setOf(sourceSetB))]
        assertEquals(
            emptyMap<DokkaSourceSet, DocumentationNode>(), documentation,
            "Expected no documentation found for different sourceSet"
        )
    }

    @Test
    fun `assert sample_b in sourceSetB`() {
        val documentation = reader[DPackage(DRI("sample.b"), sourceSets = setOf(sourceSetB))]
        assertEquals(1, documentation.keys.size, "Expected only one entry from sourceSetB")
        assertEquals(sourceSetB, documentation.keys.single(), "Expected only one entry from sourceSetB")
        assertEquals("This is package sample.b", documentation.texts.single())
    }

    @Test
    fun `assert sample_b in sourceSetB and sourceSetB2`() {
        val documentation = reader[DPackage(DRI("sample.b"), sourceSets = setOf(sourceSetB, sourceSetB2))]
        assertEquals(1, documentation.keys.size, "Expected only one entry from sourceSetB")
        assertEquals(sourceSetB, documentation.keys.single(), "Expected only one entry from sourceSetB")
        assertEquals("This is package sample.b", documentation.texts.single())
    }
}