-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[K2] Fix
@constructor
documentation for primary constructors (#3499)
- Loading branch information
Showing
3 changed files
with
188 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
dokka-subprojects/plugin-base/src/test/kotlin/model/ConstructorsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package model | ||
|
||
import org.jetbrains.dokka.analysis.kotlin.markdown.MARKDOWN_ELEMENT_FILE_NAME | ||
import org.jetbrains.dokka.model.* | ||
import org.jetbrains.dokka.model.doc.* | ||
import org.jetbrains.dokka.model.doc.P | ||
import kotlin.test.Test | ||
import utils.* | ||
|
||
|
||
class ConstructorsTest : AbstractModelTest("/src/main/kotlin/constructors/Test.kt", "constructors") { | ||
|
||
@Test | ||
fun `should have documentation for @constructor tag without parameters`() { | ||
val expectedRootDescription = Description( | ||
CustomDocTag( | ||
emptyList(), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
|
||
val expectedConstructorTag = Constructor( | ||
CustomDocTag( | ||
listOf( | ||
P( | ||
listOf( | ||
Text("some doc"), | ||
) | ||
) | ||
), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
val expectedDescriptionTag = Description( | ||
CustomDocTag( | ||
listOf( | ||
P( | ||
listOf( | ||
Text("some doc"), | ||
) | ||
) | ||
), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
inlineModelTest( | ||
""" | ||
|/** | ||
|* @constructor some doc | ||
|*/ | ||
|class A | ||
""".trimMargin() | ||
) { | ||
val classlike = packages.flatMap { it.classlikes }.first() as DClass | ||
classlike.name equals "A" | ||
classlike.documentation.values.single() equals DocumentationNode(listOf(expectedRootDescription, expectedConstructorTag)) | ||
val constructor = classlike.constructors.single() | ||
constructor.documentation.values.single() equals DocumentationNode(listOf(expectedDescriptionTag)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `should have documentation for @constructor tag`() { | ||
|
||
val expectedRootDescription = Description( | ||
CustomDocTag( | ||
emptyList(), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
|
||
val expectedConstructorTag = Constructor( | ||
CustomDocTag( | ||
listOf( | ||
P( | ||
listOf( | ||
Text("some doc"), | ||
) | ||
) | ||
), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
val expectedDescriptionTag = Description( | ||
CustomDocTag( | ||
listOf( | ||
P( | ||
listOf( | ||
Text("some doc"), | ||
) | ||
) | ||
), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
inlineModelTest( | ||
""" | ||
|/** | ||
|* @constructor some doc | ||
|*/ | ||
|class A(a: Int) | ||
""".trimMargin() | ||
) { | ||
val classlike = packages.flatMap { it.classlikes }.first() as DClass | ||
classlike.name equals "A" | ||
classlike.documentation.values.single() equals DocumentationNode(listOf(expectedRootDescription, expectedConstructorTag)) | ||
val constructor = classlike.constructors.single() | ||
constructor.documentation.values.single() equals DocumentationNode(listOf(expectedDescriptionTag)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `should ignore documentation in @constructor tag for a secondary constructor`() { | ||
val expectedRootDescription = Description( | ||
CustomDocTag( | ||
emptyList(), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
|
||
val expectedConstructorTag = Constructor( | ||
CustomDocTag( | ||
listOf( | ||
P( | ||
listOf( | ||
Text("some doc"), | ||
) | ||
) | ||
), | ||
params = emptyMap(), | ||
name = MARKDOWN_ELEMENT_FILE_NAME | ||
) | ||
) | ||
|
||
inlineModelTest( | ||
""" | ||
|/** | ||
|* @constructor some doc | ||
|*/ | ||
|class A { | ||
| constructor(a: Int) | ||
|} | ||
""".trimMargin() | ||
) { | ||
val classlike = packages.flatMap { it.classlikes }.first() as DClass | ||
classlike.name equals "A" | ||
classlike.documentation.values.single() equals DocumentationNode(listOf(expectedRootDescription, expectedConstructorTag)) | ||
val constructor = classlike.constructors.single() | ||
constructor.documentation.isEmpty() equals true | ||
} | ||
} | ||
|
||
} |