diff options
Diffstat (limited to 'test-tools/src/main/kotlin/matchers/content')
-rw-r--r-- | test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt b/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt index e1026a97..67c0e692 100644 --- a/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt +++ b/test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt @@ -30,12 +30,14 @@ class ContentMatcherBuilder<T : ContentComposite> @PublishedApi internal constru internal val children = mutableListOf<MatcherElement>() internal val assertions = mutableListOf<T.() -> Unit>() - fun build() = CompositeMatcher(kclass, children) { assertions.forEach { it() } } + fun build() = CompositeMatcher(kclass, childrenOrSkip()) { assertions.forEach { it() } } // part of DSL that cannot be defined as an extension operator fun String.unaryPlus() { children += TextMatcher(this) } + + private fun childrenOrSkip() = if (children.isEmpty() && assertions.isNotEmpty()) listOf(Anything) else children } fun <T : ContentComposite> ContentMatcherBuilder<T>.check(assertion: T.() -> Unit) { |