aboutsummaryrefslogtreecommitdiff
path: root/plugins/javadoc/src/test
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-06-30 08:03:38 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-01 09:43:03 +0200
commita16e101fad10d024a84aa36069ec6032fcbaf3e6 (patch)
tree64e19695dccd67c3e1b1621eeac2ad469e01cb46 /plugins/javadoc/src/test
parent14e71e40dfab5f18ccd56b0c015383c0dfb5df51 (diff)
downloaddokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.gz
dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.bz2
dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.zip
Implement `AbstractJavadocTemplateMapTest` API
Diffstat (limited to 'plugins/javadoc/src/test')
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt69
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt22
2 files changed, 91 insertions, 0 deletions
diff --git a/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt
new file mode 100644
index 00000000..7b31d064
--- /dev/null
+++ b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt
@@ -0,0 +1,69 @@
+package javadoc
+
+import javadoc.pages.JavadocPageNode
+import javadoc.renderer.JavadocContentToTemplateMapTranslator
+import org.jetbrains.dokka.DokkaConfigurationImpl
+import org.jetbrains.dokka.javadoc.JavadocPlugin
+import org.jetbrains.dokka.model.withDescendants
+import org.jetbrains.dokka.pages.RootPageNode
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.plugability.plugin
+import org.jetbrains.dokka.plugability.querySingle
+import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
+
+internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() {
+ protected var config: DokkaConfigurationImpl = dokkaConfiguration {
+ format = "javadoc"
+ passes {
+ pass {
+ sourceRoots = listOf("src")
+ analysisPlatform = "jvm"
+ }
+ }
+ }
+
+ data class Result(
+ val rootPageNode: RootPageNode,
+ val context: DokkaContext
+ ) {
+
+ val translator: JavadocContentToTemplateMapTranslator by lazy {
+ val locationProvider = context.plugin<JavadocPlugin>()
+ .querySingle { locationProviderFactory }
+ .getLocationProvider(rootPageNode)
+
+ JavadocContentToTemplateMapTranslator(locationProvider, context)
+ }
+
+ val JavadocPageNode.templateMap: Map<String, Any?> get() = translator.templateMapForPageNode(this)
+
+ inline fun <reified T : JavadocPageNode> allPagesOfType(): List<T> {
+ return rootPageNode.withDescendants().filterIsInstance<T>().toList()
+ }
+
+ inline fun <reified T : JavadocPageNode> firstPageOfType(): T {
+ return rootPageNode.withDescendants().filterIsInstance<T>().first()
+ }
+
+ inline fun <reified T : JavadocPageNode> firstPageOfTypeOrNull(): T? {
+ return rootPageNode.withDescendants().filterIsInstance<T>().firstOrNull()
+ }
+
+ inline fun <reified T : JavadocPageNode> singlePageOfType(): T {
+ return rootPageNode.withDescendants().filterIsInstance<T>().single()
+ }
+ }
+
+ fun testTemplateMapInline(
+ query: String,
+ configuration: DokkaConfigurationImpl = config,
+ assertions: Result.() -> Unit
+ ) {
+ testInline(query, configuration) {
+ renderingStage = { rootPageNode, dokkaContext ->
+ Result(rootPageNode, dokkaContext).assertions()
+ }
+ }
+ }
+}
+
diff --git a/plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt
new file mode 100644
index 00000000..732454f7
--- /dev/null
+++ b/plugins/javadoc/src/test/kotlin/javadoc/JavadocModuleTemplateMapTest.kt
@@ -0,0 +1,22 @@
+package javadoc
+
+import javadoc.pages.JavadocModulePageNode
+import org.junit.jupiter.api.Test
+
+internal class JavadocModuleTemplateMapTest : AbstractJavadocTemplateMapTest() {
+
+ @Test
+ fun simpleKotlinExample() {
+ testTemplateMapInline(
+ """
+ /src/source.kt
+ package test
+ class Test
+ """.trimIndent(),
+ config
+ ) {
+ val moduleContentMap = singlePageOfType<JavadocModulePageNode>().templateMap
+ println("module")
+ }
+ }
+}