Fix array iterators to adhere to Iterator contract

#KT-17453 Fixed

Change expected exceptions in tests.
This commit is contained in:
Ilya Gorbunov
2017-04-17 23:49:43 +03:00
parent 2380e0bacc
commit 4a5d8534c1
6 changed files with 46 additions and 28 deletions
+9 -9
View File
@@ -21,7 +21,7 @@ internal fun arrayIterator(array: dynamic, type: String?) = when (type) {
object : Iterator<dynamic> {
var index = 0
override fun hasNext() = index < arr.size
override fun next() = if (index < arr.size) arr[index++] else throw IndexOutOfBoundsException("$index")
override fun next() = if (index < arr.size) arr[index++] else throw NoSuchElementException("$index")
}
}
"BooleanArray" -> booleanArrayIterator(array)
@@ -39,56 +39,56 @@ internal fun arrayIterator(array: dynamic, type: String?) = when (type) {
internal fun booleanArrayIterator(array: BooleanArray) = object : BooleanIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextBoolean() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextBoolean() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("byteArrayIterator")
internal fun byteArrayIterator(array: ByteArray) = object : ByteIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextByte() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextByte() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("shortArrayIterator")
internal fun shortArrayIterator(array: ShortArray) = object : ShortIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextShort() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextShort() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("charArrayIterator")
internal fun charArrayIterator(array: CharArray) = object : CharIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextChar() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextChar() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("intArrayIterator")
internal fun intArrayIterator(array: IntArray) = object : IntIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextInt() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextInt() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("floatArrayIterator")
internal fun floatArrayIterator(array: FloatArray) = object : FloatIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextFloat() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextFloat() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("doubleArrayIterator")
internal fun doubleArrayIterator(array: DoubleArray) = object : DoubleIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextDouble() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextDouble() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("longArrayIterator")
internal fun longArrayIterator(array: LongArray) = object : LongIterator() {
var index = 0
override fun hasNext() = index < array.size
override fun nextLong() = if (index < array.size) array[index++] else throw IndexOutOfBoundsException("$index")
override fun nextLong() = if (index < array.size) array[index++] else throw NoSuchElementException("$index")
}
@JsName("PropertyMetadata")