aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/packageList/PackageListTest.kt
blob: 310a23c6d839e3131e783482fd009c94e572125e (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
package packageList

import org.jetbrains.dokka.base.renderers.PackageListService
import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class PackageListTest {
    @Test
    fun `one module package list is created correctly`() {
        val nonStandardLocations = mapOf("//longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/" to "[JS root]/long-array-with-fun.html")
        val modules = mapOf("" to setOf("foo", "bar", "baz"))
        val format = RecognizedLinkFormat.DokkaHtml
        val output = PackageListService.renderPackageList(nonStandardLocations, modules, format.formatName, format.linkExtension)
        val expected = """
            |${'$'}dokka.format:html-v1
            |${'$'}dokka.linkExtension:html
            |${'$'}dokka.location://longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/[JS root]/long-array-with-fun.html
            |bar
            |baz
            |foo
            |""".trimMargin()
        assertEquals(expected, output)
    }

    @Test
    fun `multi-module package list is created correctly`() {
        val nonStandardLocations = mapOf("//longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/" to "[JS root]/long-array-with-fun.html")
        val modules = mapOf("moduleA" to setOf("foo", "bar"), "moduleB" to setOf("baz"), "moduleC" to setOf("qux"))
        val format = RecognizedLinkFormat.DokkaHtml
        val output = PackageListService.renderPackageList(nonStandardLocations, modules, format.formatName, format.linkExtension)
        val expected = """
            |${'$'}dokka.format:html-v1
            |${'$'}dokka.linkExtension:html
            |${'$'}dokka.location://longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/[JS root]/long-array-with-fun.html
            |module:moduleA
            |bar
            |foo
            |module:moduleB
            |baz
            |module:moduleC
            |qux
            |""".trimMargin()
        assertEquals(expected, output)
    }

    @Test
    fun `empty package set in module`() {
        val nonStandardLocations = emptyMap<String, String>()
        val modules = mapOf("moduleA" to setOf("foo", "bar"), "moduleB" to emptySet(), "moduleC" to setOf("qux"))
        val format = RecognizedLinkFormat.DokkaHtml
        val output = PackageListService.renderPackageList(nonStandardLocations, modules, format.formatName, format.linkExtension)
        val expected = """
            |${'$'}dokka.format:html-v1
            |${'$'}dokka.linkExtension:html
            |
            |module:moduleA
            |bar
            |foo
            |module:moduleC
            |qux
            |""".trimMargin()
        assertEquals(expected, output)
    }
}