aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/base-test-utils
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/base-test-utils')
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt41
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/renderers/RenderingOnlyTestBase.kt6
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt14
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/renderers/TestPage.kt4
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/testRunner/baseTestApi.kt102
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/utils/TestOutputWriter.kt18
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt2
7 files changed, 100 insertions, 87 deletions
diff --git a/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt
index 9a715e39..fcd73ff0 100644
--- a/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt
+++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt
@@ -8,7 +8,7 @@ import org.jsoup.nodes.Element
import org.jsoup.nodes.Node
import org.jsoup.nodes.TextNode
-fun Element.match(vararg matchers: Any, ignoreSpanWithTokenStyle:Boolean = false): Unit =
+public fun Element.match(vararg matchers: Any, ignoreSpanWithTokenStyle:Boolean = false): Unit =
childNodes()
.let { list ->
if(ignoreSpanWithTokenStyle) {
@@ -25,25 +25,28 @@ fun Element.match(vararg matchers: Any, ignoreSpanWithTokenStyle:Boolean = false
.zip(matchers)
.forEach { (n, m) -> m.accepts(n, ignoreSpan = ignoreSpanWithTokenStyle) }
-open class Tag(val name: String, vararg val matchers: Any, val expectedClasses: List<String> = emptyList())
-class Div(vararg matchers: Any) : Tag("div", *matchers)
-class P(vararg matchers: Any) : Tag("p", *matchers)
-class Span(vararg matchers: Any) : Tag("span", *matchers)
-class A(vararg matchers: Any) : Tag("a", *matchers)
-class B(vararg matchers: Any) : Tag("b", *matchers)
-class I(vararg matchers: Any) : Tag("i", *matchers)
-class STRIKE(vararg matchers: Any) : Tag("strike", *matchers)
+public open class Tag(
+ public val name: String,
+ public vararg val matchers: Any,
+ public val expectedClasses: List<String> = emptyList()
+)
+public class Div(vararg matchers: Any) : Tag("div", *matchers)
+public class P(vararg matchers: Any) : Tag("p", *matchers)
+public class Span(vararg matchers: Any) : Tag("span", *matchers)
+public class A(vararg matchers: Any) : Tag("a", *matchers)
+public class B(vararg matchers: Any) : Tag("b", *matchers)
+public class I(vararg matchers: Any) : Tag("i", *matchers)
+public class STRIKE(vararg matchers: Any) : Tag("strike", *matchers)
+public class BlockQuote(vararg matchers: Any) : Tag("blockquote", *matchers)
+public class Dl(vararg matchers: Any) : Tag("dl", *matchers)
+public class Dt(vararg matchers: Any) : Tag("dt", *matchers)
+public class Dd(vararg matchers: Any) : Tag("dd", *matchers)
+public class Var(vararg matchers: Any) : Tag("var", *matchers)
+public class U(vararg matchers: Any) : Tag("u", *matchers)
+public object Wbr : Tag("wbr")
+public object Br : Tag("br")
-class BlockQuote(vararg matchers: Any) : Tag("blockquote", *matchers)
-class Dl(vararg matchers: Any) : Tag("dl", *matchers)
-class Dt(vararg matchers: Any) : Tag("dt", *matchers)
-class Dd(vararg matchers: Any) : Tag("dd", *matchers)
-class Var(vararg matchers: Any) : Tag("var", *matchers)
-class U(vararg matchers: Any) : Tag("u", *matchers)
-object Wbr : Tag("wbr")
-object Br : Tag("br")
-
-fun Tag.withClasses(vararg classes: String) = Tag(name, *matchers, expectedClasses = classes.toList())
+public fun Tag.withClasses(vararg classes: String): Tag = Tag(name, *matchers, expectedClasses = classes.toList())
private fun Any.accepts(n: Node, ignoreSpan:Boolean = true) {
when (this) {
diff --git a/plugins/base/base-test-utils/src/main/kotlin/renderers/RenderingOnlyTestBase.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/RenderingOnlyTestBase.kt
index cc050d0f..d2ff3ad4 100644
--- a/plugins/base/base-test-utils/src/main/kotlin/renderers/RenderingOnlyTestBase.kt
+++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/RenderingOnlyTestBase.kt
@@ -6,7 +6,7 @@ package renderers
import org.jetbrains.dokka.testApi.context.MockContext
-abstract class RenderingOnlyTestBase<T> {
- abstract val context: MockContext
- abstract val renderedContent: T
+public abstract class RenderingOnlyTestBase<T> {
+ public abstract val context: MockContext
+ public abstract val renderedContent: T
}
diff --git a/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt
index da4cd732..ecbe809b 100644
--- a/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt
+++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt
@@ -10,14 +10,14 @@ import org.jsoup.select.Elements
import utils.Tag
import utils.TestOutputWriter
-fun TestOutputWriter.renderedContent(path: String = "root/example.html"): Element =
+public fun TestOutputWriter.renderedContent(path: String = "root/example.html"): Element =
contents.getValue(path).let { Jsoup.parse(it) }.select("#content")
.single()
-fun Element.signature(): Elements = select("div.symbol.monospace")
-fun Element.tab(tabName: String): Elements = select("div[data-togglable=\"$tabName\"]")
-fun Element.firstSignature(): Element = signature().first() ?: throw NoSuchElementException("No signature found")
-fun Element.lastSignature(): Element = signature().last() ?: throw NoSuchElementException("No signature found")
+public fun Element.signature(): Elements = select("div.symbol.monospace")
+public fun Element.tab(tabName: String): Elements = select("div[data-togglable=\"$tabName\"]")
+public fun Element.firstSignature(): Element = signature().first() ?: throw NoSuchElementException("No signature found")
+public fun Element.lastSignature(): Element = signature().last() ?: throw NoSuchElementException("No signature found")
-class Parameters(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameters"))
-class Parameter(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameter"))
+public class Parameters(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameters"))
+public class Parameter(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameter"))
diff --git a/plugins/base/base-test-utils/src/main/kotlin/renderers/TestPage.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/TestPage.kt
index c5615f9b..6fb484bf 100644
--- a/plugins/base/base-test-utils/src/main/kotlin/renderers/TestPage.kt
+++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/TestPage.kt
@@ -15,7 +15,7 @@ import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.jetbrains.dokka.utilities.LoggingLevel
-fun testPage(callback: PageContentBuilder.DocumentableContentBuilder.() -> Unit): RawTestPage {
+public fun testPage(callback: PageContentBuilder.DocumentableContentBuilder.() -> Unit): RawTestPage {
val content = PageContentBuilder(
EmptyCommentConverter,
KotlinSignatureProvider(EmptyCommentConverter, DokkaConsoleLogger(LoggingLevel.DEBUG)),
@@ -29,7 +29,7 @@ fun testPage(callback: PageContentBuilder.DocumentableContentBuilder.() -> Unit)
return RawTestPage(content)
}
-class RawTestPage(
+public class RawTestPage(
override val content: ContentNode,
override val name: String = "testPage",
override val dri: Set<DRI> = setOf(DRI.topLevel),
diff --git a/plugins/base/base-test-utils/src/main/kotlin/testRunner/baseTestApi.kt b/plugins/base/base-test-utils/src/main/kotlin/testRunner/baseTestApi.kt
index d9b2b1d2..3dc0e54b 100644
--- a/plugins/base/base-test-utils/src/main/kotlin/testRunner/baseTestApi.kt
+++ b/plugins/base/base-test-utils/src/main/kotlin/testRunner/baseTestApi.kt
@@ -21,52 +21,54 @@ import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.utilities.LoggingLevel
-class BaseDokkaTestGenerator(
+public class BaseDokkaTestGenerator(
configuration: DokkaConfiguration,
logger: DokkaLogger,
testMethods: BaseTestMethods,
additionalPlugins: List<DokkaPlugin> = emptyList()
) : DokkaTestGenerator<BaseTestMethods>(configuration, logger, testMethods, additionalPlugins) {
- override fun generate() = with(testMethods) {
- val dokkaGenerator = DokkaGenerator(configuration, logger)
+ override fun generate() {
+ with(testMethods) {
+ val dokkaGenerator = DokkaGenerator(configuration, logger)
- val context =
- dokkaGenerator.initializePlugins(configuration, logger, additionalPlugins)
- pluginsSetupStage(context)
+ val context =
+ dokkaGenerator.initializePlugins(configuration, logger, additionalPlugins)
+ pluginsSetupStage(context)
- val singleModuleGeneration = context.single(CoreExtensions.generation) as SingleModuleGeneration
+ val singleModuleGeneration = context.single(CoreExtensions.generation) as SingleModuleGeneration
- val modulesFromPlatforms = singleModuleGeneration.createDocumentationModels()
- documentablesCreationStage(modulesFromPlatforms)
+ val modulesFromPlatforms = singleModuleGeneration.createDocumentationModels()
+ documentablesCreationStage(modulesFromPlatforms)
- verificationStage { singleModuleGeneration.validityCheck(context) }
+ verificationStage { singleModuleGeneration.validityCheck(context) }
- val filteredModules = singleModuleGeneration.transformDocumentationModelBeforeMerge(modulesFromPlatforms)
- documentablesFirstTransformationStep(filteredModules)
+ val filteredModules = singleModuleGeneration.transformDocumentationModelBeforeMerge(modulesFromPlatforms)
+ documentablesFirstTransformationStep(filteredModules)
- val documentationModel = singleModuleGeneration.mergeDocumentationModels(filteredModules)
- documentablesMergingStage(documentationModel!!)
+ val documentationModel = singleModuleGeneration.mergeDocumentationModels(filteredModules)
+ documentablesMergingStage(documentationModel!!)
- val transformedDocumentation = singleModuleGeneration.transformDocumentationModelAfterMerge(documentationModel)
- documentablesTransformationStage(transformedDocumentation)
+ val transformedDocumentation = singleModuleGeneration.transformDocumentationModelAfterMerge(documentationModel)
+ documentablesTransformationStage(transformedDocumentation)
- val pages = singleModuleGeneration.createPages(transformedDocumentation)
- pagesGenerationStage(pages)
+ val pages = singleModuleGeneration.createPages(transformedDocumentation)
+ pagesGenerationStage(pages)
- val transformedPages = singleModuleGeneration.transformPages(pages)
- pagesTransformationStage(transformedPages)
+ val transformedPages = singleModuleGeneration.transformPages(pages)
+ pagesTransformationStage(transformedPages)
- singleModuleGeneration.render(transformedPages)
- renderingStage(transformedPages, context)
+ singleModuleGeneration.render(transformedPages)
+ renderingStage(transformedPages, context)
- singleModuleGeneration.runPostActions()
+ singleModuleGeneration.runPostActions()
- singleModuleGeneration.reportAfterRendering()
+ singleModuleGeneration.reportAfterRendering()
+ }
}
}
-data class BaseTestMethods(
+public data class BaseTestMethods(
override val pluginsSetupStage: (DokkaContext) -> Unit,
override val verificationStage: (() -> Unit) -> Unit,
override val documentablesCreationStage: (List<DModule>) -> Unit,
@@ -87,31 +89,35 @@ data class BaseTestMethods(
renderingStage,
)
-class BaseTestBuilder : TestBuilder<BaseTestMethods>() {
- var pluginsSetupStage: (DokkaContext) -> Unit = {}
- var verificationStage: (() -> Unit) -> Unit = {}
- var documentablesCreationStage: (List<DModule>) -> Unit = {}
- var preMergeDocumentablesTransformationStage: (List<DModule>) -> Unit = {}
- var documentablesMergingStage: (DModule) -> Unit = {}
- var documentablesTransformationStage: (DModule) -> Unit = {}
- var pagesGenerationStage: (RootPageNode) -> Unit = {}
- var pagesTransformationStage: (RootPageNode) -> Unit = {}
- var renderingStage: (RootPageNode, DokkaContext) -> Unit = { _, _ -> }
-
- override fun build() = BaseTestMethods(
- pluginsSetupStage,
- verificationStage,
- documentablesCreationStage,
- preMergeDocumentablesTransformationStage,
- documentablesMergingStage,
- documentablesTransformationStage,
- pagesGenerationStage,
- pagesTransformationStage,
- renderingStage
- )
+public class BaseTestBuilder : TestBuilder<BaseTestMethods>() {
+ public var pluginsSetupStage: (DokkaContext) -> Unit = {}
+ public var verificationStage: (() -> Unit) -> Unit = {}
+ public var documentablesCreationStage: (List<DModule>) -> Unit = {}
+ public var preMergeDocumentablesTransformationStage: (List<DModule>) -> Unit = {}
+ public var documentablesMergingStage: (DModule) -> Unit = {}
+ public var documentablesTransformationStage: (DModule) -> Unit = {}
+ public var pagesGenerationStage: (RootPageNode) -> Unit = {}
+ public var pagesTransformationStage: (RootPageNode) -> Unit = {}
+ public var renderingStage: (RootPageNode, DokkaContext) -> Unit = { _, _ -> }
+
+ override fun build(): BaseTestMethods {
+ return BaseTestMethods(
+ pluginsSetupStage,
+ verificationStage,
+ documentablesCreationStage,
+ preMergeDocumentablesTransformationStage,
+ documentablesMergingStage,
+ documentablesTransformationStage,
+ pagesGenerationStage,
+ pagesTransformationStage,
+ renderingStage
+ )
+ }
}
-abstract class BaseAbstractTest(logger: TestLogger = TestLogger(DokkaConsoleLogger(LoggingLevel.DEBUG))) : AbstractTest<BaseTestMethods, BaseTestBuilder, BaseDokkaTestGenerator>(
+public abstract class BaseAbstractTest(
+ logger: TestLogger = TestLogger(DokkaConsoleLogger(LoggingLevel.DEBUG))
+) : AbstractTest<BaseTestMethods, BaseTestBuilder, BaseDokkaTestGenerator>(
::BaseTestBuilder,
::BaseDokkaTestGenerator,
logger,
diff --git a/plugins/base/base-test-utils/src/main/kotlin/utils/TestOutputWriter.kt b/plugins/base/base-test-utils/src/main/kotlin/utils/TestOutputWriter.kt
index 578bbfe7..089a94ca 100644
--- a/plugins/base/base-test-utils/src/main/kotlin/utils/TestOutputWriter.kt
+++ b/plugins/base/base-test-utils/src/main/kotlin/utils/TestOutputWriter.kt
@@ -8,15 +8,16 @@ import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.renderers.OutputWriter
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.plugability.DokkaPluginApiPreview
+import org.jetbrains.dokka.plugability.Extension
import org.jetbrains.dokka.plugability.PluginApiPreviewAcknowledgement
import java.util.*
-class TestOutputWriterPlugin(failOnOverwrite: Boolean = true) : DokkaPlugin() {
- val writer = TestOutputWriter(failOnOverwrite)
+public class TestOutputWriterPlugin(failOnOverwrite: Boolean = true) : DokkaPlugin() {
+ public val writer: TestOutputWriter = TestOutputWriter(failOnOverwrite)
private val dokkaBase by lazy { plugin<DokkaBase>() }
- val testWriter by extending {
+ public val testWriter: Extension<OutputWriter, *, *> by extending {
(dokkaBase.outputWriter
with writer
override dokkaBase.fileWriter)
@@ -27,10 +28,12 @@ class TestOutputWriterPlugin(failOnOverwrite: Boolean = true) : DokkaPlugin() {
PluginApiPreviewAcknowledgement
}
-class TestOutputWriter(private val failOnOverwrite: Boolean = true) : OutputWriter {
- val contents: Map<String, String> get() = _contents
-
+public class TestOutputWriter(
+ private val failOnOverwrite: Boolean = true
+) : OutputWriter {
+ public val contents: Map<String, String> get() = _contents
private val _contents = Collections.synchronizedMap(mutableMapOf<String, String>())
+
override suspend fun write(path: String, text: String, ext: String) {
val fullPath = "$path$ext"
_contents.putIfAbsent(fullPath, text)?.also {
@@ -38,6 +41,7 @@ class TestOutputWriter(private val failOnOverwrite: Boolean = true) : OutputWrit
}
}
- override suspend fun writeResources(pathFrom: String, pathTo: String) =
+ override suspend fun writeResources(pathFrom: String, pathTo: String) {
write(pathTo, "*** content of $pathFrom ***", "")
+ }
}
diff --git a/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt b/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt
index 5b2ed612..207ebb8a 100644
--- a/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt
+++ b/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt
@@ -12,7 +12,7 @@ import kotlin.test.assertEquals
* Parses it using JSOUP, trims whitespace at the end of the line and asserts if they are equal
* parsing is required to unify the formatting
*/
-fun assertHtmlEqualsIgnoringWhitespace(expected: String, actual: String) {
+public fun assertHtmlEqualsIgnoringWhitespace(expected: String, actual: String) {
val ignoreFormattingSettings = Document.OutputSettings().indentAmount(0).outline(true)
assertEquals(
Jsoup.parse(expected).outputSettings(ignoreFormattingSettings).outerHtml().trimSpacesAtTheEndOfLine(),