diff options
author | Vadim Mishenev <vad-mishenev@yandex.ru> | 2022-10-26 21:07:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 21:07:09 +0300 |
commit | d1b24984fdf6d2f383697b557086c62c94e4eee0 (patch) | |
tree | 037cd0ed9deafd2a174535458f3b5c0ab9b1635b /plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt | |
parent | 4c122a4d46f9f100e1508b602942c571067a1d88 (diff) | |
download | dokka-d1b24984fdf6d2f383697b557086c62c94e4eee0.tar.gz dokka-d1b24984fdf6d2f383697b557086c62c94e4eee0.tar.bz2 dokka-d1b24984fdf6d2f383697b557086c62c94e4eee0.zip |
Fix source link to the line with name (#2724)
Diffstat (limited to 'plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt')
-rw-r--r-- | plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt new file mode 100644 index 00000000..81b4db69 --- /dev/null +++ b/plugins/base/src/test/kotlin/transformers/SourceLinkTransformerTest.kt @@ -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 + ) + } + } + } +}
\ No newline at end of file |