Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- signature of `isIn` and `isNotIn` has been changed to ensure at least two items are supplied.
- added assertions `isIn(Iterable<T>)` and `isNotIn(Iterable<T>)`
- change `Assert<T>.fail` return type to `Nothing`.
- `isIn` and `isNotIn` failure messages now report the actual value against the expected collection.

## [0.28.1] 2024-04-17

Expand Down
12 changes: 6 additions & 6 deletions assertk/src/commonMain/kotlin/assertk/assertions/any.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ fun Assert<Any?>.isNotSameInstanceAs(expected: Any?) = given { actual ->
fun <T> Assert<T>.isIn(first: T, second: T, vararg rest: T) = given { actual ->
val values = listOf(first, second, *rest)
if (actual in values) return
expected(":${show(values)} to contain:${show(actual)}")
expected(":${show(actual)} to be in:${show(values)}")
}

@Deprecated("For binary compatibility", level = DeprecationLevel.HIDDEN)
fun <T> Assert<T>.isIn(vararg values: T) = given { actual ->
if (actual in values) return
expected(":${show(values)} to contain:${show(actual)}")
expected(":${show(actual)} to be in:${show(values)}")
}

@Deprecated("isIn with no values always fails", level = DeprecationLevel.ERROR)
Expand All @@ -124,7 +124,7 @@ fun <T> Assert<T>.isIn(first: T) {
*/
fun <T> Assert<T>.isIn(values: Iterable<T>) = given { actual ->
if (actual in values) return
expected(":${show(values)} to contain:${show(actual)}")
expected(":${show(actual)} to be in:${show(values)}")
}

/**
Expand All @@ -134,13 +134,13 @@ fun <T> Assert<T>.isIn(values: Iterable<T>) = given { actual ->
fun <T> Assert<T>.isNotIn(first: T, second: T, vararg rest: T) = given { actual ->
val values = listOf(first, second, *rest)
if (actual !in values) return
expected(":${show(values)} to not contain:${show(actual)}")
expected(":${show(actual)} to not be in:${show(values)}")
}

@Deprecated("For binary compatibility", level = DeprecationLevel.HIDDEN)
fun <T> Assert<T>.isNotIn(vararg values: T) = given { actual ->
if (actual !in values) return
expected(":${show(values)} to not contain:${show(actual)}")
expected(":${show(actual)} to not be in:${show(values)}")
}

@Deprecated("isNotIn with no values always succeeds", level = DeprecationLevel.ERROR)
Expand All @@ -163,7 +163,7 @@ fun <T> Assert<T>.isNotIn(first: T) {
*/
fun <T> Assert<T>.isNotIn(values: Iterable<T>) = given { actual ->
if (actual !in values) return
expected(":${show(values)} to not contain:${show(actual)}")
expected(":${show(actual)} to not be in:${show(values)}")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class AnyTest {
val error = assertFailsWith<AssertionError> {
assertThat(subject).isIn(isOut1, isOut2)
}
assertEquals("expected:<[not test1, not test2]> to contain:<test>", error.message)
assertEquals("expected:<test> to be in:<[not test1, not test2]>", error.message)
}

@Test
Expand All @@ -150,7 +150,7 @@ class AnyTest {
val error = assertFailsWith<AssertionError> {
assertThat(subject).isIn(list)
}
assertEquals("expected:<[not test1]> to contain:<test>", error.message)
assertEquals("expected:<test> to be in:<[not test1]>", error.message)
}

@Test
Expand All @@ -165,7 +165,7 @@ class AnyTest {
val error = assertFailsWith<AssertionError> {
assertThat(subject).isIn(list)
}
assertEquals("expected:<[not test1, not test2]> to contain:<test>", error.message)
assertEquals("expected:<test> to be in:<[not test1, not test2]>", error.message)
}

@Test
Expand All @@ -183,7 +183,7 @@ class AnyTest {
val error = assertFailsWith<AssertionError> {
assertThat(subject).isNotIn(isOut1, isIn, isOut2)
}
assertEquals("expected:<[not test1, test, not test2]> to not contain:<test>", error.message)
assertEquals("expected:<test> to not be in:<[not test1, test, not test2]>", error.message)
}

@Test
Expand All @@ -198,7 +198,7 @@ class AnyTest {
val error = assertFailsWith<AssertionError> {
assertThat(subject).isNotIn(list)
}
assertEquals("expected:<[test]> to not contain:<test>", error.message)
assertEquals("expected:<test> to not be in:<[test]>", error.message)
}

@Test
Expand All @@ -213,7 +213,7 @@ class AnyTest {
val error = assertFailsWith<AssertionError> {
assertThat(subject).isNotIn(list)
}
assertEquals("expected:<[not test1, test, not test2]> to not contain:<test>", error.message)
assertEquals("expected:<test> to not be in:<[not test1, test, not test2]>", error.message)
}

@Test
Expand Down