package signatures
import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.DFunction
import org.jetbrains.dokka.model.DefinitelyNonNullable
import org.jetbrains.dokka.model.dfs
import org.junit.jupiter.api.Test
import utils.*
import kotlin.test.assertEquals
import kotlin.test.assertFalse
class SignatureTest : BaseAbstractTest() {
private val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
classpath = listOf(
commonStdlibPath ?: throw IllegalStateException("Common stdlib is not found"),
jvmStdlibPath ?: throw IllegalStateException("JVM stdlib is not found")
)
externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
}
}
}
private val mppConfiguration = dokkaConfiguration {
moduleName = "test"
sourceSets {
sourceSet {
name = "common"
sourceRoots = listOf("src/main/kotlin/common/Test.kt")
classpath = listOf(commonStdlibPath!!)
externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
}
sourceSet {
name = "jvm"
dependentSourceSets = setOf(DokkaSourceSetID("test", "common"))
sourceRoots = listOf("src/main/kotlin/jvm/Test.kt")
classpath = listOf(commonStdlibPath!!)
externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
}
}
}
fun source(signature: String) =
"""
|/src/main/kotlin/test/Test.kt
|package example
|
| $signature
""".trimIndent()
@Test
fun `fun`() {
val source = source("fun simpleFun(): String = \"Celebrimbor\"")
val writerPlugin = TestOutputWriterPlugin()
testInline(
source,
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/example/simple-fun.html").firstSignature().match(
"fun ", A("simpleFun"), "(): ", A("String"), Span(),
ignoreSpanWithTokenStyle = true
)
}
}
}
@Test
fun `open fun`() {
val source = source("open fun simpleFun(): String = \"Celebrimbor\"")
val writerPlugin = TestOutputWriterPlugin()
testInline(
source,
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/example/simple-fun.html").firstSignature().match(
"open fun ", A("simpleFun"), "(): ", A("String"), Span(),
ignoreSpanWithTokenStyle = true
)
}
}
}
@Test
fun `open suspend fun`() {
val source = source("open suspend fun simpleFun(): String = \"Celebrimbor\"")
val writerPlugin = TestOutputWriterPlugin()
testInline(
source,
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/example/simple-fun.html").firstSignature().match(
"open suspend fun ", A("simpleFun"), "(): ", A("String"), Span(),
ignoreSpanWithTokenStyle = true
)
}
}
}
@Test
fun `fun with params`() {
val source = source("fun simpleFun(a: Int, b: Boolean, c: Any): String = \"Celebrimbor\"")
val writerPlugin = TestOutputWriterPlugin()
testInline(
source,
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/example/simple-fun.html").firstSignature().match(
"fun ", A("simpleFun"), "(", Parameters(
Parameter("a: ", A("Int"), ","),
Parameter("b: ", A("Boolean"), ","),
Parameter("c: ", A("Any")),
), "): ", A("String"), Span(),
ignoreSpanWithTokenStyle = true
)
}
}
}
@Test
fun `fun with function param`() {
val