Skip to content

Commit 02211ee

Browse files
authored
Add tests for #4338 and #4049 (#4361)
1 parent f82020d commit 02211ee

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

dokka-subprojects/plugin-base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,94 @@ class SourceLinkTransformerTest : BaseAbstractTest() {
128128
}
129129
}
130130
}
131+
132+
@Test
133+
fun `each declaration should include exactly one source link in the case #4338`() {
134+
val configuration = dokkaConfiguration {
135+
sourceSets {
136+
sourceSet {
137+
sourceRoots = listOf("src/")
138+
sourceLinks = listOf(
139+
SourceLinkDefinitionImpl(
140+
localDirectory = "src/main/kotlin",
141+
remoteUrl = URL("https://github.com/user/repo/tree/master/src/main/kotlin"),
142+
remoteLineSuffix = "#L"
143+
)
144+
)
145+
}
146+
}
147+
}
148+
149+
val writerPlugin = TestOutputWriterPlugin()
150+
151+
testInline(
152+
"""
153+
|/src/main/kotlin/basic/Deprecated.kt
154+
|package testpackage
155+
|
156+
|val ff = 0 // #4338
157+
|fun ff() = 0
158+
""".trimMargin(),
159+
configuration,
160+
pluginOverrides = listOf(writerPlugin)
161+
) {
162+
renderingStage = { _, _ ->
163+
val pageFf = writerPlugin.writer.renderedContent("root/testpackage/ff.html")
164+
fun Element.getAllSourceElements() = select(".symbol .source-link")
165+
assertEquals(
166+
2,
167+
pageFf.getAllSourceElements().size
168+
)
169+
assertEquals(
170+
listOf("https://github.com/user/repo/tree/master/src/main/kotlin/basic/Deprecated.kt#L4", "https://github.com/user/repo/tree/master/src/main/kotlin/basic/Deprecated.kt#L3"),
171+
pageFf.getAllSourceElements().map { it.select("a[href]").attr("href") }
172+
)
173+
}
174+
}
175+
}
176+
177+
@Test
178+
fun `each declaration should include exactly one source link in the case #4049`() {
179+
val configuration = dokkaConfiguration {
180+
sourceSets {
181+
sourceSet {
182+
sourceRoots = listOf("src/")
183+
sourceLinks = listOf(
184+
SourceLinkDefinitionImpl(
185+
localDirectory = "src/main/kotlin",
186+
remoteUrl = URL("https://github.com/user/repo/tree/master/src/main/kotlin"),
187+
remoteLineSuffix = "#L"
188+
)
189+
)
190+
}
191+
}
192+
}
193+
194+
val writerPlugin = TestOutputWriterPlugin()
195+
196+
testInline(
197+
"""
198+
|/src/main/kotlin/basic/Deprecated.kt
199+
|package testpackage
200+
|fun overloadWithVararg(novararg: String){} // #4049
201+
|fun overloadWithVararg(vararg elements: String){}
202+
""".trimMargin(),
203+
configuration,
204+
pluginOverrides = listOf(writerPlugin)
205+
) {
206+
renderingStage = { _, _ ->
207+
val pageOverloadWithVararg = writerPlugin.writer.renderedContent("root/testpackage/overload-with-vararg.html")
208+
fun Element.getAllSourceElements() = select(".symbol .source-link")
209+
210+
assertEquals(
211+
2,
212+
pageOverloadWithVararg.getAllSourceElements().size
213+
)
214+
assertEquals(
215+
listOf("https://github.com/user/repo/tree/master/src/main/kotlin/basic/Deprecated.kt#L2", "https://github.com/user/repo/tree/master/src/main/kotlin/basic/Deprecated.kt#L3"),
216+
pageOverloadWithVararg.getAllSourceElements().map { it.select("a[href]").attr("href") }
217+
)
218+
}
219+
}
220+
}
131221
}

0 commit comments

Comments
 (0)