diff options
author | Ignat Beresnev <ignat@beresnev.me> | 2022-01-27 12:56:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 12:56:27 +0300 |
commit | e0a10c24ea7e623137f2ab21522ed0f84bf59814 (patch) | |
tree | c863973a41efccb4ad34858c88b885e5370b2dbd /plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt | |
parent | 7c44db1ef0075e2b80a4723e0747bbf57c32e775 (diff) | |
download | dokka-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/renderers/JsoupUtils.kt')
-rw-r--r-- | plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt | 14 |
1 files changed, 11 insertions, 3 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() |