diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-26 16:09:04 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-31 15:10:04 +0200 |
commit | 3935b4e05c13528e5b8f4b99aea1962ab904a8ee (patch) | |
tree | 219b470d72d6735859275d40543d6499436379bb | |
parent | 855718815ff58660a965b29247137355e67160c9 (diff) | |
download | dokka-3935b4e05c13528e5b8f4b99aea1962ab904a8ee.tar.gz dokka-3935b4e05c13528e5b8f4b99aea1962ab904a8ee.tar.bz2 dokka-3935b4e05c13528e5b8f4b99aea1962ab904a8ee.zip |
Implement `root package is matched by empty string and the root keyword` test
4 files changed, 112 insertions, 9 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt index 4900e9a8..e712d6e5 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt @@ -56,6 +56,13 @@ private class ContextModuleAndPackageDocumentationReader( } } + private val ModuleAndPackageDocumentationFragment.canonicalPackageName: String + get() { + check(classifier == Classifier.Package) + if (name == "[root]") return "" + return name + } + override fun get(module: DModule): SourceSetDependent<DocumentationNode> { return findDocumentationNodes(module.sourceSets) { fragment -> fragment.classifier == Classifier.Module && ( @@ -68,8 +75,7 @@ private class ContextModuleAndPackageDocumentationReader( override fun get(pkg: DPackage): SourceSetDependent<DocumentationNode> { return findDocumentationNodes(pkg.sourceSets) { fragment -> - // TODO NOW: handle JS Root thing - fragment.classifier == Classifier.Package && fragment.name == pkg.dri.packageName + fragment.classifier == Classifier.Package && fragment.canonicalPackageName == pkg.dri.packageName } } } diff --git a/plugins/base/src/test/kotlin/transformers/AbstractContextModuleAndPackageDocumentationReaderTest.kt b/plugins/base/src/test/kotlin/transformers/AbstractContextModuleAndPackageDocumentationReaderTest.kt index 7f435013..0f26b2f5 100644 --- a/plugins/base/src/test/kotlin/transformers/AbstractContextModuleAndPackageDocumentationReaderTest.kt +++ b/plugins/base/src/test/kotlin/transformers/AbstractContextModuleAndPackageDocumentationReaderTest.kt @@ -12,11 +12,12 @@ abstract class AbstractContextModuleAndPackageDocumentationReaderTest { protected lateinit var temporaryDirectory: Path - protected val SourceSetDependent<DocumentationNode>.texts: List<String> - get() = values.flatMap { it.withDescendants() } - .flatMap { it.children } - .flatMap { it.children } - .mapNotNull { it as? Text } - .map { it.body } - + companion object { + val SourceSetDependent<DocumentationNode>.texts: List<String> + get() = values.flatMap { it.withDescendants() } + .flatMap { it.children } + .flatMap { it.children } + .mapNotNull { it as? Text } + .map { it.body } + } } diff --git a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt new file mode 100644 index 00000000..e1b9d199 --- /dev/null +++ b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt @@ -0,0 +1,59 @@ +package transformers + +import org.jetbrains.dokka.base.transformers.documentables.ModuleAndPackageDocumentationReader +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.DPackage +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.utilities.DokkaConsoleLogger +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import testApi.testRunner.dokkaConfiguration +import testApi.testRunner.sourceSet +import kotlin.test.assertEquals + +class ContextModuleAndPackageDocumentationReaderTest3 : AbstractContextModuleAndPackageDocumentationReaderTest() { + + private val include by lazy { temporaryDirectory.resolve("include.md").toFile() } + + @BeforeEach + fun materializeInclude() { + include.writeText( + """ + # Package + This is the root package + + # Package [root] + This is also the root package + """.trimIndent() + ) + } + + private val sourceSet by lazy { + sourceSet { + includes = listOf(include.canonicalPath) + } + } + + private val context by lazy { + DokkaContext.create( + configuration = dokkaConfiguration { + sourceSets { + add(sourceSet) + } + }, + logger = DokkaConsoleLogger, + pluginOverrides = emptyList() + ) + } + + private val reader by lazy { ModuleAndPackageDocumentationReader(context) } + + + @Test + fun `root package is matched by empty string and the root keyword`() { + val documentation = reader[DPackage(DRI(""), sourceSets = setOf(sourceSet))] + assertEquals( + listOf("This is the root package", "This is also the root package"), documentation.texts + ) + } +} diff --git a/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt index e622e79d..2d356a81 100644 --- a/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt @@ -4,6 +4,7 @@ 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 transformers.AbstractContextModuleAndPackageDocumentationReaderTest.Companion.texts import java.nio.file.Path import kotlin.test.assertEquals @@ -20,6 +21,9 @@ class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest( # Package This is the root package + # Package [root] + This is also the root package + # Package common This is the common package @@ -47,6 +51,7 @@ class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest( analysisPlatform = "js" sourceRoots = listOf("src/jsMain/kotlin") dependentSourceSets = setOf(DokkaSourceSetID("moduleA", "commonMain")) + includes = listOf(include.canonicalPath) } sourceSet { moduleName = "moduleA" @@ -55,6 +60,7 @@ class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest( analysisPlatform = "jvm" sourceRoots = listOf("src/jvmMain/kotlin") dependentSourceSets = setOf(DokkaSourceSetID("moduleA", "commonMain")) + includes = listOf(include.canonicalPath) } } } @@ -90,6 +96,37 @@ class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest( listOf("", "common", "js", "jvm").sorted(), packageNames.sorted(), "Expected all packages to be present" ) + + /* Assert module documentation */ + assertEquals(3, module.documentation.keys.size, "Expected all three source sets") + assertEquals("This is moduleA", module.documentation.texts.distinct().joinToString()) + + /* Assert root package */ + val rootPackage = module.packages.single { it.dri.packageName == "" } + assertEquals(3, rootPackage.documentation.keys.size, "Expected all three source sets") + assertEquals( + listOf("This is the root package", "This is also the root package"), + rootPackage.documentation.texts.distinct() + ) + + /* Assert common package */ + val commonPackage = module.packages.single { it.dri.packageName == "common" } + assertEquals(3, commonPackage.documentation.keys.size, "Expected all three source sets") + assertEquals("This is the common package", commonPackage.documentation.texts.distinct().joinToString()) + + /* Assert js package */ + val jsPackage = module.packages.single { it.dri.packageName == "js" } + assertEquals( + "This is the js package", + jsPackage.documentation.texts.joinToString() + ) + + /* Assert the jvm package */ + val jvmPackage = module.packages.single { it.dri.packageName == "jvm" } + assertEquals( + "This is the jvm package", + jvmPackage.documentation.texts.joinToString() + ) } } } |