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

import org.jetbrains.dokka.DocumentationModule
import org.jetbrains.dokka.DocumentationNode
import org.jetbrains.dokka.KotlinAsJavaDocumentationBuilder
import org.junit.Test
import kotlin.test.assertEquals

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

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

            val fn = facadeClass.members.single()
            assertEquals("fn", fn.name)
            assertEquals(DocumentationNode.Kind.CompanionObjectFunction, fn.kind)
        }
    }

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

fun verifyModelAsJava(source: String,
                      withJdk: Boolean = false,
                      withKotlinRuntime: Boolean = false,
                      verifier: (DocumentationModule) -> Unit) {
    verifyModel(source,
            withJdk = withJdk, withKotlinRuntime = withKotlinRuntime,
            packageDocumentationBuilder = KotlinAsJavaDocumentationBuilder(),
            verifier = verifier)
}