-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix source link to the line with name (#2724)
- Loading branch information
Showing
4 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package transformers | ||
|
||
import org.jetbrains.dokka.SourceLinkDefinitionImpl | ||
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest | ||
import org.junit.jupiter.api.Test | ||
import signatures.renderedContent | ||
import utils.TestOutputWriterPlugin | ||
import java.net.URL | ||
import kotlin.test.assertEquals | ||
import org.jsoup.nodes.Element | ||
|
||
class SourceLinkTransformerTest : BaseAbstractTest() { | ||
|
||
private fun Element.getSourceLink() = select(".symbol .floating-right") | ||
.select("a[href]") | ||
.attr("href") | ||
|
||
@Test | ||
fun `source link should lead to name`() { | ||
val configuration = dokkaConfiguration { | ||
sourceSets { | ||
sourceSet { | ||
sourceRoots = listOf("src/") | ||
sourceLinks = listOf( | ||
SourceLinkDefinitionImpl( | ||
localDirectory = "src/main/kotlin", | ||
remoteUrl = URL("https://github.com/user/repo/tree/master/src/main/kotlin"), | ||
remoteLineSuffix = "#L" | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
val writerPlugin = TestOutputWriterPlugin() | ||
|
||
testInline( | ||
""" | ||
|/src/main/kotlin/basic/Deprecated.kt | ||
|package testpackage | ||
| | ||
|/** | ||
|* Marks the annotated declaration as deprecated. ... | ||
|*/ | ||
|@Target(CLASS, FUNCTION, PROPERTY, ANNOTATION_CLASS, CONSTRUCTOR, PROPERTY_SETTER, PROPERTY_GETTER, TYPEALIAS) | ||
|@MustBeDocumented | ||
|public annotation class Deprecated( | ||
| val message: String, | ||
| val replaceWith: ReplaceWith = ReplaceWith(""), | ||
| val level: DeprecationLevel = DeprecationLevel.WARNING | ||
|) | ||
""".trimMargin(), | ||
configuration, | ||
pluginOverrides = listOf(writerPlugin) | ||
) { | ||
renderingStage = { _, _ -> | ||
val page = writerPlugin.writer.renderedContent("root/testpackage/-deprecated/index.html") | ||
val sourceLink = page.getSourceLink() | ||
|
||
assertEquals( | ||
"https://github.com/user/repo/tree/master/src/main/kotlin/basic/Deprecated.kt#L8", | ||
sourceLink | ||
) | ||
} | ||
} | ||
} | ||
} |