diff options
Diffstat (limited to 'plugins/base/src/test/kotlin/content/signatures')
-rw-r--r-- | plugins/base/src/test/kotlin/content/signatures/ConstructorsSignaturesTest.kt | 469 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt | 515 |
2 files changed, 0 insertions, 984 deletions
diff --git a/plugins/base/src/test/kotlin/content/signatures/ConstructorsSignaturesTest.kt b/plugins/base/src/test/kotlin/content/signatures/ConstructorsSignaturesTest.kt deleted file mode 100644 index 9a413e0e..00000000 --- a/plugins/base/src/test/kotlin/content/signatures/ConstructorsSignaturesTest.kt +++ /dev/null @@ -1,469 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package content.signatures - -import matchers.content.* -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest -import org.jetbrains.dokka.pages.BasicTabbedContentType -import org.jetbrains.dokka.pages.ContentPage -import kotlin.test.Test -import utils.OnlyDescriptors - -class ConstructorsSignaturesTest : BaseAbstractTest() { - private val testConfiguration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - analysisPlatform = "jvm" - } - } - } - - @Test - fun `class name without parenthesis`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |class SomeClass - | - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "SomeClass" } as ContentPage - page.content.assertNode { - group { - header(1) { +"SomeClass" } - platformHinted { - group { - +"class " - link { +"SomeClass" } - } - } - } - skipAllNotMatching() - } - } - } - } - - @Test - fun `class name with empty parenthesis`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |class SomeClass() - | - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "SomeClass" } as ContentPage - page.content.assertNode { - group { - header(1) { +"SomeClass" } - platformHinted { - group { - +"class " - link { +"SomeClass" } - } - } - } - skipAllNotMatching() - } - } - } - } - - @Test - fun `class with a parameter`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |class SomeClass(a: String) - | - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "SomeClass" } as ContentPage - page.content.assertNode { - group { - header(1) { +"SomeClass" } - platformHinted { - group { - +"class " - link { +"SomeClass" } - +"(" - group { - group { - +"a: " - group { link { +"String" } } - } - } - +")" - } - } - } - skipAllNotMatching() - } - } - } - } - - @Test - fun `class with a val parameter`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |class SomeClass(val a: String, var i: Int) - | - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "SomeClass" } as ContentPage - page.content.assertNode { - group { - header(1) { +"SomeClass" } - platformHinted { - group { - +"class " - link { +"SomeClass" } - +"(" - group { - group { - +"val a: " - group { link { +"String" } } - +", " - } - group { - +"var i: " - group { link { +"Int" } } - } - } - +")" - } - } - } - skipAllNotMatching() - } - } - } - } - - @OnlyDescriptors("Order of constructors is different in K2") - @Test - fun `class with a parameterless secondary constructor`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |class SomeClass(a: String) { - | constructor() - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "SomeClass" } as ContentPage - page.content.assertNode { - group { - header(1) { +"SomeClass" } - platformHinted { - group { - +"class " - link { +"SomeClass" } - +"(" - group { - group { - +"a: " - group { link { +"String" } } - } - } - +")" - } - } - } - tabbedGroup { - group { - tab(BasicTabbedContentType.CONSTRUCTOR) { - header { +"Constructors" } - table { - group { - link { +"SomeClass" } - platformHinted { - group { - +"constructor" - +"(" - +")" - } - group { - +"constructor" - +"(" - group { - group { - +"a: " - group { link { +"String" } } - } - } - +")" - } - } - } - } - } - } - skipAllNotMatching() - } - } - } - } - } - - - @OnlyDescriptors("Order of constructors is different in K2") - @Test - fun `class with a few documented constructors`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - | /** - | * some comment - | * @constructor ctor comment - | **/ - |class SomeClass(a: String){ - | /** - | * ctor one - | **/ - | constructor(): this("") - | - | /** - | * ctor two - | **/ - | constructor(b: Int): this("") - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "SomeClass" } as ContentPage - page.content.assertNode { - group { - header(1) { +"SomeClass" } - platformHinted { - group { - +"class " - link { +"SomeClass" } - +"(" - group { - group { - +"a: " - group { link { +"String" } } - } - } - +")" - } - skipAllNotMatching() - } - } - tabbedGroup { - group { - tab(BasicTabbedContentType.CONSTRUCTOR) { - header { +"Constructors" } - table { - group { - link { +"SomeClass" } - platformHinted { - group { - +"constructor" - +"(" - +")" - } - group { - group { - group { +"ctor one" } - } - } - group { - +"constructor" - +"(" - group { - group { - +"b: " - group { - link { +"Int" } - } - } - } - +")" - } - group { - group { - group { +"ctor two" } - } - } - group { - +"constructor" - +"(" - group { - group { - +"a: " - group { - link { +"String" } - } - } - } - +")" - } - group { - group { - group { +"ctor comment" } - } - } - } - } - } - } - } - skipAllNotMatching() - } - } - } - } - } - - @Test - fun `class with explicitly documented constructor`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - | /** - | * some comment - | * @constructor ctor comment - | **/ - |class SomeClass(a: String) - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "SomeClass" } as ContentPage - page.content.assertNode { - group { - header(1) { +"SomeClass" } - platformHinted { - group { - +"class " - link { +"SomeClass" } - +"(" - group { - group { - +"a: " - group { link { +"String" } } - } - } - +")" - } - skipAllNotMatching() - } - } - tabbedGroup { - group { - tab(BasicTabbedContentType.CONSTRUCTOR) { - header { +"Constructors" } - table { - group { - link { +"SomeClass" } - platformHinted { - group { - +"constructor" - +"(" - group { - group { - +"a: " - group { - link { +"String" } - } - } - } - +")" - } - group { - group { - group { +"ctor comment" } - } - } - } - } - } - } - } - skipAllNotMatching() - } - } - } - } - } - - @Test - fun `should render primary constructor, but not constructors block for annotation class`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |annotation class MyAnnotation(val param: String) {} - """.trimIndent(), - testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "MyAnnotation" } as ContentPage - page.content.assertNode { - group { - header(1) { +"MyAnnotation" } - platformHinted { - group { - +"annotation class " - link { +"MyAnnotation" } - +"(" - group { - group { - +"val param: " - group { link { +"String" } } - } - } - +")" - } - } - } - group { - group { - group { - header { +"Properties" } - table { - skipAllNotMatching() - } - } - } - } - } - } - } - } -} diff --git a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt deleted file mode 100644 index 8af9e082..00000000 --- a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt +++ /dev/null @@ -1,515 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package content.signatures - -import matchers.content.* -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest -import org.jetbrains.dokka.pages.ContentPage -import org.jetbrains.dokka.pages.PackagePageNode -import utils.ParamAttributes -import utils.bareSignature -import utils.propertySignature -import utils.typealiasSignature -import kotlin.test.Test - -class ContentForSignaturesTest : BaseAbstractTest() { - - private val testConfiguration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - analysisPlatform = "jvm" - documentedVisibilities = setOf( - DokkaConfiguration.Visibility.PUBLIC, - DokkaConfiguration.Visibility.PRIVATE, - DokkaConfiguration.Visibility.PROTECTED, - DokkaConfiguration.Visibility.INTERNAL, - ) - } - } - } - - @Test - fun `function`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |fun function(abc: String): String { - | return "Hello, " + abc - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage - page.content.assertNode { - group { - header(1) { +"function" } - } - divergentGroup { - divergentInstance { - divergent { - bareSignature( - emptyMap(), - "", - "", - emptySet(), - "function", - "String", - "abc" to ParamAttributes(emptyMap(), emptySet(), "String") - ) - } - } - } - } - } - } - } - - @Test - fun `private function`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |private fun function(abc: String): String { - | return "Hello, " + abc - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage - page.content.assertNode { - group { - header(1) { +"function" } - } - divergentGroup { - divergentInstance { - divergent { - bareSignature( - emptyMap(), - "private", - "", - emptySet(), - "function", - "String", - "abc" to ParamAttributes(emptyMap(), emptySet(), "String") - ) - } - } - } - } - } - } - } - - @Test - fun `open function`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |open fun function(abc: String): String { - | return "Hello, " + abc - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage - page.content.assertNode { - group { - header(1) { +"function" } - } - divergentGroup { - divergentInstance { - divergent { - bareSignature( - emptyMap(), - "", - "open", - emptySet(), - "function", - "String", - "abc" to ParamAttributes(emptyMap(), emptySet(), "String") - ) - } - } - } - } - } - } - } - - @Test - fun `function without parameters`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |fun function(): String { - | return "Hello" - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage - page.content.assertNode { - group { - header(1) { +"function" } - } - divergentGroup { - divergentInstance { - divergent { - bareSignature( - annotations = emptyMap(), - visibility = "", - modifier = "", - keywords = emptySet(), - name = "function", - returnType = "String", - ) - } - } - } - - } - } - } - } - - - @Test - fun `suspend function`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |suspend fun function(abc: String): String { - | return "Hello, " + abc - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage - page.content.assertNode { - group { - header(1) { +"function" } - } - divergentGroup { - divergentInstance { - divergent { - bareSignature( - emptyMap(), - "", - "", - setOf("suspend"), - "function", - "String", - "abc" to ParamAttributes(emptyMap(), emptySet(), "String") - ) - } - } - } - } - } - } - } - - @Test - fun `protected open suspend function`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |protected open suspend fun function(abc: String): String { - | return "Hello, " + abc - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage - page.content.assertNode { - group { - header(1) { +"function" } - } - divergentGroup { - divergentInstance { - divergent { - bareSignature( - emptyMap(), - "protected", - "open", - setOf("suspend"), - "function", - "String", - "abc" to ParamAttributes(emptyMap(), emptySet(), "String") - ) - } - } - } - } - } - } - } - - @Test - fun `protected open suspend inline function`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |protected open suspend inline fun function(abc: String): String { - | return "Hello, " + abc - |} - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } - .children.single { it.name == "function" } as ContentPage - page.content.assertNode { - group { - header(1) { +"function" } - } - divergentGroup { - divergentInstance { - divergent { - bareSignature( - emptyMap(), - "protected", - "open", - setOf("inline", "suspend"), - "function", - "String", - "abc" to ParamAttributes(emptyMap(), emptySet(), "String") - ) - } - } - } - } - } - } - } - - @Test - fun `property`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |val property: Int = 6 - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - propertySignature(emptyMap(), "", "", emptySet(), "val", "property", "Int", "6") - } - } - } - } - - @Test - fun `const property`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |const val property: Int = 6 - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - propertySignature(emptyMap(), "", "", setOf("const"), "val", "property", "Int", "6") - } - } - } - } - - @Test - fun `protected property`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |protected val property: Int = 6 - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - propertySignature(emptyMap(), "protected", "", emptySet(), "val", "property", "Int", "6") - } - } - } - } - - @Test - fun `protected lateinit property`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |protected lateinit var property: Int = 6 - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - propertySignature(emptyMap(), "protected", "", setOf("lateinit"), "var", "property", "Int", null) - } - } - } - } - - @Test - fun `should not display default value for mutable property`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |var property: Int = 6 - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - propertySignature( - annotations = emptyMap(), - visibility = "", - modifier = "", - keywords = setOf(), - preposition = "var", - name = "property", - type = "Int", - value = null - ) - } - } - } - } - - @Test - fun `typealias to String`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |typealias Alias = String - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - typealiasSignature("Alias", "String") - } - } - } - } - - @Test - fun `typealias to Int`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |typealias Alias = Int - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - typealiasSignature("Alias", "Int") - } - } - } - } - - @Test - fun `typealias to type in same package`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - | - |typealias Alias = X - |class X - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - typealiasSignature("Alias", "X") - } - } - } - } - - @Test - fun `typealias to type in different package`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - |import other.X - |typealias Alias = X - | - |/src/main/kotlin/test/source2.kt - |package other - |class X - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - typealiasSignature("Alias", "X") - } - } - } - } - - @Test - fun `typealias to type in different package with same name`() { - testInline( - """ - |/src/main/kotlin/test/source.kt - |package test - |typealias Alias = other.Alias - | - |/src/main/kotlin/test/source2.kt - |package other - |class Alias - """.trimIndent(), testConfiguration - ) { - pagesTransformationStage = { module -> - val page = module.children.single { it.name == "test" } as PackagePageNode - page.content.assertNode { - typealiasSignature("Alias", "other.Alias") - } - } - } - } -} |