aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/locationProvider/Dokka010ExternalLocationProviderTest.kt
blob: 1a2a45d7a3a34cddf74be9e2f606d3297a7f3070 (plain)
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
package locationProvider

import org.jetbrains.dokka.ExternalDocumentationLink
import org.jetbrains.dokka.base.resolvers.external.Dokka010ExternalLocationProvider
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
import org.jetbrains.dokka.base.resolvers.shared.PackageList
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.TypeConstructor
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.net.URL

class Dokka010ExternalLocationProviderTest : AbstractCoreTest() {
    private val testDataDir =
        getTestDataDir("locationProvider").toAbsolutePath().toString().removePrefix("/").let { "/$it" }
    private val kotlinLang = "https://kotlinlang.org/api/latest/jvm/stdlib"
    private val packageListURL = URL("file://$testDataDir/old-package-list")
    private val configuration = dokkaConfiguration {
        sourceSets {
            sourceSet {
                sourceRoots = listOf("src/")
                classpath += jvmStdlibPath!!
                ExternalDocumentationLink(kotlinLang, packageListURL.toString())
            }
        }
    }

    private fun getTestLocationProvider(context: DokkaContext? = null): Dokka010ExternalLocationProvider {
        val dokkaContext = context ?: DokkaContext.create(configuration, logger, emptyList())
        val packageList = PackageList.load(packageListURL, 8, true)!!
        val externalDocumentation =
            ExternalDocumentation(URL(kotlinLang), packageList)
        return Dokka010ExternalLocationProvider(externalDocumentation, ".html", dokkaContext)
    }

    @Test
    fun `ordinary link`() {
        val locationProvider = getTestLocationProvider()
        val dri = DRI("kotlin.reflect", "KVisibility")

        assertEquals("$kotlinLang/kotlin.reflect/-k-visibility/index.html", locationProvider.resolve(dri))
    }

    @Test
    fun `relocation in package list`() {
        val locationProvider = getTestLocationProvider()
        val dri = DRI("kotlin.text", "StringBuilder")

        assertEquals("$kotlinLang/kotlin.relocated.text/-string-builder/index.html", locationProvider.resolve(dri))
    }

    @Test
    fun `method relocation in package list`() {
        val locationProvider = getTestLocationProvider()
        val dri = DRI(
            "kotlin",
            "",
            Callable(
                "minus",
                null,
                listOf(
                    TypeConstructor("java.math.BigDecimal", emptyList()),
                    TypeConstructor("java.math.BigDecimal", emptyList())
                )
            )
        )

        assertEquals("$kotlinLang/kotlin/java.math.-big-decimal/minus.html", locationProvider.resolve(dri))
    }
}