aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/kotlin/model/KotlinAsJavaTest.kt
blob: b5c156183d51cb73d40d4454c576f0931552d6c7 (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 org.jetbrains.dokka.tests

import org.jetbrains.dokka.DocumentationModule
import org.jetbrains.dokka.NodeKind
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.RefKind
import org.junit.Assert
import org.junit.Test
import org.junit.Assert.assertEquals

class KotlinAsJavaTest {
    @Test fun function() {
        verifyModelAsJava("testdata/functions/function.kt") { model ->
            val pkg = model.members.single()

            val facadeClass = pkg.members.single { it.name == "FunctionKt" }
            assertEquals(NodeKind.Class, facadeClass.kind)

            val fn = facadeClass.members.single()
            assertEquals("fn", fn.name)
            assertEquals(NodeKind.Function, fn.kind)
        }
    }

    @Test fun propertyWithComment() {
        verifyModelAsJava("testdata/comments/oneLineDoc.kt") { model ->
            val facadeClass = model.members.single().members.single { it.name == "OneLineDocKt" }
            val getter = facadeClass.members.single { it.name == "getProperty" }
            assertEquals(NodeKind.Function, getter.kind)
            assertEquals("doc", getter.content.summary.toTestString())
        }
    }


    @Test fun constants() {
        verifyModelAsJava("testdata/java/constants.java") { cls ->
            selectNodes(cls) {
                subgraphOf(RefKind.Member)
                matching { it.name == "constStr" || it.name == "refConst" }
            }.forEach {
                assertEquals("In $it", "\"some value\"", it.detailOrNull(NodeKind.Value)?.name)
            }
            val nullConstNode = selectNodes(cls) {
                subgraphOf(RefKind.Member)
                withName("nullConst")
            }.single()

            Assert.assertNull(nullConstNode.detailOrNull(NodeKind.Value))
        }
    }
}

fun verifyModelAsJava(source: String,
                      modelConfig: ModelConfig = ModelConfig(),
                      verifier: (DocumentationModule) -> Unit) {
    checkSourceExistsAndVerifyModel(
        source,
        modelConfig = ModelConfig(
            withJdk = modelConfig.withJdk,
            withKotlinRuntime = modelConfig.withKotlinRuntime,
            format = "html-as-java",
            analysisPlatform = Platform.jvm),
        verifier = verifier
    )
}