aboutsummaryrefslogtreecommitdiff
path: root/test-tools/src
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-08-05 10:43:35 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-14 14:16:41 +0200
commit8af7e4cade0a872ed638acf42d8c474415af290f (patch)
tree5bf8c8f480649b1525efb9f3a1f400e48d12ccc9 /test-tools/src
parent6bcff75d3718b9ef0a4feb803ceff97cde3644f1 (diff)
downloaddokka-8af7e4cade0a872ed638acf42d8c474415af290f.tar.gz
dokka-8af7e4cade0a872ed638acf42d8c474415af290f.tar.bz2
dokka-8af7e4cade0a872ed638acf42d8c474415af290f.zip
Add test tools for extracted string assertions
Diffstat (limited to 'test-tools/src')
-rw-r--r--test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt17
1 files changed, 17 insertions, 0 deletions
diff --git a/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt b/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt
index 01abab28..e1026a97 100644
--- a/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt
+++ b/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt
@@ -3,6 +3,8 @@ package matchers.content
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isEqualTo
+import assertk.assertions.matches
+import org.jetbrains.dokka.model.withDescendants
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.test.tools.matchers.content.*
import kotlin.reflect.KClass
@@ -40,6 +42,21 @@ fun <T : ContentComposite> ContentMatcherBuilder<T>.check(assertion: T.() -> Uni
assertions += assertion
}
+private val ContentComposite.extractedText
+ get() = withDescendants().filterIsInstance<ContentText>().joinToString(separator = "") { it.text }
+
+fun <T : ContentComposite> ContentMatcherBuilder<T>.hasExactText(expected: String) {
+ assertions += {
+ assertThat(this::extractedText).isEqualTo(expected)
+ }
+}
+
+fun <T : ContentComposite> ContentMatcherBuilder<T>.textMatches(pattern: Regex) {
+ assertions += {
+ assertThat(this::extractedText).matches(pattern)
+ }
+}
+
inline fun <reified S : ContentComposite> ContentMatcherBuilder<*>.composite(
block: ContentMatcherBuilder<S>.() -> Unit
) {