aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/content/properties/ContentForClassWithParamsAndPropertiesTest.kt
blob: 164fa62da2be9351931bf2d3b23f98c90a62ea1d (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package content.properties

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.DClass
import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.pages.ClasslikePageNode
import org.jetbrains.dokka.pages.RootPageNode
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

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

    @Test
    fun `should work for a simple property`() {
        propertyTest { rootPage ->
            val node = rootPage.dfs { it.name == "LoadInitialParams" } as ClasslikePageNode
            val actualDocsForPlaceholdersEnabled =
                (node.documentables.firstOrNull() as DClass).constructors.first().parameters.find { it.name == "placeholdersEnabled" }
                    ?.documentation?.entries?.first()?.value
            assertEquals(DocumentationNode(listOf(docsForPlaceholdersEnabled)), actualDocsForPlaceholdersEnabled)
        }
    }

    @Test
    fun `should work for a simple with linebreak`() {
        propertyTest { rootPage ->
            val node = rootPage.dfs { it.name == "LoadInitialParams" } as ClasslikePageNode
            val actualDocsForRequestedLoadSize =
                (node.documentables.firstOrNull() as DClass).constructors.first().parameters.find { it.name == "requestedLoadSize" }
                    ?.documentation?.entries?.first()?.value
            assertEquals(DocumentationNode(listOf(docsForRequestedLoadSize)), actualDocsForRequestedLoadSize)
        }
    }

    @Test
    fun `should work with multiline property inline code`() {
        propertyTest { rootPage ->
            val node = rootPage.dfs { it.name == "LoadInitialParams" } as ClasslikePageNode

            val actualDocsForRequestedInitialKey =
                (node.documentables.firstOrNull() as DClass).constructors.first().parameters.find { it.name == "requestedInitialKey" }
                    ?.documentation?.entries?.first()?.value
            assertEquals(DocumentationNode(listOf(docsForRequestedInitialKey)), actualDocsForRequestedInitialKey)
        }
    }

    @Test
    fun `constructor should only the param and constructor tags`() {
        propertyTest { rootPage ->
            val constructorDocs = Description(
                root = CustomDocTag(
                    children = listOf(
                        P(
                            children = listOf(
                                Text("Creates an empty group.")
                            )
                        )
                    ),
                    emptyMap(), "MARKDOWN_FILE"
                )
            )
            val node = rootPage.dfs { it.name == "LoadInitialParams" } as ClasslikePageNode

            val actualDocs =
                (node.documentables.firstOrNull() as DClass).constructors.first().documentation.entries.first().value
            assertEquals(DocumentationNode(listOf(constructorDocs, docsForParam)), actualDocs)
        }
    }

    @Test
    fun `class should have all tags`() {
        propertyTest { rootPage ->
            val ownDescription = Description(
                root = CustomDocTag(
                    children = listOf(
                        P(
                            children = listOf(
                                Text("Holder object for inputs to loadInitial.")
                            )
                        )
                    ),
                    emptyMap(), "MARKDOWN_FILE"
                )
            )
            val node = rootPage.dfs { it.name == "LoadInitialParams" } as ClasslikePageNode

            val actualDocs =
                (node.documentables.firstOrNull() as DClass).documentation.entries.first().value
            assertEquals(
                DocumentationNode(
                    listOf(
                        ownDescription,
                        docsForParam,
                        docsForRequestedInitialKey,
                        docsForRequestedLoadSize,
                        docsForPlaceholdersEnabled,
                        docsForConstructor
                    )
                ),
                actualDocs
            )
        }
    }

    @Test
    fun `property should also work with own docs that override the param tag`() {
        propertyTest { rootPage ->
            val ownDescription = Description(
                root = CustomDocTag(
                    children = listOf(
                        P(
                            children = listOf(
                                Text("Own docs")
                            )
                        )
                    ),
                    emptyMap(), "MARKDOWN_FILE"
                )
            )
            val node = rootPage.dfs { it.name == "ItemKeyedDataSource" } as ClasslikePageNode

            val actualDocs =
                (node.documentables.firstOrNull() as DClass).properties.first().documentation.entries.first().value
            assertEquals(
                DocumentationNode(listOf(ownDescription)),
                actualDocs
            )
        }
    }


    private fun propertyTest(block: (RootPageNode) -> Unit) {
        testInline(
            """ |/src/main/kotlin/test/source.kt
                |package test
                |/**
                | * @property tested Docs from class
                | */
                |abstract class ItemKeyedDataSource<Key : Any, Value : Any> : DataSource<Key, Value>(ITEM_KEYED) {
                |    /** 
                |     * Own docs 
                |     */
                |    val tested = ""
                |
                |    /**
                |     * Holder object for inputs to loadInitial.
                |     *
                |     * @param Key Type of data used to query Value types out of the DataSource.
                |     * @property requestedInitialKey Load items around this key, or at the beginning of the data set
                |     * if `null` is passed.
                |     *
                |     * Note that this key is generally a hint, and may be ignored if you want to always load from
                |     * the beginning.
                |     * @property requestedLoadSize Requested number of items to load.
                |     *
                |     * Note that this may be larger than available data.
                |     * @property placeholdersEnabled Defines whether placeholders are enabled, and whether the
                |     * loaded total count will be ignored.
                |     * 
                |     * @constructor Creates an empty group.
                |     */
                |    open class LoadInitialParams<Key : Any>(
                |        @JvmField
                |        val requestedInitialKey: Key?,
                |        @JvmField
                |        val requestedLoadSize: Int,
                |        @JvmField
                |        val placeholdersEnabled: Boolean
                |    )
                |}""".trimIndent(), testConfiguration
        ) {
            pagesGenerationStage = block
        }
    }

    private val docsForPlaceholdersEnabled = Property(
        root = CustomDocTag(
            listOf(
                P(
                    children = listOf(
                        Text("Defines whether placeholders are enabled, and whether the loaded total count will be ignored.")
                    )
                )
            ), emptyMap(), "MARKDOWN_FILE"
        ),
        name = "placeholdersEnabled"
    )

    private val docsForRequestedInitialKey = Property(
        root = CustomDocTag(
            listOf(
                P(
                    children = listOf(
                        Text("Load items around this key, or at the beginning of the data set if "),
                        CodeInline(
                            listOf(
                                Text("null")
                            )
                        ),
                        Text(" is passed.")
                    ),
                    params = emptyMap()
                ),
                P(
                    children = listOf(
                        Text("Note that this key is generally a hint, and may be ignored if you want to always load from the beginning.")
                    )
                )
            ), emptyMap(), "MARKDOWN_FILE"
        ),
        name = "requestedInitialKey"
    )

    private val docsForRequestedLoadSize = Property(
        root = CustomDocTag(
            listOf(
                P(
                    children = listOf(
                        Text("Requested number of items to load.")
                    )
                ),
                P(
                    children = listOf(
                        Text("Note that this may be larger than available data.")
                    )
                )
            ), emptyMap(), "MARKDOWN_FILE"
        ),
        name = "requestedLoadSize"
    )

    private val docsForConstructor = Constructor(
        root = CustomDocTag(
            children = listOf(
                P(
                    children = listOf(
                        Text("Creates an empty group.")
                    )
                )
            ),
            emptyMap(), "MARKDOWN_FILE"
        )
    )

    private val docsForParam = Param(
        root = CustomDocTag(
            children = listOf(
                P(
                    children = listOf(
                        Text("Type of data used to query Value types out of the DataSource.")
                    )
                )
            ),
            emptyMap(), "MARKDOWN_FILE"
        ),
        name = "Key"
    )
}