aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/renderers
diff options
context:
space:
mode:
authorKamil Doległo <9080183+kamildoleglo@users.noreply.github.com>2021-01-05 12:19:01 +0100
committerGitHub <noreply@github.com>2021-01-05 12:19:01 +0100
commitef98e4b6505c3fdd192b1d5057c718079d27b972 (patch)
treeca93d1482422f4b882715721234e4ab4352e474a /plugins/base/src/test/kotlin/renderers
parentd3f0e03284999e6f7fac99a345ed91cb63503706 (diff)
downloaddokka-ef98e4b6505c3fdd192b1d5057c718079d27b972.tar.gz
dokka-ef98e4b6505c3fdd192b1d5057c718079d27b972.tar.bz2
dokka-ef98e4b6505c3fdd192b1d5057c718079d27b972.zip
Fix a bug with inserting template commands instead of link text (#1685)
Some test methods were dropped intentionally, as using them can lead to subtle bugs. The same methods are available in the base-test-utils module
Diffstat (limited to 'plugins/base/src/test/kotlin/renderers')
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/BasicTest.kt20
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt23
2 files changed, 20 insertions, 23 deletions
diff --git a/plugins/base/src/test/kotlin/renderers/html/BasicTest.kt b/plugins/base/src/test/kotlin/renderers/html/BasicTest.kt
new file mode 100644
index 00000000..fbcdf70e
--- /dev/null
+++ b/plugins/base/src/test/kotlin/renderers/html/BasicTest.kt
@@ -0,0 +1,20 @@
+package renderers.html
+
+import org.jetbrains.dokka.base.renderers.html.HtmlRenderer
+import org.jetbrains.dokka.links.DRI
+import org.junit.jupiter.api.Test
+import renderers.testPage
+import utils.Span
+import utils.match
+
+class BasicTest : HtmlRenderingOnlyTestBase() {
+ @Test
+ fun `unresolved DRI link should render as text`() {
+ val page = testPage {
+ link("linkText", DRI("nonexistentPackage", "nonexistentClass"))
+ }
+
+ HtmlRenderer(context).render(page)
+ renderedContent.match(Span("linkText"))
+ }
+}
diff --git a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
index 0d3763ee..71d141e2 100644
--- a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
+++ b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
@@ -62,26 +62,3 @@ abstract class HtmlRenderingOnlyTestBase : RenderingOnlyTestBase<Element>() {
.dropWhile { !it.contains("""<div id="content">""") }
.joinToString(separator = "") { it.trim() }
}
-
-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")
- }
-}