diff options
Diffstat (limited to 'core/content-matcher-test-utils/src')
-rw-r--r-- | core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt | 14 | ||||
-rw-r--r-- | core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt | 7 |
2 files changed, 10 insertions, 11 deletions
diff --git a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt index 67c0e692..264be933 100644 --- a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt +++ b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt @@ -3,7 +3,6 @@ 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.* @@ -53,12 +52,6 @@ fun <T : ContentComposite> ContentMatcherBuilder<T>.hasExactText(expected: Strin } } -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 ) { @@ -96,6 +89,13 @@ fun ContentMatcherBuilder<*>.table(block: ContentMatcherBuilder<ContentTable>.() fun ContentMatcherBuilder<*>.platformHinted(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) = composite<PlatformHintedContent> { group(block) } +fun ContentMatcherBuilder<*>.list(block: ContentMatcherBuilder<ContentList>.() -> Unit) = composite(block) + +fun ContentMatcherBuilder<*>.caption(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) = composite<ContentGroup> { + block() + check { assertThat(this::style).contains(ContentStyle.Caption) } +} + fun ContentMatcherBuilder<*>.br() = node<ContentBreakLine>() fun ContentMatcherBuilder<*>.somewhere(block: ContentMatcherBuilder<*>.() -> Unit) { diff --git a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt index f42e28f3..6a0e1c97 100644 --- a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt +++ b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt @@ -69,10 +69,9 @@ private class TextMatcherState( ) : MatchWalkerState() { override fun next(node: ContentNode): MatchWalkerState { node as? ContentText ?: throw MatcherError("Expected text: \"$text\" but got\n${node.debugRepresentation()}", anchor) - val trimmed = node.text.trim() return when { - text == trimmed -> rest.pop() - text.startsWith(trimmed) -> TextMatcherState(text.removePrefix(node.text).trim(), rest, anchor) + text == node.text -> rest.pop() + text.startsWith(node.text) -> TextMatcherState(text.removePrefix(node.text), rest, anchor) else -> throw MatcherError("Expected text: \"$text\", but got: \"${node.text}\"", anchor) } } @@ -111,7 +110,7 @@ private class SkippingMatcherState( private class FurtherSiblings(val list: List<MatcherElement>, val parent: CompositeMatcher<*>) { fun pop(): MatchWalkerState = when (val head = list.firstOrNull()) { - is TextMatcher -> TextMatcherState(head.text.trim(), drop(), head) + is TextMatcher -> TextMatcherState(head.text, drop(), head) is NodeMatcher<*> -> NodeMatcherState(head, drop()) is Anything -> SkippingMatcherState(drop().pop()) null -> EmptyMatcherState(parent) |