aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-08-26 14:49:31 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-31 15:10:04 +0200
commit855718815ff58660a965b29247137355e67160c9 (patch)
tree82884ed2efc89adf3e44a22f3b24813238bb9e39 /plugins
parent9bf535bf8c0b758fc0abf99b61208fa5430239d6 (diff)
downloaddokka-855718815ff58660a965b29247137355e67160c9.tar.gz
dokka-855718815ff58660a965b29247137355e67160c9.tar.bz2
dokka-855718815ff58660a965b29247137355e67160c9.zip
WIP
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt14
-rw-r--r--plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt31
-rw-r--r--plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt96
-rw-r--r--plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerUnitTest.kt (renamed from plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerTest.kt)2
4 files changed, 122 insertions, 21 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt
index 2667681c..6155af52 100644
--- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt
+++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.parsers.moduleAndPackage
+import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier.*
import java.io.File
@@ -24,17 +25,18 @@ private fun parseModuleAndPackageDocFragment(
val firstLine = firstLineAndDocumentation[0]
val classifierAndName = firstLine.split(Regex("\\s+"), limit = 2)
- if (classifierAndName.size != 2) {
- throw IllegalModuleAndPackageDocumentation(source, "Missing ${classifierAndName.first()} name")
- }
val classifier = when (classifierAndName[0].trim()) {
- "Module" -> ModuleAndPackageDocumentation.Classifier.Module
- "Package" -> ModuleAndPackageDocumentation.Classifier.Package
+ "Module" -> Module
+ "Package" -> Package
else -> throw IllegalStateException("Unexpected classifier ${classifierAndName[0]}")
}
- val name = classifierAndName[1].trim()
+ if (classifierAndName.size != 2 && classifier == Module) {
+ throw IllegalModuleAndPackageDocumentation(source, "Missing Module name")
+ }
+
+ val name = classifierAndName.getOrNull(1)?.trim().orEmpty()
if (name.contains(Regex("\\s"))) {
throw IllegalModuleAndPackageDocumentation(
source, "Module/Package name cannot contain whitespace in '$firstLine'"
diff --git a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt
index 5c0a0646..17f9631a 100644
--- a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt
+++ b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt
@@ -76,21 +76,24 @@ class ParseModuleAndPackageDocumentationFragmentsTest {
}
@Test
- fun `no package name specified fails`() {
- val exception = assertThrows<IllegalModuleAndPackageDocumentation> {
- parseModuleAndPackageDocumentationFragments(
- source(
- """
- # Package
- No package name given
- """.trimIndent()
- )
- )
- }
+ fun `no package name specified does not fail`() {
+ val source = source(
+ """
+ # Package
+ This is a root package
+ """.trimIndent()
+ )
+ val fragments = parseModuleAndPackageDocumentationFragments(source)
+ assertEquals(1, fragments.size, "Expected a single package fragment")
- assertTrue(
- "Missing Package name" in exception.message.orEmpty(),
- "Expected 'Missing Package name' in error message"
+ assertEquals(
+ ModuleAndPackageDocumentationFragment(
+ name = "",
+ classifier = Package,
+ documentation = "This is a root package",
+ source = source
+ ),
+ fragments.single()
)
}
diff --git a/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt
new file mode 100644
index 00000000..e622e79d
--- /dev/null
+++ b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt
@@ -0,0 +1,96 @@
+package transformers
+
+import org.jetbrains.dokka.DokkaSourceSetID
+import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.io.TempDir
+import java.nio.file.Path
+import kotlin.test.assertEquals
+
+class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest() {
+
+ @Test
+ fun `multiplatform project`(@TempDir tempDir: Path) {
+ val include = tempDir.resolve("include.md").toFile()
+ include.writeText(
+ """
+ # Module moduleA
+ This is moduleA
+
+ # Package
+ This is the root package
+
+ # Package common
+ This is the common package
+
+ # Package jvm
+ This is the jvm package
+
+ # Package js
+ This is the js package
+ """.trimIndent()
+ )
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ moduleName = "moduleA"
+ name = "commonMain"
+ displayName = "common"
+ analysisPlatform = "common"
+ sourceRoots = listOf("src/commonMain/kotlin")
+ includes = listOf(include.canonicalPath)
+ }
+ sourceSet {
+ moduleName = "moduleA"
+ name = "jsMain"
+ displayName = "js"
+ analysisPlatform = "js"
+ sourceRoots = listOf("src/jsMain/kotlin")
+ dependentSourceSets = setOf(DokkaSourceSetID("moduleA", "commonMain"))
+ }
+ sourceSet {
+ moduleName = "moduleA"
+ name = "jvmMain"
+ displayName = "jvm"
+ analysisPlatform = "jvm"
+ sourceRoots = listOf("src/jvmMain/kotlin")
+ dependentSourceSets = setOf(DokkaSourceSetID("moduleA", "commonMain"))
+ }
+ }
+ }
+
+ testInline(
+ """
+ /src/commonMain/kotlin/common/CommonApi.kt
+ package common
+ val commonApi = "common"
+
+ /src/jsMain/kotlin/js/JsApi.kt
+ package js
+ val jsApi = "js"
+
+ /src/jvmMain/kotlin/jvm/JvmApi.kt
+ package jvm
+ val jvmApi = "jvm"
+
+ /src/commonMain/kotlin/CommonRoot.kt
+ val commonRoot = "commonRoot"
+
+ /src/jsMain/kotlin/JsRoot.kt
+ val jsRoot = "jsRoot"
+
+ /src/jvmMain/kotlin/JvmRoot.kt
+ val jvmRoot = "jvmRoot"
+ """.trimIndent(),
+ configuration
+ ) {
+ this.documentablesMergingStage = { module ->
+ val packageNames = module.packages.map { it.dri.packageName ?: "NULL" }
+ assertEquals(
+ listOf("", "common", "js", "jvm").sorted(), packageNames.sorted(),
+ "Expected all packages to be present"
+ )
+ }
+ }
+ }
+}
diff --git a/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerUnitTest.kt
index d2b41273..b75f8e5b 100644
--- a/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerTest.kt
+++ b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerUnitTest.kt
@@ -13,7 +13,7 @@ import testApi.testRunner.documentationNode
import testApi.testRunner.sourceSet
-class ModuleAndPackageDocumentationTransformerTest {
+class ModuleAndPackageDocumentationTransformerUnitTest {
@Test
fun `empty list of modules`() {