package basic import org.jetbrains.dokka.links.* import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.asSequence import org.junit.jupiter.api.Assertions.assertEquals import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Test class DRITest : AbstractCoreTest() { @Test fun issue634() { val configuration = dokkaConfiguration { passes { pass { sourceRoots = listOf("src/") } } } testInline( """ |/src/main/kotlin/basic/Test.kt |package toplevel | |inline fun > Array.mySortBy( | crossinline selector: (T) -> R?): Array = TODO() |} """.trimMargin(), configuration ) { documentablesMergingStage = { module -> val expected = TypeConstructor( "kotlin.Function1", listOf( TypeParam(listOf(Nullable(TypeConstructor("kotlin.Any", emptyList())))), Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) ) ) val actual = module.packages.single() .functions.single() .dri.callable?.params?.single() assertEquals(expected, actual) } } } @Test fun issue634WithImmediateNullableSelf() { val configuration = dokkaConfiguration { passes { pass { sourceRoots = listOf("src/") } } } testInline( """ |/src/main/kotlin/basic/Test.kt |package toplevel | |fun > Array.doSomething(t: T?): Array = TODO() |} """.trimMargin(), configuration ) { documentablesMergingStage = { module -> val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) val actual = module.packages.single() .functions.single() .dri.callable?.params?.single() assertEquals(expected, actual) } } } @Test fun issue634WithGenericNullableReceiver() { val configuration = dokkaConfiguration { passes { pass { sourceRoots = listOf("src/") } } } testInline( """ |/src/main/kotlin/basic/Test.kt |package toplevel | |fun > T?.doSomethingWithNullable() = TODO() |} """.trimMargin(), configuration ) { documentablesMergingStage = { module -> val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) val actual = module.packages.single() .functions.single() .dri.callable?.receiver assertEquals(expected, actual) } } } @Test fun issue642WithStarAndAny() { val configuration = dokkaConfiguration { passes { pass { analysisPlatform = "js" sourceRoots = listOf("src/") } } } testInline( """ |/src/main/kotlin/Test.kt | |open class Bar |class ReBarBar : Bar() |class Foo, R : List>> | |fun > Foo.qux(): String = TODO() |fun > Foo.qux(): String = TODO() | """.trimMargin(), configuration ) { pagesGenerationStage = { module -> // DRI(//qux/Foo[TypeParam(bounds=[kotlin.Comparable[kotlin.Any?]]),*]#//) val expectedDRI = DRI( "", null, Callable( "qux", TypeConstructor( "Foo", listOf( TypeParam( listOf( TypeConstructor( "kotlin.Comparable", listOf( Nullable(TypeConstructor("kotlin.Any", emptyList())) ) ) ) ), StarProjection ) ), emptyList() ) ) val driCount = module .asSequence() .filterIsInstance() .sumBy { it.dri.count { dri -> dri == expectedDRI } } assertEquals(1, driCount) } } } }