From 0a2a5896ece71f9d37930274c86b09a5fdf38644 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Wed, 5 Aug 2020 15:38:00 +0200 Subject: Add tests checking omitting of obvious types --- test-tools/src/main/kotlin/matchers/content/ContentMatchersDsl.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test-tools/src/main/kotlin/matchers') 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 @PublishedApi internal constru internal val children = mutableListOf() internal val assertions = mutableListOf 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 ContentMatcherBuilder.check(assertion: T.() -> Unit) { -- cgit