Improve argument validation in copyOfRange
Make copyOfRange implementation non-inline in order not to expose copyOfRangeToIndexCheck implementation detail. It will be possible to make the function non-inline itself later without that JvmName trick, when apiVersion 1.2 support is discontinued. #KT-19489
This commit is contained in:
@@ -26,6 +26,9 @@ class ListSpecificTest {
|
||||
@Test
|
||||
fun slice() {
|
||||
val list = listOf('A', 'B', 'C', 'D')
|
||||
|
||||
assertEquals(emptyList(), list.slice(IntRange.EMPTY))
|
||||
|
||||
// ABCD
|
||||
// 0123
|
||||
assertEquals(listOf('B', 'C', 'D'), list.slice(1..3))
|
||||
@@ -33,6 +36,13 @@ class ListSpecificTest {
|
||||
|
||||
val iter = listOf(2, 0, 3)
|
||||
assertEquals(listOf('C', 'A', 'D'), list.slice(iter))
|
||||
|
||||
for (range in listOf(-1 until 0, 0 until 2, 2..2)) {
|
||||
val bounds = "range: $range"
|
||||
val exClass = IndexOutOfBoundsException::class
|
||||
assertFailsWith(exClass, bounds) { listOf("x").slice(range) }
|
||||
assertFailsWith(exClass, bounds) { listOf("x").slice(range.asIterable()) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user