aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test
diff options
context:
space:
mode:
authorMarcin Aman <maman@virtuslab.com>2020-05-25 14:40:59 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-06-03 11:45:54 +0200
commitf0742fb7f8a937ef7c2e5a92d6f4a0fd079baa62 (patch)
treef7c7b8c7844b862b784a1651db5a4cb235207e41 /plugins/base/src/test
parent02ddcd61dea19efd60c0da972ac0b5bd1d6ebf89 (diff)
downloaddokka-f0742fb7f8a937ef7c2e5a92d6f4a0fd079baa62.tar.gz
dokka-f0742fb7f8a937ef7c2e5a92d6f4a0fd079baa62.tar.bz2
dokka-f0742fb7f8a937ef7c2e5a92d6f4a0fd079baa62.zip
Enum constructor values
Diffstat (limited to 'plugins/base/src/test')
-rw-r--r--plugins/base/src/test/kotlin/enums/EnumsTest.kt146
-rw-r--r--plugins/base/src/test/kotlin/utils/contentUtils.kt2
2 files changed, 144 insertions, 4 deletions
diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt
index 5f8bf8c8..6c44dc35 100644
--- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt
+++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt
@@ -1,11 +1,16 @@
package enums
+import matchers.content.assertNode
+import matchers.content.group
+import matchers.content.header
+import matchers.content.link
+import org.jetbrains.dokka.model.ConstructorValues
import org.jetbrains.dokka.model.DEnum
-import org.jetbrains.dokka.pages.ClasslikePageNode
-import org.jetbrains.dokka.pages.ModulePageNode
-import org.junit.jupiter.api.Test
+import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.junit.jupiter.api.Assertions.*
+import org.junit.jupiter.api.Test
+import utils.unwrapAnnotation
class EnumsTest : AbstractCoreTest() {
@@ -85,7 +90,142 @@ class EnumsTest : AbstractCoreTest() {
}
}
+ @Test
+ fun enumWithConstructor() {
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/basic/Test.kt
+ |package enums
+ |
+ |
+ |enum class Test(name: String, index: Int, excluded: Boolean) {
+ | E1("e1", 1, true),
+ | E2("e2", 2, false);
+ |}
+ """.trimMargin(),
+ configuration
+ ) {
+ documentablesTransformationStage = { m ->
+ m.packages.let { p ->
+ p.first().classlikes.let { c ->
+ val enum = c.first() as DEnum
+ val (first, second) = enum.entries
+
+ assertEquals(1, first.extra.allOfType<ConstructorValues>().size)
+ assertEquals(1, second.extra.allOfType<ConstructorValues>().size)
+ assertEquals(listOf("\"e1\"", "1", "true"), first.extra.allOfType<ConstructorValues>().first().values)
+ assertEquals(listOf("\"e2\"", "2", "false"), second.extra.allOfType<ConstructorValues>().first().values)
+ }
+ }
+ }
+ pagesGenerationStage = { module ->
+ val entryPage = module.dfs { it.name == "E1" } as ClasslikePageNode
+ val signaturePart = (entryPage.content.dfs {
+ it is ContentGroup && it.dci.toString() == "[enums/Test.E1///PointingToDeclaration/][Symbol]"
+ } as ContentGroup).children.first() as ContentGroup
+ assertEquals("(\"e1\", 1, true)", signaturePart.constructorSignature())
+ }
+ }
+ }
+
+ @Test
+ fun enumWithMethods() {
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/basic/Test.kt
+ |package enums
+ |
+ |
+ |interface Sample {
+ | fun toBeImplemented(): String
+ |}
+ |
+ |enum class Test: Sample {
+ | E1 {
+ | override fun toBeImplemented(): String = "e1"
+ | }
+ |}
+ """.trimMargin(),
+ configuration
+ ) {
+ documentablesTransformationStage = { m ->
+ m.packages.let { p ->
+ p.first().classlikes.let { c ->
+ val enum = c.first { it is DEnum } as DEnum
+ val first = enum.entries.first()
+
+ assertEquals(1, first.extra.allOfType<ConstructorValues>().size)
+ assertEquals(emptyList<String>(), first.extra.allOfType<ConstructorValues>().first().values)
+ assertNotNull(first.functions.find { it.name == "toBeImplemented" })
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ fun enumWithAnnotationsOnEntries(){
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/basic/Test.kt
+ |package enums
+ |
+ |enum class Test {
+ | @SinceKotlin("1.3")
+ | E1
+ |}
+ """.trimMargin(),
+ configuration
+ ) {
+ pagesTransformationStage = { m ->
+ val entryNode = m.children.first { it.name == "enums" }.children.first { it.name == "Test" }.children.first() as ClasslikePageNode
+ val signature = (entryNode.content as ContentGroup).dfs { it is ContentGroup && it.dci.toString() == "[enums/Test.E1///PointingToDeclaration/][Cover]" } as ContentGroup
+
+ signature.assertNode {
+ header(1) { +"E1" }
+ group {
+ mapOf("SinceKotlin" to setOf("version")).entries.forEach {
+ group {
+ group {
+ unwrapAnnotation(it)
+ }
+ link { +"E1" }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
fun ModulePageNode.getClasslikeToMemberMap() =
this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy({ it.value }) { it.key }
+
+ private fun ContentGroup.constructorSignature(): String =
+ children.drop(1).joinToString(separator = "") { (it as ContentText).text }
} \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/utils/contentUtils.kt b/plugins/base/src/test/kotlin/utils/contentUtils.kt
index 4aba3e9d..7e1b8bf4 100644
--- a/plugins/base/src/test/kotlin/utils/contentUtils.kt
+++ b/plugins/base/src/test/kotlin/utils/contentUtils.kt
@@ -184,7 +184,7 @@ fun ContentMatcherBuilder<*>.unnamedTag(tag: String, content: ContentMatcherBuil
group { content() }
}
-private fun ContentMatcherBuilder<*>.unwrapAnnotation(elem: Map.Entry<String, Set<String>>) {
+fun ContentMatcherBuilder<*>.unwrapAnnotation(elem: Map.Entry<String, Set<String>>) {
+"@"
link { +elem.key }
+"("