aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/base-test-utils/src/main/kotlin
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat@beresnev.me>2022-01-27 12:56:27 +0300
committerGitHub <noreply@github.com>2022-01-27 12:56:27 +0300
commite0a10c24ea7e623137f2ab21522ed0f84bf59814 (patch)
treec863973a41efccb4ad34858c88b885e5370b2dbd /plugins/base/base-test-utils/src/main/kotlin
parent7c44db1ef0075e2b80a4723e0747bbf57c32e775 (diff)
downloaddokka-e0a10c24ea7e623137f2ab21522ed0f84bf59814.tar.gz
dokka-e0a10c24ea7e623137f2ab21522ed0f84bf59814.tar.bz2
dokka-e0a10c24ea7e623137f2ab21522ed0f84bf59814.zip
KT-50292 - Implement vertical alignment of parameters (#2309)
* Implement vertical alignment (wrapping) of parameters for kt * Add tests for params wrapping and extend matchers to check for classes * Add distinguishable parameters block to kotlinAsJava, extract common logic * Create a separate Kind for symbol function parameters
Diffstat (limited to 'plugins/base/base-test-utils/src/main/kotlin')
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt14
-rw-r--r--plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt6
2 files changed, 16 insertions, 4 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 a4dadca4..22581d3a 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
@@ -21,7 +21,7 @@ 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)
+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)
@@ -34,16 +34,24 @@ class Dt(vararg matchers: Any) : Tag("dt", *matchers)
class Dd(vararg matchers: Any) : Tag("dd", *matchers)
object Wbr : Tag("wbr")
object Br : Tag("br")
+
+fun Tag.withClasses(vararg classes: String) = Tag(name, *matchers, expectedClasses = classes.toList())
+
private fun Any.accepts(n: Node, ignoreSpan:Boolean = true) {
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, ignoreSpanWithTokenStyle = ignoreSpan)
+ check(n is Element) { "Expected node to be Element: $n" }
+ assert(n.tagName() == name) { "Tag \"$name\" expected but found: \"$n\"" }
+ expectedClasses.forEach {
+ assert(n.hasClass(it)) { "Expected to find class \"$it\" for tag \"$name\", found: ${n.classNames()}" }
+ }
+ if (matchers.isNotEmpty()) n.match(*matchers, ignoreSpanWithTokenStyle = ignoreSpan)
}
else -> throw IllegalArgumentException("$this is not proper matcher")
}
}
+
private fun List<Node>.uniteConsecutiveTextNodes(): MutableList<Node> {
val resList = mutableListOf<Node>()
var acc = StringBuilder()
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 e77b8757..ddaefd8c 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
@@ -2,6 +2,7 @@ package signatures
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
+import utils.Tag
import utils.TestOutputWriter
fun TestOutputWriter.renderedContent(path: String = "root/example.html") =
@@ -9,4 +10,7 @@ fun TestOutputWriter.renderedContent(path: String = "root/example.html") =
.single()
fun Element.signature() = select("div.symbol.monospace")
-fun Element.firstSignature() = signature().first() \ No newline at end of file
+fun Element.firstSignature() = signature().first()
+
+class Parameters(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameters"))
+class Parameter(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameter")) \ No newline at end of file