kotest
kotest copied to clipboard
Add shouldContainOnly
It would be useful to have an assertion that is exactly equivalent to AssertJ's assertThat(list).containsOnly(these,elements,in,any,number,and,any,order,and,nothing,else)
.
For example:
listOf(1, 1, 1).shouldContainOnly(1) // expected to pass
listOf(1, 1, 2, 2).shouldContainOnly(1, 2) // expected to pass
listOf(1, 1, 2).shouldContainOnly(1) // expected to fail because it shouldn't contain 2
listOf(1, 1, 2).shouldContainOnly(1, 2, 3) // expected to fail because it doesn't contain 3
I think this is a tough one.
listOf(1, 1, 2, 2) shouldContainOnly listOf(1, 2)
is pretty ambigous to me what should actually be the result here just from the name
It's not ambiguous, because you wouldn't call it like that. shouldContainOnly
should take a vararg, not a list. Just as shouldContainExactly
does.
If you want to use infix functions, it's list should containOnly(1, 2)
.
@LeoColman I would like to contribute to this.
Go for it! I'll assign it to you