diff options
author | Andrey Tyrin <andrei.tyrin@jetbrains.com> | 2023-01-09 13:28:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 13:28:05 +0100 |
commit | c3aa879c3c77233c401cf314d736bf20891991ba (patch) | |
tree | 8f5ee6cff051069f72f88b6d86c9339ce02d599f /plugins/base/src/test/kotlin | |
parent | 5ad955f28bde39d2f9e972bd3ec2c341579d9474 (diff) | |
download | dokka-c3aa879c3c77233c401cf314d736bf20891991ba.tar.gz dokka-c3aa879c3c77233c401cf314d736bf20891991ba.tar.bz2 dokka-c3aa879c3c77233c401cf314d736bf20891991ba.zip |
Move inheritors, params, see also and samples tabs to description for classlikes (#2749)
Diffstat (limited to 'plugins/base/src/test/kotlin')
7 files changed, 1710 insertions, 244 deletions
diff --git a/plugins/base/src/test/kotlin/content/exceptions/ContentForExceptions.kt b/plugins/base/src/test/kotlin/content/exceptions/ContentForExceptions.kt new file mode 100644 index 00000000..f59ba529 --- /dev/null +++ b/plugins/base/src/test/kotlin/content/exceptions/ContentForExceptions.kt @@ -0,0 +1,434 @@ +package content.exceptions + +import matchers.content.* +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.PluginConfigurationImpl +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.DisplaySourceSet +import org.jetbrains.kotlin.utils.addIfNotNull +import org.junit.jupiter.api.Test +import utils.ParamAttributes +import utils.bareSignature +import utils.findTestType +import kotlin.test.assertEquals + +class ContentForExceptions : BaseAbstractTest() { + private val testConfiguration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + } + } + } + + private val mppTestConfiguration = dokkaConfiguration { + moduleName = "example" + sourceSets { + val common = sourceSet { + name = "common" + displayName = "common" + analysisPlatform = "common" + sourceRoots = listOf("src/commonMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "jvm" + displayName = "jvm" + analysisPlatform = "jvm" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/jvmMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "linuxX64" + displayName = "linuxX64" + analysisPlatform = "native" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/linuxX64Main/kotlin/pageMerger/Test.kt") + } + } + pluginsConfigurations.addIfNotNull( + PluginConfigurationImpl( + DokkaBase::class.qualifiedName!!, + DokkaConfiguration.SerializationFormat.JSON, + """{ "mergeImplicitExpectActualDeclarations": true }""", + ) + ) + } + + @Test + fun `function with navigatable thrown exception`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |/** + |* @throws Exception + |*/ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "function") + page.content.assertNode { + group { + header(1) { +"function" } + } + divergentGroup { + divergentInstance { + divergent { + bareSignature( + emptyMap(), + "", + "", + emptySet(), + "function", + null, + "abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + } + after { + header(4) { +"Throws" } + table { + group { + group { + link { +"Exception" } + } + } + } + } + } + } + } + } + } + } + + @Test + fun `function with non-navigatable thrown exception`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |/** + |* @throws UnavailableException + |*/ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "function") + page.content.assertNode { + group { + header(1) { +"function" } + } + divergentGroup { + divergentInstance { + divergent { + bareSignature( + emptyMap(), + "", + "", + emptySet(), + "function", + null, + "abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + } + after { + header(4) { +"Throws" } + table { + group { + group { + +"UnavailableException" + } + } + } + } + } + } + } + } + } + } + + @Test + fun `multiplatofrm class with throws`() { + testInline( + """ + |/src/commonMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @throws CommonException + |*/ + |expect open class Parent + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @throws JvmException + |*/ + |actual open class Parent + | + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @throws LinuxException + |*/ + |actual open class Parent + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"expect open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + header(4) { +"Throws" } + table { + group { + group { + +"CommonException" + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "common", + this.sourceSets.first().name + ) + } + } + group { + group { + +"JvmException" + } + check { + sourceSets.assertSourceSet("jvm") + } + } + group { + group { + +"LinuxException" + } + check { + sourceSets.assertSourceSet("linuxX64") + } + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `multiplatofrm class with throws in few platforms`() { + testInline( + """ + |/src/commonMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @throws CommonException + |*/ + |expect open class Parent + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @throws JvmException + |*/ + |actual open class Parent + | + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |actual open class Parent + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"expect open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + header(4) { +"Throws" } + table { + group { + group { + +"CommonException" + } + check { + sourceSets.assertSourceSet("common") + } + } + group { + group { + +"JvmException" + } + check { + sourceSets.assertSourceSet("jvm") + } + } + check { + assertEquals(2, sourceSets.size) + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `throws in merged functions`() { + testInline( + """ + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @throws LinuxException + |*/ + |fun function() { + | println() + |} + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @throws JvmException + |*/ + |fun function() { + | println() + |} + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "function") + page.content.assertNode { + group { + header(1) { +"function" } + } + divergentGroup { + divergentInstance { + divergent { + bareSignature( + emptyMap(), + "", + "", + emptySet(), + "function", + null, + ) + } + after { + header(4) { +"Throws" } + table { + group { + group { + +"JvmException" + } + } + check { + sourceSets.assertSourceSet("jvm") + } + } + } + check { + sourceSets.assertSourceSet("jvm") + } + } + divergentInstance { + divergent { + bareSignature( + emptyMap(), + "", + "", + emptySet(), + "function", + null, + ) + } + after { + header(4) { +"Throws" } + table { + group { + group { + +"LinuxException" + } + } + } + } + check { + sourceSets.assertSourceSet("linuxX64") + } + } + } + } + } + } + } +} + +private fun Set<DisplaySourceSet>.assertSourceSet(expectedName: String) { + assertEquals(1, this.size) + assertEquals(expectedName, this.first().name) +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/content/inheritors/ContentForInheritorsTest.kt b/plugins/base/src/test/kotlin/content/inheritors/ContentForInheritorsTest.kt new file mode 100644 index 00000000..09c927bd --- /dev/null +++ b/plugins/base/src/test/kotlin/content/inheritors/ContentForInheritorsTest.kt @@ -0,0 +1,494 @@ +package content.inheritors + +import matchers.content.* +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.PluginConfigurationImpl +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.kotlin.utils.addIfNotNull +import org.junit.jupiter.api.Test +import utils.classSignature +import utils.findTestType +import kotlin.test.assertEquals + +class ContentForInheritorsTest : BaseAbstractTest() { + private val testConfiguration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + } + } + } + + private val mppTestConfiguration = dokkaConfiguration { + moduleName = "example" + sourceSets { + val common = sourceSet { + name = "common" + displayName = "common" + analysisPlatform = "common" + sourceRoots = listOf("src/commonMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "jvm" + displayName = "jvm" + analysisPlatform = "jvm" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/jvmMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "linuxX64" + displayName = "linuxX64" + analysisPlatform = "native" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/linuxX64Main/kotlin/pageMerger/Test.kt") + } + } + pluginsConfigurations.addIfNotNull( + PluginConfigurationImpl( + DokkaBase::class.qualifiedName!!, + DokkaConfiguration.SerializationFormat.JSON, + """{ "mergeImplicitExpectActualDeclarations": true }""", + ) + ) + } + + + //Case from skiko library + private val mppTestConfigurationSharedAsPlatform = dokkaConfiguration { + moduleName = "example" + sourceSets { + val common = sourceSet { + name = "common" + displayName = "common" + analysisPlatform = "common" + sourceRoots = listOf("src/commonMain/kotlin/pageMerger/Test.kt") + } + val jvm = sourceSet { + name = "jvm" + displayName = "jvm" + analysisPlatform = "jvm" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/jvmMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "android" + displayName = "android" + analysisPlatform = "jvm" + dependentSourceSets = setOf(jvm.value.sourceSetID) + sourceRoots = listOf("src/androidMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "awt" + displayName = "awt" + analysisPlatform = "jvm" + dependentSourceSets = setOf(jvm.value.sourceSetID) + sourceRoots = listOf("src/awtMain/kotlin/pageMerger/Test.kt") + } + + } + } + + @Test + fun `class with one inheritor has table in description`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |class Parent + | + |class Foo : Parent() + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + classSignature( + emptyMap(), + "", + "", + emptySet(), + "Parent" + ) + header(4) { +"Inheritors" } + table { + group { + link { +"Foo" } + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `interface with few inheritors has table in description`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |interface Parent + | + |class Foo : Parent() + |class Bar : Parent() + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"interface " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"Foo" } + } + group { + link { +"Bar" } + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `inherit from one of multiplatoforms actuals`() { + testInline( + """ + |/src/commonMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |expect open class Parent + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |actual open class Parent + | + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |actual open class Parent + |class Child: Parent() + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"expect open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"Child" } + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "linuxX64", + this.sourceSets.first().name + ) + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `inherit from class in common code`() { + testInline( + """ + |/src/commonMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |open class Parent + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |class Child : Parent() + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"open class " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"Child" } + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "common", + this.sourceSets.first().name + ) + } + } + } + } + skipAllNotMatching() + } + } + } + } + + + @Test + fun `inheritors from merged classes`() { + testInline( + """ + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |open class Parent + |class LChild : Parent() + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |open class Parent + |class JChild : Parent() + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"open class " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"JChild" } + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "jvm", + this.sourceSets.first().name + ) + } + } + group { + +"open class " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"LChild" } + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "linuxX64", + this.sourceSets.first().name + ) + } + } + } + } + skipAllNotMatching() + } + } + } + } + + + @Test + fun `merged inheritors from merged classes`() { + testInline( + """ + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |open class Parent + |class Child : Parent() + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |open class Parent + |class Child : Parent() + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"open class " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"Child" } + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "jvm", + this.sourceSets.first().name + ) + } + } + group { + +"open class " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"Child" } + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "linuxX64", + this.sourceSets.first().name + ) + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `parent in shared source set that analyse as platform`() { + testInline( + """ + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |interface Parent + | + |/src/androidMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |class Child : Parent + | + |/src/awtMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |class AwtChild : Parent + |class Child : Parent + | + """.trimMargin(), + mppTestConfigurationSharedAsPlatform + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"interface " + link { + +"Parent" + } + } + header(4) { +"Inheritors" } + table { + group { + link { +"Child" } + } + group { + link { +"AwtChild" } + } + check { + assertEquals(1, sourceSets.size) + assertEquals( + "jvm", + this.sourceSets.first().name + ) + } + } + } + } + skipAllNotMatching() + } + } + } + } +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index 3531f148..742c801f 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -2,12 +2,12 @@ package content.params import matchers.content.* import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.doc.Param import org.jetbrains.dokka.model.doc.Text -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.pages.* import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.junit.jupiter.api.Test @@ -37,8 +37,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -76,8 +75,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -122,8 +120,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -175,8 +172,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + val classPage = module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -219,8 +215,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + val classPage = module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -274,7 +269,7 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -327,7 +322,7 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -375,7 +370,7 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -436,7 +431,10 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val functionPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" }.children.single { it.name == "sample" } as ContentPage + module.findTestType( + "sample", + "DocGenProcessor" + ).children.single { it.name == "sample" } as ContentPage functionPage.content.assertNode { group { header(1) { +"sample" } @@ -492,8 +490,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val functionPage = - module.children.single { it.name == "sample" }.children.single { it.name == "sample" } as ContentPage + val functionPage = module.findTestType("sample", "sample") functionPage.content.assertNode { group { header(1) { +"sample" } @@ -564,7 +561,7 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val functionPage = - module.children.single { it.name == "sample" }.children.single { it.name == "sample" } as ContentPage + module.findTestType("sample", "sample") functionPage.content.assertNode { group { header(1) { +"sample" } @@ -616,7 +613,10 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val functionPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" }.children.single { it.name == "sample" } as ContentPage + module.findTestType( + "sample", + "DocGenProcessor" + ).children.single { it.name == "sample" } as ContentPage functionPage.content.assertNode { group { header(1) { +"sample" } @@ -693,7 +693,7 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -742,7 +742,10 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val functionPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" }.children.single { it.name == "sample" } as ContentPage + module.findTestType( + "sample", + "DocGenProcessor" + ).children.single { it.name == "sample" } as ContentPage functionPage.content.assertNode { group { header(1) { +"sample" } @@ -763,14 +766,12 @@ class ContentForParamsTest : BaseAbstractTest() { } } header(4) { +"Parameters" } - group { - table { - group { - +"testParam" - comment { - +"Sample description for test param that has a type of " - link { +"String" } - } + table { + group { + +"testParam" + comment { + +"Sample description for test param that has a type of " + link { +"String" } } } } @@ -801,8 +802,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val functionPage = - module.children.single { it.name == "sample" }.children.single { it.name == "sample" } as ContentPage + val functionPage = module.findTestType("sample", "sample") functionPage.content.assertNode { group { header(1) { +"sample" } @@ -855,8 +855,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + val classPage = module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -921,7 +920,7 @@ class ContentForParamsTest : BaseAbstractTest() { ) { pagesTransformationStage = { module -> val classPage = - module.children.single { it.name == "sample" }.children.single { it.name == "DocGenProcessor" } as ContentPage + module.findTestType("sample", "DocGenProcessor") classPage.content.assertNode { group { header { +"DocGenProcessor" } @@ -982,8 +981,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1029,8 +1027,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1051,21 +1048,69 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { pWrapped("comment to function") } header(4) { +"Parameters" } - group { - table { - group { - +"abc" - check { - val textStyles = children.single { it is ContentText }.style - assertContains(textStyles, TextStyle.Underlined) - } - group { group { +"comment to param" } } + table { + group { + +"abc" + check { + val textStyles = children.single { it is ContentText }.style + assertContains(textStyles, TextStyle.Underlined) } + group { group { +"comment to param" } } + } + } + } + } + } + } + } + } + } + + @Test + fun `single parameter in class`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * comment to class + | * @param abc comment to param + | */ + |class Foo(abc: String) + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Foo") + println(page.content) + page.content.assertNode { + group { + header(1) { +"Foo" } + platformHinted { + classSignature( + emptyMap(), + "", + "", + emptySet(), + "Foo", + "abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + group { + pWrapped("comment to class") + } + header(4) { +"Parameters" } + table { + group { + +"abc" + check { + val textStyles = children.single { it is ContentText }.style + assertContains(textStyles, TextStyle.Underlined) } + group { group { +"comment to param" } } } } } } + skipAllNotMatching() } } } @@ -1089,8 +1134,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1108,32 +1152,30 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { group { group { +"comment to function" } } } header(4) { +"Parameters" } - group { - table { - group { - +"first" - check { - val textStyles = children.single { it is ContentText }.style - assertContains(textStyles, TextStyle.Underlined) - } - group { group { +"comment to first param" } } + table { + group { + +"first" + check { + val textStyles = children.single { it is ContentText }.style + assertContains(textStyles, TextStyle.Underlined) } - group { - +"second" - check { - val textStyles = children.single { it is ContentText }.style - assertContains(textStyles, TextStyle.Underlined) - } - group { group { +"comment to second param" } } + group { group { +"comment to first param" } } + } + group { + +"second" + check { + val textStyles = children.single { it is ContentText }.style + assertContains(textStyles, TextStyle.Underlined) } - group { - +"third" - check { - val textStyles = children.single { it is ContentText }.style - assertContains(textStyles, TextStyle.Underlined) - } - group { group { +"comment to third param" } } + group { group { +"comment to second param" } } + } + group { + +"third" + check { + val textStyles = children.single { it is ContentText }.style + assertContains(textStyles, TextStyle.Underlined) } + group { group { +"comment to third param" } } } } } @@ -1163,8 +1205,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1182,22 +1223,21 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { group { group { +"comment to function" } } } header(4) { +"Parameters" } - group { - table { - group { - +"c" - group { group { +"comment to c param" } } - } - group { - +"b" - group { group { +"comment to b param" } } - } - group { - +"a" - group { group { +"comment to a param" } } - } + table { + group { + +"c" + group { group { +"comment to c param" } } + } + group { + +"b" + group { group { +"comment to b param" } } + } + group { + +"a" + group { group { +"comment to a param" } } } } + } } } @@ -1223,8 +1263,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1241,20 +1280,18 @@ class ContentForParamsTest : BaseAbstractTest() { } after { header(4) { +"Parameters" } - group { - table { - group { - +"first" - group { group { +"comment to first param" } } - } - group { - +"second" - group { group { +"comment to second param" } } - } - group { - +"third" - group { group { +"comment to third param" } } - } + table { + group { + +"first" + group { group { +"comment to first param" } } + } + group { + +"second" + group { group { +"comment to second param" } } + } + group { + +"third" + group { group { +"comment to third param" } } } } } @@ -1282,8 +1319,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1309,14 +1345,13 @@ class ContentForParamsTest : BaseAbstractTest() { pWrapped("comment to receiver") } header(4) { +"Parameters" } - group { - table { - group { - +"abc" - group { group { +"comment to param" } } - } + table { + group { + +"abc" + group { group { +"comment to param" } } } } + } } } @@ -1342,8 +1377,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1361,16 +1395,14 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { group { group { +"comment to function" } } } header(4) { +"Parameters" } - group { - table { - group { - +"first" - group { group { +"comment to first param" } } - } - group { - +"third" - group { group { +"comment to third param" } } - } + table { + group { + +"first" + group { group { +"comment to first param" } } + } + group { + +"third" + group { group { +"comment to third param" } } } } } @@ -1401,8 +1433,7 @@ class ContentForParamsTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -1423,20 +1454,18 @@ class ContentForParamsTest : BaseAbstractTest() { unnamedTag("Since") { comment { +"0.11" } } header(4) { +"Parameters" } - group { - table { - group { - +"first" - group { group { +"comment to first param" } } - } - group { - +"second" - group { group { +"comment to second param" } } - } - group { - +"third" - group { group { +"comment to third param" } } - } + table { + group { + +"first" + group { group { +"comment to first param" } } + } + group { + +"second" + group { group { +"comment to second param" } } + } + group { + +"third" + group { group { +"comment to third param" } } } } } diff --git a/plugins/base/src/test/kotlin/content/samples/ContentForSamplesTest.kt b/plugins/base/src/test/kotlin/content/samples/ContentForSamplesTest.kt new file mode 100644 index 00000000..37009e46 --- /dev/null +++ b/plugins/base/src/test/kotlin/content/samples/ContentForSamplesTest.kt @@ -0,0 +1,192 @@ +package content.samples + +import matchers.content.* +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.DisplaySourceSet +import org.junit.jupiter.api.Test +import utils.classSignature +import utils.findTestType +import java.nio.file.Paths +import kotlin.test.assertEquals + +class ContentForSamplesTest : BaseAbstractTest() { + private val testDataDir = getTestDataDir("content/samples").toAbsolutePath() + + private val testConfiguration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + samples = listOf( + Paths.get("$testDataDir/samples.kt").toString(), + ) + } + } + } + + private val mppTestConfiguration = dokkaConfiguration { + moduleName = "example" + sourceSets { + val common = sourceSet { + name = "common" + displayName = "common" + analysisPlatform = "common" + sourceRoots = listOf("src/commonMain/kotlin/pageMerger/Test.kt") + samples = listOf( + Paths.get("$testDataDir/samples.kt").toString(), + ) + } + sourceSet { + name = "jvm" + displayName = "jvm" + analysisPlatform = "jvm" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/jvmMain/kotlin/pageMerger/Test.kt") + samples = listOf( + Paths.get("$testDataDir/samples.kt").toString(), + ) + } + sourceSet { + name = "linuxX64" + displayName = "linuxX64" + analysisPlatform = "native" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/linuxX64Main/kotlin/pageMerger/Test.kt") + samples = listOf( + Paths.get("$testDataDir/samples.kt").toString(), + ) + } + } + } + + @Test + fun `samples block is rendered in the description`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + | /** + | * @sample [test.sampleForClassDescription] + | */ + |class Foo + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Foo") + page.content.assertNode { + group { + header(1) { +"Foo" } + platformHinted { + classSignature( + emptyMap(), + "", + "", + emptySet(), + "Foo" + ) + header(4) { +"Samples" } + group { + codeBlock { + +"""| + |fun main() { + | //sampleStart + | print("Hello") + | //sampleEnd + |}""".trimMargin() + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `multiplatofrm class with samples in few platforms`() { + testInline( + """ + |/src/commonMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @sample [test.sampleForClassDescription] + |*/ + |expect open class Parent + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @sample unresolved + |*/ + |actual open class Parent + | + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |actual open class Parent + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"expect open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + header(4) { +"Samples" } + group { + codeBlock { + +"""| + |fun main() { + | //sampleStart + | print("Hello") + | //sampleEnd + |}""".trimMargin() + } + check { + sourceSets.assertSourceSet("common") + } + } + group { + +"unresolved" + check { + sourceSets.assertSourceSet("jvm") + } + } + } + } + skipAllNotMatching() + } + } + } + } +} + + +private fun Set<DisplaySourceSet>.assertSourceSet(expectedName: String) { + assertEquals(1, this.size) + assertEquals(expectedName, this.first().name) +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt index 5dee546f..79c1e1ad 100644 --- a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt +++ b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt @@ -1,14 +1,9 @@ package content.seealso import matchers.content.* -import org.jetbrains.dokka.pages.ContentDRILink -import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest -import org.jetbrains.dokka.links.Callable -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.links.JavaClassReference -import org.jetbrains.dokka.model.doc.See -import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull +import org.jetbrains.dokka.model.DisplaySourceSet +import org.jetbrains.dokka.pages.ContentDRILink import org.junit.jupiter.api.Test import utils.* import kotlin.test.assertEquals @@ -23,6 +18,32 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } } + private val mppTestConfiguration = dokkaConfiguration { + moduleName = "example" + sourceSets { + val common = sourceSet { + name = "common" + displayName = "common" + analysisPlatform = "common" + sourceRoots = listOf("src/commonMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "jvm" + displayName = "jvm" + analysisPlatform = "jvm" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/jvmMain/kotlin/pageMerger/Test.kt") + } + sourceSet { + name = "linuxX64" + displayName = "linuxX64" + analysisPlatform = "native" + dependentSourceSets = setOf(common.value.sourceSetID) + sourceRoots = listOf("src/linuxX64Main/kotlin/pageMerger/Test.kt") + } + } + } + @Test fun `undocumented function`() { testInline( @@ -36,8 +57,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -77,8 +97,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -98,12 +117,10 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { - group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - } + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } } } } @@ -115,6 +132,128 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } @Test + fun `undocumented seealso without reference for class`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc + | */ + |class Foo() + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Foo") + println(page.content) + page.content.assertNode { + group { + header(1) { +"Foo" } + platformHinted { + classSignature( + emptyMap(), + "", + "", + emptySet(), + "Foo" + ) + header(4) { +"See also" } + table { + group { + +"abc" + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `undocumented seealso with reference to parameter for class`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc + | */ + |class Foo(abc: String) + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Foo") + println(page.content) + page.content.assertNode { + group { + header(1) { +"Foo" } + platformHinted { + classSignature( + emptyMap(), + "", + "", + emptySet(), + "Foo", + "abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + header(4) { +"See also" } + table { + group { + +"abc" + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test + fun `undocumented seealso with reference to property for class`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc + | */ + |class Foo(val abc: String) + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Foo") + println(page.content) + page.content.assertNode { + group { + header(1) { +"Foo" } + platformHinted { + classSignature( + emptyMap(), + "", + "", + emptySet(), + "Foo", + "val abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + header(4) { +"See also" } + table { + group { + link { +"Foo.abc" } + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test fun `documented seealso`() { testInline( """ @@ -129,8 +268,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -150,14 +288,12 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - group { - group { +"Comment to abc" } - } + group { +"Comment to abc" } } } } @@ -170,6 +306,50 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } @Test + fun `documented seealso with reference to property for class`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc Comment to abc + | */ + |class Foo(val abc: String) + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("test", "Foo") + println(page.content) + page.content.assertNode { + group { + header(1) { +"Foo" } + platformHinted { + classSignature( + emptyMap(), + "", + "", + emptySet(), + "Foo", + "val abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + header(4) { +"See also" } + table { + group { + link { +"Foo.abc" } + group { + group { +"Comment to abc" } + } + } + } + } + } + skipAllNotMatching() + } + } + } + } + + @Test fun `should use fully qualified name for unresolved link`() { testInline( """ @@ -184,8 +364,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -205,13 +384,11 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { + table { + group { + +"com.example.NonExistingClass" group { - +"com.example.NonExistingClass" - group { - group { +"description for non-existing" } - } + group { +"description for non-existing" } } } } @@ -238,8 +415,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -259,21 +435,20 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { - group { - link { - check { - assertEquals( - "kotlin.collections/Collection///PointingToDeclaration/", - (this as ContentDRILink).address.toString() - ) - } - +"Collection" + table { + group { + link { + check { + assertEquals( + "kotlin.collections/Collection///PointingToDeclaration/", + (this as ContentDRILink).address.toString() + ) } + +"Collection" } } } + } } } @@ -297,8 +472,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -318,16 +492,15 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"Collection" } group { - //DRI should be "test//abc/#/-1/" - link { +"Collection" } - group { - group { +"Comment to stdliblink" } - } + group { +"Comment to stdliblink" } } } + } } } @@ -355,8 +528,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -380,17 +552,16 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { unnamedTag("Since") { comment { +"0.11" } } header(4) { +"See also" } - group { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"Collection" } group { - //DRI should be "test//abc/#/-1/" - link { +"Collection" } - group { - group { +"Comment to stdliblink" } - } + group { +"Comment to stdliblink" } } } } + } } } @@ -415,8 +586,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -436,17 +606,16 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - group { - group { +"Comment to abc2" } - } + group { +"Comment to abc2" } } } } + } } } @@ -471,8 +640,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { """.trimIndent(), testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("test", "function") page.content.assertNode { group { header(1) { +"function" } @@ -492,21 +660,19 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - group { - group { +"Comment to abc1" } - } - } - group { - //DRI should be "test//abc/#/-1/" - link { +"Collection" } - group { group { +"Comment to collection" } } + group { +"Comment to abc1" } } } + group { + //DRI should be "test//abc/#/-1/" + link { +"Collection" } + group { group { +"Comment to collection" } } + } } } } @@ -543,8 +709,7 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { testConfiguration ) { pagesTransformationStage = { module -> - val page = module.children.single { it.name == "com.example" } - .children.single { it.name == "function" } as ContentPage + val page = module.findTestType("com.example", "function") page.content.assertNode { group { @@ -564,19 +729,17 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } after { header(4) { +"See also" } - group { - table { + table { + group { + link { +"CollectionExtensions.property" } group { - link { +"CollectionExtensions.property" } - group { - group { +"static property" } - } + group { +"static property" } } + } + group { + link { +"CollectionExtensions.emptyList" } group { - link { +"CollectionExtensions.emptyList" } - group { - group { +"static emptyList" } - } + group { +"static emptyList" } } } } @@ -587,4 +750,109 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { } } } + + @Test + fun `multiplatform class with seealso in few platforms`() { + testInline( + """ + |/src/commonMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |/** + |* @see Unit + |*/ + |expect open class Parent + | + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |val x = 0 + |/** + |* @see x resolved + |* @see y unresolved + |*/ + |actual open class Parent + | + |/src/linuxX64Main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |actual open class Parent + | + """.trimMargin(), + mppTestConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.findTestType("pageMerger", "Parent") + page.content.assertNode { + group { + header(1) { +"Parent" } + platformHinted { + group { + +"expect open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + group { + +"actual open class " + link { + +"Parent" + } + } + header(4) { + +"See also" + check { + assertEquals(2, sourceSets.size) + } + } + table { + group { + link { +"Unit" } + check { + sourceSets.assertSourceSet("common") + } + } + group { + link { +"Unit" } + check { + sourceSets.assertSourceSet("jvm") + } + } + group { + link { +"x" } + group { group { +"resolved" } } + check { + sourceSets.assertSourceSet("jvm") + } + } + group { + +"y" + group { group { +"unresolved" } } + check { + sourceSets.assertSourceSet("jvm") + } + } + + check { + assertEquals(2, sourceSets.size) + } + } + } + } + skipAllNotMatching() + } + } + } + } } + +private fun Set<DisplaySourceSet>.assertSourceSet(expectedName: String) { + assertEquals(1, this.size) + assertEquals(expectedName, this.first().name) +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index fadc8e83..7dfe1e1d 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -1,13 +1,13 @@ package linkableContent import org.jetbrains.dokka.SourceLinkDefinitionImpl +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.base.transformers.pages.samples.DefaultSamplesTransformer import org.jetbrains.dokka.base.transformers.pages.sourcelinks.SourceLinksTransformer import org.jetbrains.dokka.model.WithGenerics import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.pages.* -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.junit.jupiter.api.Assertions @@ -200,7 +200,6 @@ class LinkableContentTest : BaseAbstractTest() { .cast<ContentDivergentGroup>().children.single() .cast<ContentDivergentInstance>().after .cast<ContentGroup>().children.last() - .cast<ContentGroup>().children.last() .cast<ContentGroup>().children.single() .cast<ContentCodeBlock>().children.single().cast<ContentText>().text Assertions.assertEquals( diff --git a/plugins/base/src/test/kotlin/utils/contentUtils.kt b/plugins/base/src/test/kotlin/utils/contentUtils.kt index 9f024c5b..d38af3f4 100644 --- a/plugins/base/src/test/kotlin/utils/contentUtils.kt +++ b/plugins/base/src/test/kotlin/utils/contentUtils.kt @@ -1,9 +1,9 @@ package utils import matchers.content.* -import org.jetbrains.dokka.model.* import org.jetbrains.dokka.pages.ContentGroup -import kotlin.text.Typography.nbsp +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.RootPageNode //TODO: Try to unify those functions after update to 1.4 fun ContentMatcherBuilder<*>.functionSignature( @@ -68,6 +68,53 @@ fun ContentMatcherBuilder<*>.bareSignature( } } +fun ContentMatcherBuilder<*>.classSignature( + annotations: Map<String, Set<String>>, + visibility: String, + modifier: String, + keywords: Set<String>, + name: String, + vararg params: Pair<String, ParamAttributes>, + parent: String? = null +) = group { + annotations.entries.forEach { + group { + unwrapAnnotation(it) + } + } + if (visibility.isNotBlank()) +"$visibility " + if (modifier.isNotBlank()) +"$modifier " + +("${keywords.joinToString("") { "$it " }}class ") + link { +name } + if (params.isNotEmpty()) { + +"(" + group { + params.forEachIndexed { id, (n, t) -> + group { + t.annotations.forEach { + unwrapAnnotation(it) + } + t.keywords.forEach { + +it + } + + +"$n: " + group { link { +(t.type) } } + if (id != params.lastIndex) + +", " + } + } + } + +")" + } + if (parent != null) { + +(" : ") + link { + +(parent) + } + } +} + fun ContentMatcherBuilder<*>.functionSignatureWithReceiver( annotations: Map<String, Set<String>>, visibility: String?, @@ -272,3 +319,6 @@ data class ParamAttributes( val keywords: Set<String>, val type: String ) + +fun RootPageNode.findTestType(packageName: String, name: String) = + children.single { it.name == packageName }.children.single { it.name == name } as ContentPage
\ No newline at end of file |