From 8af7e4cade0a872ed638acf42d8c474415af290f Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Wed, 5 Aug 2020 10:43:35 +0200 Subject: Add test tools for extracted string assertions --- .../main/kotlin/matchers/content/ContentMatchersDsl.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt') 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 ContentMatcherBuilder.check(assertion: T.() -> Uni assertions += assertion } +private val ContentComposite.extractedText + get() = withDescendants().filterIsInstance().joinToString(separator = "") { it.text } + +fun ContentMatcherBuilder.hasExactText(expected: String) { + assertions += { + assertThat(this::extractedText).isEqualTo(expected) + } +} + +fun ContentMatcherBuilder.textMatches(pattern: Regex) { + assertions += { + assertThat(this::extractedText).matches(pattern) + } +} + inline fun ContentMatcherBuilder<*>.composite( block: ContentMatcherBuilder.() -> Unit ) { -- cgit