diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-02-12 18:05:24 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-02-18 13:28:23 +0100 |
commit | 46b4bbb68ce1285a1aea700cc0d0000c6b7ed97b (patch) | |
tree | 862f5283fd2db16b973422dc60491760fa556262 /plugins/base/src/test/kotlin/basic/DRITest.kt | |
parent | c4c6a165d968fefbf8caa52b9c9763b58fc39803 (diff) | |
download | dokka-46b4bbb68ce1285a1aea700cc0d0000c6b7ed97b.tar.gz dokka-46b4bbb68ce1285a1aea700cc0d0000c6b7ed97b.tar.bz2 dokka-46b4bbb68ce1285a1aea700cc0d0000c6b7ed97b.zip |
Moves all core tests to base plugin
Diffstat (limited to 'plugins/base/src/test/kotlin/basic/DRITest.kt')
-rw-r--r-- | plugins/base/src/test/kotlin/basic/DRITest.kt | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/basic/DRITest.kt b/plugins/base/src/test/kotlin/basic/DRITest.kt new file mode 100644 index 00000000..c7dc85fb --- /dev/null +++ b/plugins/base/src/test/kotlin/basic/DRITest.kt @@ -0,0 +1,168 @@ +package basic + +import org.jetbrains.dokka.links.* +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.asSequence +import org.junit.Assert.assertEquals +import org.junit.Test +import testApi.testRunner.AbstractCoreTest + +class DRITest : AbstractCoreTest() { + @Test + fun `#634`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package toplevel + | + |inline fun <T, R : Comparable<R>> Array<out T>.mySortBy( + | crossinline selector: (T) -> R?): Array<out T> = 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 `#634 with immediate nullable self`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package toplevel + | + |fun <T : Comparable<T>> Array<T>.doSomething(t: T?): Array<T> = 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 `#634 with generic nullable receiver`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package toplevel + | + |fun <T : Comparable<T>> 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 `#642 with * and Any?`() { + val configuration = dokkaConfiguration { + passes { + pass { + analysisPlatform = "js" + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + | + |open class Bar<Z> + |class ReBarBar : Bar<StringBuilder>() + |class Foo<out T : Comparable<*>, R : List<Bar<*>>> + | + |fun <T : Comparable<Any?>> Foo<T, *>.qux(): String = TODO() + |fun <T : Comparable<*>> Foo<T, *>.qux(): String = TODO() + | + """.trimMargin(), + configuration + ) { + pagesGenerationStage = { module -> + // DRI(//qux/Foo[TypeParam(bounds=[kotlin.Comparable[kotlin.Any?]]),kotlin.Any?]#//) + val expectedDRI = DRI( + "", + null, + Callable( + "qux", + TypeConstructor( + "Foo", + listOf( + TypeParam( + listOf( + TypeConstructor( + "kotlin.Comparable", + listOf( + Nullable(TypeConstructor("kotlin.Any", emptyList())) + ) + ) + ) + ), + Nullable(TypeConstructor("kotlin.Any", emptyList())) + ) + ), + emptyList() + ) + ) + + val driCount = module + .asSequence() + .filterIsInstance<ContentPage>() + .sumBy { it.dri.count { dri -> dri == expectedDRI } } + + assertEquals(1, driCount) + } + } + } +}
\ No newline at end of file |