aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt')
-rw-r--r--plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt30
1 files changed, 30 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt
index a6977258..686baf04 100644
--- a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt
+++ b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt
@@ -14,6 +14,10 @@ import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.testApi.context.MockContext
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
+import org.jsoup.Jsoup
+import org.jsoup.nodes.Element
+import org.jsoup.nodes.Node
+import org.jsoup.nodes.TextNode
import utils.TestOutputWriter
abstract class RenderingOnlyTestBase {
@@ -23,6 +27,10 @@ abstract class RenderingOnlyTestBase {
DokkaBase().locationProviderFactory to ::DefaultLocationProviderFactory
)
+ protected val renderedContent: Element by lazy {
+ files.contents.getValue("test-page.html").let { Jsoup.parse(it) }.select("#content").single()
+ }
+
protected fun linesAfterContentTag() =
files.contents.getValue("test-page.html").lines()
.dropWhile { !it.contains("""<div id="content">""") }
@@ -60,6 +68,28 @@ class TestPage(callback: PageContentBuilder.DocumentableContentBuilder.() -> Uni
override fun modified(name: String, children: List<PageNode>) = this
}
+fun Element.match(vararg matchers: Any): Unit =
+ childNodes()
+ .filter { it !is TextNode || it.text().isNotBlank() }
+ .let { it.drop(it.size - matchers.size) }
+ .zip(matchers)
+ .forEach { (n, m) -> m.accepts(n) }
+
+open class Tag(val name: String, vararg val matchers: Any)
+class Div(vararg matchers: Any): Tag("div", *matchers)
+class P(vararg matchers: Any): Tag("p", *matchers)
+
+private fun Any.accepts(n: Node) {
+ when (this) {
+ is String -> assert(n is TextNode && n.text().trim() == this.trim()) { "\"$this\" expected but found: $n" }
+ is Tag -> {
+ assert(n is Element && n.tagName() == name) { "Tag $name expected but found: $n" }
+ if (n is Element && matchers.isNotEmpty()) n.match(*matchers)
+ }
+ else -> throw IllegalArgumentException("$this is not proper matcher")
+ }
+}
+
internal object EmptyCommentConverter : CommentsToContentConverter {
override fun buildContent(