From f80d5938ccafcf5bd41d73f98bebe2d9699faa95 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Thu, 2 Jul 2020 11:33:52 +0200 Subject: Add GFM renderer tests --- .../test/kotlin/renderers/RenderingOnlyTestBase.kt | 77 ++------------------- .../src/test/kotlin/renderers/defaultSourceSet.kt | 31 +++++++++ .../test/kotlin/renderers/html/DivergentTest.kt | 2 +- .../kotlin/renderers/html/GroupWrappingTest.kt | 2 +- .../renderers/html/HtmlRenderingOnlyTestBase.kt | 78 ++++++++++++++++++++++ .../renderers/html/SourceSetDependentHintTest.kt | 6 +- .../test/kotlin/renderers/html/defaultSourceSet.kt | 31 --------- 7 files changed, 119 insertions(+), 108 deletions(-) create mode 100644 plugins/base/src/test/kotlin/renderers/defaultSourceSet.kt create mode 100644 plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt delete mode 100644 plugins/base/src/test/kotlin/renderers/html/defaultSourceSet.kt (limited to 'plugins/base/src/test/kotlin/renderers') diff --git a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt index 21a70802..8e58bbcd 100644 --- a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt +++ b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt @@ -1,50 +1,19 @@ package renderers -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.base.DokkaBase -import org.jetbrains.dokka.base.renderers.RootCreator -import org.jetbrains.dokka.base.resolvers.external.DokkaExternalLocationProviderFactory -import org.jetbrains.dokka.base.resolvers.external.JavadocExternalLocationProviderFactory -import org.jetbrains.dokka.base.resolvers.local.DefaultLocationProviderFactory import org.jetbrains.dokka.base.signatures.KotlinSignatureProvider -import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Documentable -import org.jetbrains.dokka.model.doc.DocTag -import org.jetbrains.dokka.model.properties.PropertyContainer -import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.pages.ContentNode +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.PageNode +import org.jetbrains.dokka.pages.RootPageNode 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 +import renderers.html.EmptyCommentConverter abstract class RenderingOnlyTestBase { - val files = TestOutputWriter() - val context = MockContext( - DokkaBase().outputWriter to { _ -> files }, - DokkaBase().locationProviderFactory to ::DefaultLocationProviderFactory, - DokkaBase().htmlPreprocessors to { _ -> RootCreator }, - DokkaBase().externalLocationProviderFactory to { ::JavadocExternalLocationProviderFactory }, - DokkaBase().externalLocationProviderFactory to { ::DokkaExternalLocationProviderFactory }, - testConfiguration = DokkaConfigurationImpl( - "", "", null, false, emptyList(), emptyList(), emptyMap(), emptyList(), false - ) - ) - - 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("""
""") } - .joinToString(separator = "") { it.trim() } - + abstract val context: MockContext } class TestPage(callback: PageContentBuilder.DocumentableContentBuilder.() -> Unit) : RootPageNode(), ContentPage { @@ -76,37 +45,3 @@ class TestPage(callback: PageContentBuilder.DocumentableContentBuilder.() -> Uni override fun modified(name: String, children: List) = 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) -class Span(vararg matchers: Any) : Tag("span", *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( - docTag: DocTag, - dci: DCI, - sourceSets: Set, - styles: Set