From e0a10c24ea7e623137f2ab21522ed0f84bf59814 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 27 Jan 2022 12:56:27 +0300 Subject: 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 --- .../src/main/kotlin/renderers/JsoupUtils.kt | 14 +++++++++++--- .../src/main/kotlin/renderers/SignatureUtils.kt | 6 +++++- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'plugins/base/base-test-utils/src/main') 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 = 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.uniteConsecutiveTextNodes(): MutableList { val resList = mutableListOf() 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 -- cgit