diff options
Diffstat (limited to 'test-tools/src/main')
-rw-r--r-- | test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt | 17 |
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 ) { |