Throw correct exceptions expected by stdlib tests

This commit is contained in:
Pavel Punegov
2018-08-07 12:38:21 +03:00
committed by Pavel Punegov
parent bb44fdda88
commit 57d21f9a38
3 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ public actual open class AssertionError : Error {
actual constructor()
constructor(message: String?) : super(message)
constructor(cause: Throwable?) : super(cause)
actual constructor(message: Any?) : super(message.toString())
@@ -330,6 +330,7 @@ actual class ArrayList<E> private constructor(
}
override fun remove() {
check(lastIndex != -1) { "Call next() or previous() before removing element from the iterator." }
list.removeAt(lastIndex)
index = lastIndex
lastIndex = -1
@@ -552,7 +552,7 @@ actual class HashMap<K, V> private constructor(
internal class KeysItr<K, V>(map: HashMap<K, V>) : Itr<K, V>(map), MutableIterator<K> {
override fun next(): K {
if (index >= map.length) throw IndexOutOfBoundsException()
if (index >= map.length) throw NoSuchElementException()
lastIndex = index++
val result = map.keysArray[lastIndex]
initNext()
@@ -563,7 +563,7 @@ actual class HashMap<K, V> private constructor(
internal class ValuesItr<K, V>(map: HashMap<K, V>) : Itr<K, V>(map), MutableIterator<V> {
override fun next(): V {
if (index >= map.length) throw IndexOutOfBoundsException()
if (index >= map.length) throw NoSuchElementException()
lastIndex = index++
val result = map.valuesArray!![lastIndex]
initNext()
@@ -574,7 +574,7 @@ actual class HashMap<K, V> private constructor(
internal class EntriesItr<K, V>(map: HashMap<K, V>) : Itr<K, V>(map),
MutableIterator<MutableMap.MutableEntry<K, V>> {
override fun next(): EntryRef<K, V> {
if (index >= map.length) throw IndexOutOfBoundsException()
if (index >= map.length) throw NoSuchElementException()
lastIndex = index++
val result = EntryRef(map, lastIndex)
initNext()
@@ -582,7 +582,7 @@ actual class HashMap<K, V> private constructor(
}
internal fun nextHashCode(): Int {
if (index >= map.length) throw IndexOutOfBoundsException()
if (index >= map.length) throw NoSuchElementException()
lastIndex = index++
val result = map.keysArray[lastIndex].hashCode() xor map.valuesArray!![lastIndex].hashCode()
initNext()
@@ -590,7 +590,7 @@ actual class HashMap<K, V> private constructor(
}
fun nextAppendString(sb: StringBuilder) {
if (index >= map.length) throw IndexOutOfBoundsException()
if (index >= map.length) throw NoSuchElementException()
lastIndex = index++
val key = map.keysArray[lastIndex]
if (key == map) sb.append("(this Map)") else sb.append(key)