Skip to content

Commit e26380e

Browse files
authored
Fix IndexOutOfBoundsException in containsExactly differ (#187)
Fixes #185
1 parent e3fa0a8 commit e26380e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

assertk-common/src/main/kotlin/assertk/assertions/support/ListDiffer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal object ListDiffer {
8484
k - 1
8585
}
8686

87-
val prevX = v[prevK]
87+
val prevX = v.ringIndex(prevK)
8888
val prevY = prevX - prevK
8989

9090
while (x > prevX && y > prevY) {

assertk-common/src/test/kotlin/test/assertk/assertions/ListTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ class ListTest {
2626
)
2727
}
2828

29+
// https://github.com/willowtreeapps/assertk/issues/185
30+
@Test fun containsExactly_elements_in_different_order_fails2() {
31+
val error = assertFails {
32+
assertThat(listOf("1", "2", "3")).containsExactly("2", "3", "1")
33+
}
34+
assertEquals(
35+
"""expected to contain exactly:
36+
| at index:0 unexpected:<"1">
37+
| at index:2 expected:<"1">
38+
""".trimMargin(), error.message
39+
)
40+
}
41+
2942
@Test fun containsExactly_same_indexes_are_together() {
3043
val error = assertFails {
3144
assertThat(listOf(1, 1)).containsExactly(2, 2)

0 commit comments

Comments
 (0)