Provide removeAll and retainAll with predicate for MutableIterables and MutableList.
#KT-8760 Fixed
This commit is contained in:
@@ -8,12 +8,10 @@ import org.junit.Test as test
|
||||
|
||||
class MutableCollectionTest {
|
||||
|
||||
// TODO: Use apply scope function
|
||||
|
||||
@test fun addAll() {
|
||||
val data = listOf("foo", "bar")
|
||||
|
||||
fun assertAdd(f: MutableList<String>.() -> Unit) = assertEquals(data, arrayListOf<String>().let { it.f(); it })
|
||||
fun assertAdd(f: MutableList<String>.() -> Unit) = assertEquals(data, arrayListOf<String>().apply(f))
|
||||
|
||||
assertAdd { addAll(data) }
|
||||
assertAdd { addAll(data.toTypedArray()) }
|
||||
@@ -26,12 +24,17 @@ class MutableCollectionTest {
|
||||
val data = listOf("bar")
|
||||
val expected = listOf("foo")
|
||||
|
||||
fun assertRemove(f: MutableList<String>.() -> Unit) = assertEquals(expected, arrayListOf(*content).let { it.f(); it })
|
||||
fun assertRemove(f: MutableList<String>.() -> Unit) = assertEquals(expected, content.toArrayList().apply(f))
|
||||
|
||||
assertRemove { removeAll(data) }
|
||||
assertRemove { removeAll(data.toTypedArray()) }
|
||||
assertRemove { removeAll(data.toTypedArray().asIterable()) }
|
||||
assertRemove { removeAll(data.asSequence()) }
|
||||
assertRemove { removeAll { it in data } }
|
||||
assertRemove { (this as MutableIterable<String>).removeAll { it in data } }
|
||||
|
||||
val predicate = { cs: CharSequence -> cs.first() == 'b' }
|
||||
assertRemove { removeAll(predicate) }
|
||||
}
|
||||
|
||||
|
||||
@@ -40,12 +43,17 @@ class MutableCollectionTest {
|
||||
val data = listOf("bar")
|
||||
val expected = listOf("bar", "bar")
|
||||
|
||||
fun assertRetain(f: MutableList<String>.() -> Unit) = assertEquals(expected, arrayListOf(*content).let { it.f(); it })
|
||||
fun assertRetain(f: MutableList<String>.() -> Unit) = assertEquals(expected, content.toArrayList().apply(f))
|
||||
|
||||
assertRetain { retainAll(data) }
|
||||
assertRetain { retainAll(data.toTypedArray()) }
|
||||
assertRetain { retainAll(data.toTypedArray().asIterable()) }
|
||||
assertRetain { retainAll(data.asSequence()) }
|
||||
assertRetain { retainAll { it in data } }
|
||||
assertRetain { (this as MutableIterable<String>).retainAll { it in data } }
|
||||
|
||||
val predicate = { cs: CharSequence -> cs.first() == 'b' }
|
||||
assertRetain { retainAll(predicate) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user