diff options
author | Vadim Mishenev <vad-mishenev@yandex.ru> | 2023-06-30 16:44:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-30 16:44:20 +0300 |
commit | 12a386bb7185f862a1cbd831e6856c4235953833 (patch) | |
tree | 9fcfaba5bf87587e008fb9feb52264618e4180a2 /plugins/base/src/test | |
parent | 26112637ba3511afc218fbe0ead6f72421ac7c77 (diff) | |
download | dokka-12a386bb7185f862a1cbd831e6856c4235953833.tar.gz dokka-12a386bb7185f862a1cbd831e6856c4235953833.tar.bz2 dokka-12a386bb7185f862a1cbd831e6856c4235953833.zip |
Generate dedicated pages for typealiases (#3051)
Diffstat (limited to 'plugins/base/src/test')
5 files changed, 161 insertions, 4 deletions
diff --git a/plugins/base/src/test/kotlin/content/functions/ContentForBriefTest.kt b/plugins/base/src/test/kotlin/content/functions/ContentForBriefTest.kt index f86506af..c09a0e4d 100644 --- a/plugins/base/src/test/kotlin/content/functions/ContentForBriefTest.kt +++ b/plugins/base/src/test/kotlin/content/functions/ContentForBriefTest.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.TypeConstructor import org.jetbrains.dokka.model.DClass +import org.jetbrains.dokka.model.DPackage import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.* import org.junit.jupiter.api.Assertions.assertEquals @@ -132,6 +133,32 @@ class ContentForBriefTest : BaseAbstractTest() { } @Test + fun `brief should work for typealias`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |/** + |* This is an example <!-- not visible --> of html + |* + |* This is definitely not a brief + |*/ + |typealias A = Int + """.trimIndent(), + testConfiguration + ) { + pagesTransformationStage = { module -> + val functionBriefDocs = module.singleTypeAliasesDescription("test") + + assertEquals( + "This is an example <!-- not visible --> of html", + functionBriefDocs.children.joinToString("") { (it as ContentText).text }) + } + } + } + + @Test fun `brief for functions should work with html`() { testInline( """ @@ -344,4 +371,14 @@ class ContentForBriefTest : BaseAbstractTest() { val function = functionsTable.children.first() return function.dfs { it is ContentGroup && it.dci.kind == ContentKind.Comment && it.children.all { it is ContentText } } as ContentGroup } + private fun RootPageNode.singleTypeAliasesDescription(packageName: String): ContentGroup { + val packagePage = + dfs { it.name == packageName && (it as WithDocumentables).documentables.firstOrNull() is DPackage } as ContentPage + val contentTable = + packagePage.content.dfs { it is ContentTable && it.dci.kind == ContentKind.Classlikes } as ContentTable + + assertEquals(1, contentTable.children.size) + val row = contentTable.children.first() + return row.dfs { it is ContentGroup && it.dci.kind == ContentKind.Comment && it.children.all { it is ContentText } } as ContentGroup + } }
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/content/typealiases/TypealiasTest.kt b/plugins/base/src/test/kotlin/content/typealiases/TypealiasTest.kt new file mode 100644 index 00000000..c2f58cb9 --- /dev/null +++ b/plugins/base/src/test/kotlin/content/typealiases/TypealiasTest.kt @@ -0,0 +1,78 @@ +package content.typealiases + +import matchers.content.* +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.dfs +import org.jetbrains.dokka.pages.* +import org.junit.jupiter.api.Test +import utils.assertNotNull + + +class TypealiasTest : BaseAbstractTest() { + private val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + classpath = listOf(commonStdlibPath!!) + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + } + } + } + + @Test + fun `typealias should have a dedicated page with full documentation`() { + testInline( + """ + |/src/main/kotlin/test/Test.kt + |package example + | + | /** + | * Brief text + | * + | * some text + | * + | * @see String + | * @throws Unit + | */ + | typealias A = String + """, + configuration + ) { + pagesTransformationStage = { module -> + val content = (module.dfs { it.name == "A" } as ClasslikePageNode).content + val platformHinted = content.dfs { it is PlatformHintedContent } + platformHinted.assertNotNull("platformHinted").assertNode { + group { + group { + group { + +"typealias " + group { group { link { +"A" } } } + +" = " + group { link { +"String" } } + } + } + + group { + group { + group { + group { +"Brief text" } + group { +"some text" } + } + } + } + + header { +"See also" } + table { + group { link { +"String" } } + } + + header { +"Throws" } + table { + group { group { link { +"Unit" } } } + } + } + } + } + } + } +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/renderers/html/NavigationIconTest.kt b/plugins/base/src/test/kotlin/renderers/html/NavigationIconTest.kt index a7a7bacf..e83f70d5 100644 --- a/plugins/base/src/test/kotlin/renderers/html/NavigationIconTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/NavigationIconTest.kt @@ -37,7 +37,7 @@ class NavigationIconTest : BaseAbstractTest() { .filterKeys { it.startsWith("images/nav-icons") } .keys.sorted() - assertEquals(15, navIconAssets.size) + assertEquals(16, navIconAssets.size) assertEquals("images/nav-icons/abstract-class-kotlin.svg", navIconAssets[0]) assertEquals("images/nav-icons/abstract-class.svg", navIconAssets[1]) assertEquals("images/nav-icons/annotation-kotlin.svg", navIconAssets[2]) @@ -53,6 +53,7 @@ class NavigationIconTest : BaseAbstractTest() { assertEquals("images/nav-icons/interface-kotlin.svg", navIconAssets[12]) assertEquals("images/nav-icons/interface.svg", navIconAssets[13]) assertEquals("images/nav-icons/object.svg", navIconAssets[14]) + assertEquals("images/nav-icons/typealias-kotlin.svg", navIconAssets[15]) } } } @@ -100,6 +101,15 @@ class NavigationIconTest : BaseAbstractTest() { } @Test + fun `should add icon styles to kotlin typealias navigation item`() { + assertNavigationIcon( + source = kotlinSource("typealias KotlinTypealias = String"), + expectedIconClass = "typealias-kt", + expectedNavLinkText = "KotlinTypealias" + ) + } + + @Test fun `should add icon styles to kotlin enum navigation item`() { assertNavigationIcon( source = kotlinSource("enum class KotlinEnum {}"), diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index 3a263fd0..d271be2e 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -603,7 +603,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example.html").firstSignature().match( + writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match( "typealias ", A("PlainTypealias"), " = ", A("Int"), ignoreSpanWithTokenStyle = true ) @@ -663,7 +663,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example.html").firstSignature().match( + writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match( "typealias ", A("PlainTypealias"), " = ", A("Comparable"), "<", A("Int"), ">", ignoreSpanWithTokenStyle = true @@ -690,7 +690,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example.html").firstSignature().match( + writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match( "typealias ", A("GenericTypealias"), "<", A("T"), "> = ", A("Comparable"), "<", A("T"), ">", ignoreSpanWithTokenStyle = true diff --git a/plugins/base/src/test/kotlin/transformers/MergeImplicitExpectActualDeclarationsTest.kt b/plugins/base/src/test/kotlin/transformers/MergeImplicitExpectActualDeclarationsTest.kt index 5e335209..241fb481 100644 --- a/plugins/base/src/test/kotlin/transformers/MergeImplicitExpectActualDeclarationsTest.kt +++ b/plugins/base/src/test/kotlin/transformers/MergeImplicitExpectActualDeclarationsTest.kt @@ -114,6 +114,38 @@ class MergeImplicitExpectActualDeclarationsTest : BaseAbstractTest() { } @Test + fun `should merge class and typealias`() { + testInline( + """ + |/src/jvmMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |class A { + | fun method1(): String + |} + | + |/src/jsMain/kotlin/pageMerger/Test.kt + |package pageMerger + | + |typealias A = String + | + """.trimMargin(), + configuration(true), + cleanupOutput = true + ) { + pagesTransformationStage = { root -> + val classPage = root.dfs { it.name == "A" } as? ClasslikePageNode + assertNotNull(classPage, "Tested class not found!") + + val platformHintedContent = classPage.content.dfs { it is PlatformHintedContent }.assertNotNull("platformHintedContent") + assertEquals(2, platformHintedContent.sourceSets.size) + + platformHintedContent.dfs { it is ContentText && it.text == "class " }.assertNotNull("class keyword") + platformHintedContent.dfs { it is ContentText && it.text == "typealias " }.assertNotNull("typealias keyword") + } + } + } + @Test fun `should merge method and prop`() { testInline( """ |