-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have upper bound print violations (#3847)
`shouldHaveUpperBound` should output elements that violate the assumption, such as: ``` shouldThrowAny { listOf(1, 2, 3) shouldHaveUpperBound 2 }.shouldHaveMessage("Collection should have upper bound 2, but the following elements are above it: [3]") ``` likewise, add same output for `shouldHaveLowerBound`: ``` shouldThrowAny { listOf(1, 2, 3) shouldHaveLowerBound 2 }.shouldHaveMessage("Collection should have lower bound 2, but the following elements are below it: [1]") ```
- Loading branch information
1 parent
dbcc745
commit 77db319
Showing
2 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...assertions-core/src/jvmTest/kotlin/com/sksamuel/kotest/matchers/collections/BoundsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.sksamuel.kotest.matchers.collections | ||
|
||
import io.kotest.assertions.throwables.shouldThrowAny | ||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.collections.shouldHaveLowerBound | ||
import io.kotest.matchers.collections.shouldHaveUpperBound | ||
import io.kotest.matchers.throwable.shouldHaveMessage | ||
|
||
class BoundsTest: WordSpec() { | ||
init { | ||
"haveUpperBound" should { | ||
"pass" { | ||
listOf(1, 2, 3) shouldHaveUpperBound 3 | ||
} | ||
|
||
"fail" { | ||
shouldThrowAny { | ||
listOf(1, 2, 3) shouldHaveUpperBound 2 | ||
}.shouldHaveMessage("Collection should have upper bound 2, but the following elements are above it: [3]") | ||
} | ||
} | ||
|
||
"haveLowerBound" should { | ||
"pass" { | ||
listOf(1, 2, 3) shouldHaveLowerBound 1 | ||
} | ||
"fail" { | ||
shouldThrowAny { | ||
listOf(1, 2, 3) shouldHaveLowerBound 2 | ||
}.shouldHaveMessage("Collection should have lower bound 2, but the following elements are below it: [1]") | ||
} | ||
} | ||
} | ||
} |