Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Mar 20, 2024
1 parent 31da651 commit d937a1e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,40 +421,4 @@ class LinkableContentTest : BaseAbstractTest() {
}
}

@Test
fun `should have a correct url to an external inherited member #2879`() {
val writerPlugin = TestOutputWriterPlugin()
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
classpath = listOfNotNull(jvmStdlibPath)
}
}
}

testInline(
"""
/src/kotlin/main.kt
open interface C : Collection<C>
interface A : C()
interface B : C()
""".trimIndent()
,
pluginOverrides = listOf(writerPlugin),
configuration = configuration
) {
renderingStage = { rootPage, ctx ->
val location = DokkaLocationProvider(rootPage, ctx, ".html")
val classA = rootPage.dfs { it is ClasslikePageNode && it.name == "A" }
val classB = rootPage.dfs { it is ClasslikePageNode && it.name == "B" }
val classC = rootPage.dfs { it is ClasslikePageNode && it.name == "C" }
val sourceSet = (classA as ClasslikePageNode).content.sourceSets
val dri = org.jetbrains.dokka.links.DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList()))
assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classA))
assertEquals("index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classB))
assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classC))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
package locationProvider

import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider
import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider
import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
import org.jetbrains.dokka.base.resolvers.shared.PackageList
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.TypeConstructor
import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.pages.ClasslikePageNode
import org.jetbrains.dokka.plugability.DokkaContext
import utils.TestOutputWriterPlugin
import java.net.URL
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class DefaultExternalLocationProviderTest : BaseAbstractTest() {
private val testDataDir =
Expand Down Expand Up @@ -75,4 +80,82 @@ class DefaultExternalLocationProviderTest : BaseAbstractTest() {

assertEquals(null, locationProvider.resolve(dri))
}

@Test
fun `should have a correct url to an external inherited member #2879`() {
val writerPlugin = TestOutputWriterPlugin()
val configuration = dokkaConfiguration {


sourceSets {
sourceSet {
externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
sourceRoots = listOf("src/")
classpath = listOfNotNull(jvmStdlibPath)
}
}
}

testInline(
"""
/src/kotlin/main.kt
open interface C : Collection<C>
interface A : C()
interface B : C()
""".trimIndent()
,
pluginOverrides = listOf(writerPlugin),
configuration = configuration
) {
renderingStage = { rootPage, ctx ->
val location = DokkaLocationProvider(rootPage, ctx, ".html")
val classA = rootPage.dfs { it is ClasslikePageNode && it.name == "A" }
val classB = rootPage.dfs { it is ClasslikePageNode && it.name == "B" }
val classC = rootPage.dfs { it is ClasslikePageNode && it.name == "C" }
val sourceSet = (classA as ClasslikePageNode).content.sourceSets
val dri = DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList()))
assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classA))
assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classB))
assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classC))
}
}
}

@Test
fun `should have external links for external inherited members`() {
val writerPlugin = TestOutputWriterPlugin()
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
sourceRoots = listOf("src/")
classpath = listOfNotNull(jvmStdlibPath)
}
}
}

testInline(
"""
/src/kotlin/main.kt
interface MyCharSequence: CharSequence
""".trimIndent()
,
pluginOverrides = listOf(writerPlugin),
configuration = configuration
) {
renderingStage = { _, _ ->
"".chars()
val content = writerPlugin.writer.contents["root/[root]/-my-char-sequence/index.html"] ?: ""
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/length.html\"><span><span>length</span></span></a>"))
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/get.html\"><span><span>get</span></span></a>"))
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/sub-sequence.html\"><span>sub</span><wbr></wbr><span><span>Sequence</span></span></a>"))
// TODO #3542
// these links are invalid
// chars() and codePoints() are absent in https://kotlinlang.org/ since they come from mapping Kotlin to Java
// see https://kotlinlang.org/docs/java-interop.html#mapped-types
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/chars.html\"><span><span>chars</span></span></a>"))
assertTrue(content.contains("<a href=\"https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/code-points.html\"><span>code</span><wbr></wbr><span><span>Points</span></span></a>"))
}
}
}
}

0 comments on commit d937a1e

Please sign in to comment.