/
SuppressTagFilterTest.kt
207 lines (197 loc) · 6.09 KB
/
SuppressTagFilterTest.kt
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
package transformers
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.model.WithCompanion
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
class SuppressTagFilterTest : BaseAbstractTest() {
private val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src")
}
}
}
@Test
fun `should filter classes with suppress tag`() {
testInline(
"""
|/src/suppressed/NotSuppressed.kt
|/**
| * sample docs
|*/
|class NotSuppressed
|/src/suppressed/Suppressed.kt
|/**
| * sample docs
| * @suppress
|*/
|class Suppressed
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
assertEquals(
"NotSuppressed",
modules.flatMap { it.packages }.flatMap { it.classlikes }.singleOrNull()?.name
)
}
}
}
@Test
fun `should filter functions with suppress tag`() {
testInline(
"""
|/src/suppressed/Suppressed.kt
|class Suppressed {
| /**
| * sample docs
| * @suppress
| */
| fun suppressedFun(){ }
|}
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
assertNull(modules.flatMap { it.packages }.flatMap { it.classlikes }.flatMap { it.functions }
.firstOrNull { it.name == "suppressedFun" })
}
}
}
@Test
fun `should filter top level functions`() {
testInline(
"""
|/src/suppressed/Suppressed.kt
|/**
| * sample docs
| * @suppress
| */
|fun suppressedFun(){ }
|
|/**
| * Sample
| */
|fun notSuppressedFun() { }
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
assertNull(modules.flatMap { it.packages }.flatMap { it.functions }
.firstOrNull { it.name == "suppressedFun" })
}
}
}
@Test
fun `should filter setter`() {
testInline(
"""
|/src/suppressed/Suppressed.kt
|var property: Int
|/** @suppress */
|private set
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
val prop = modules.flatMap { it.packages }.flatMap { it.properties }
.find { it.name == "property" }
assertNotNull(prop)
assertNotNull(prop.getter)
assertNull(prop.setter)
}
}
}
@Test
fun `should filter top level type aliases`() {
testInline(
"""
|/src/suppressed/suppressed.kt
|/**
| * sample docs
| * @suppress
| */
|typealias suppressedTypeAlias = String
|
|/**
| * Sample
| */
|typealias notSuppressedTypeAlias = String
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
assertNull(modules.flatMap { it.packages }.flatMap { it.typealiases }
.firstOrNull { it.name == "suppressedTypeAlias" })
assertNotNull(modules.flatMap { it.packages }.flatMap { it.typealiases }
.firstOrNull { it.name == "notSuppressedTypeAlias" })
}
}
}
@Test
fun `should filter companion object`() {
testInline(
"""
|/src/suppressed/Suppressed.kt
|class Suppressed {
|/**
| * @suppress
| */
|companion object {
| val x = 1
|}
|}
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
assertNull((modules.flatMap { it.packages }.flatMap { it.classlikes }
.firstOrNull { it.name == "Suppressed" } as? WithCompanion)?.companion)
}
}
}
@Test
fun `should suppress inner classlike`() {
testInline(
"""
|/src/suppressed/Testing.kt
|class Testing {
| /**
| * Sample
| * @suppress
| */
| inner class Suppressed {
| val x = 1
| }
|}
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
val testingClass = modules.flatMap { it.packages }.flatMap { it.classlikes }.single()
assertNull(testingClass.classlikes.firstOrNull())
}
}
}
@Test
fun `should suppress enum entry`() {
testInline(
"""
|/src/suppressed/Testing.kt
|enum class Testing {
| /**
| * Sample
| * @suppress
| */
| SUPPRESSED,
|
| /**
| * Not suppressed
| */
| NOT_SUPPRESSED
|}
""".trimIndent(), configuration
) {
preMergeDocumentablesTransformationStage = { modules ->
val testingClass = modules.flatMap { it.packages }.flatMap { it.classlikes }.single() as DEnum
assertEquals(listOf("NOT_SUPPRESSED"), testingClass.entries.map { it.name })
}
}
}
}