Skip to content

Commit

Permalink
Fix asserting no other elements
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Aug 7, 2024
1 parent 8af7caa commit 272e5bd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,12 @@ fun <T: Iterable<E>, E> Builder<T>.containsWithOrderingConstraints(
val assertNoOtherElements = section.expectsNoOtherElements
if (assertNoOtherElements) {
assert("contains no other elements", expected = emptyList<E>()) {
if (elementsConsumed == it.count()) {
val declaredElements = section.elementsWithConstraints.map { it.element }
val undeclaredElements = it - declaredElements
if (undeclaredElements.isEmpty()) {
pass()
} else {
fail(actual = it.drop(elementsConsumed))
fail(actual = undeclaredElements)
}
}
} else {
Expand All @@ -704,6 +706,7 @@ fun <T: Iterable<E>, E> Builder<T>.containsWithOrderingConstraints(
}

val assertNoFurtherElements = builder.expectsNoFurtherElements ||
allSections.last().expectsNoOtherElements ||
// Check if the last section explicitly defines the end element
allSections.last().endDefinedBy is SectionAssertionSpec.EndDefinition.DeclaredElement<*>
if (assertNoFurtherElements) {
Expand Down

0 comments on commit 272e5bd

Please sign in to comment.