aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/base-test-utils
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/base-test-utils')
-rw-r--r--plugins/base/base-test-utils/api/base-test-utils.api13
-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
3 files changed, 28 insertions, 5 deletions
diff --git a/plugins/base/base-test-utils/api/base-test-utils.api b/plugins/base/base-test-utils/api/base-test-utils.api
index d3db4866..b6ec84a1 100644
--- a/plugins/base/base-test-utils/api/base-test-utils.api
+++ b/plugins/base/base-test-utils/api/base-test-utils.api
@@ -85,6 +85,14 @@ public final class renderers/TestPageKt {
public static final fun testPage (Lkotlin/jvm/functions/Function1;)Lrenderers/RawTestPage;
}
+public final class signatures/Parameter : utils/Tag {
+ public fun <init> ([Ljava/lang/Object;)V
+}
+
+public final class signatures/Parameters : utils/Tag {
+ public fun <init> ([Ljava/lang/Object;)V
+}
+
public final class signatures/SignatureUtilsKt {
public static final fun firstSignature (Lorg/jsoup/nodes/Element;)Lorg/jsoup/nodes/Element;
public static final fun renderedContent (Lutils/TestOutputWriter;Ljava/lang/String;)Lorg/jsoup/nodes/Element;
@@ -131,6 +139,7 @@ public final class utils/I : utils/Tag {
public final class utils/JsoupUtilsKt {
public static final fun match (Lorg/jsoup/nodes/Element;[Ljava/lang/Object;Z)V
public static synthetic fun match$default (Lorg/jsoup/nodes/Element;[Ljava/lang/Object;ZILjava/lang/Object;)V
+ public static final fun withClasses (Lutils/Tag;[Ljava/lang/String;)Lutils/Tag;
}
public final class utils/P : utils/Tag {
@@ -146,7 +155,9 @@ public final class utils/Span : utils/Tag {
}
public class utils/Tag {
- public fun <init> (Ljava/lang/String;[Ljava/lang/Object;)V
+ public fun <init> (Ljava/lang/String;[Ljava/lang/Object;Ljava/util/List;)V
+ public synthetic fun <init> (Ljava/lang/String;[Ljava/lang/Object;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
+ public final fun getExpectedClasses ()Ljava/util/List;
public final fun getMatchers ()[Ljava/lang/Object;
public final fun getName ()Ljava/lang/String;
}
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