aboutsummaryrefslogtreecommitdiff
path: root/plugins/javadoc/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/javadoc/src/test/kotlin')
-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")
+ }
+ }
+}