Files
kotlin-fork/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/addAll.kt
T
Ilya Matveev 85827b4880 tests: Copy stdlib tests from Kotlin/JVM
This patch copies Kotlin/JVM stdlib tests (libraries/stdlib/test)
excepting ones with explicit java dependencies. It also transforms
the tests to use them as box-tests.
2017-04-07 17:21:11 +07:00

30 lines
1.1 KiB
Kotlin

import kotlin.test.*
fun <T, C : MutableCollection<T>> testOperation(before: List<T>, after: List<T>, expectedModified: Boolean, toMutableCollection: (List<T>) -> C)
= fun(operation: (C.() -> Boolean)) {
val list = toMutableCollection(before)
assertEquals(expectedModified, list.operation())
assertEquals(toMutableCollection(after), list)
}
fun <T> testOperation(before: List<T>, after: List<T>, expectedModified: Boolean)
= testOperation(before, after, expectedModified, { it.toMutableList() })
fun box() {
val data = listOf("foo", "bar")
testOperation(emptyList(), data, true).let { assertAdd ->
assertAdd { addAll(data) }
assertAdd { addAll(data.toTypedArray()) }
assertAdd { addAll(data.toTypedArray().asIterable()) }
assertAdd { addAll(data.asSequence()) }
}
testOperation(data, data, false, { it.toCollection(LinkedHashSet()) }).let { assertAdd ->
assertAdd { addAll(data) }
assertAdd { addAll(data.toTypedArray()) }
assertAdd { addAll(data.toTypedArray().asIterable()) }
assertAdd { addAll(data.asSequence()) }
}
}