Move JVM8 box test to common
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FULL_JDK
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.util.*
|
||||
import java.util.function.Predicate
|
||||
|
||||
class MyList : AbstractCollection<String>(), MutableCollection<String> {
|
||||
override fun iterator(): MutableIterator<String> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun removeIf(predicate: Predicate<in String>) =
|
||||
predicate.test("abc")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ml = mutableListOf("xyz", "abc")
|
||||
|
||||
if (!ml.removeIf { x -> x == "abc" }) return "fail 1"
|
||||
if (ml.removeIf { x -> x == "abc" }) return "fail 2"
|
||||
|
||||
if (ml != listOf("xyz")) return "fail 3"
|
||||
|
||||
val myList = MyList()
|
||||
|
||||
if (!myList.removeIf { x -> x == "abc" }) return "fail 4"
|
||||
if (myList.removeIf { x -> x == "xyz" }) return "fail 5"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FULL_JDK
|
||||
// WITH_RUNTIME
|
||||
// LANGUAGE_VERSION: 1.1
|
||||
import java.util.stream.*
|
||||
|
||||
class B<F> : List<F> {
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun contains(element: F): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun containsAll(elements: Collection<F>): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun get(index: Int): F {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun indexOf(element: F): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<F> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun lastIndexOf(element: F): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(): ListIterator<F> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun listIterator(index: Int): ListIterator<F> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<F> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun stream() = Stream.of("abc", "ab") as Stream<F>
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a: List<String> = listOf("abc", "a", "ab")
|
||||
val b = a.stream().filter { it.length > 1 }.collect(Collectors.toList())
|
||||
if (b != listOf("abc", "ab")) return "fail 1"
|
||||
|
||||
val c = B<String>().stream().collect(Collectors.toList())
|
||||
if (c != listOf("abc", "ab")) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// LANGUAGE_VERSION: 1.0
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
class A(val x: List<String>) : List<String> by x
|
||||
|
||||
fun box(): String {
|
||||
return A(listOf("OK"))[0]
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// KT-5190 Java 8 Stream.collect couldn't be called
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
import java.util.stream.Collectors
|
||||
import java.util.stream.Stream
|
||||
|
||||
fun box(): String {
|
||||
val mutableListOf = mutableListOf("OK", "B", "C")
|
||||
|
||||
return test((mutableListOf as java.util.Collection<String>).stream()) as String
|
||||
}
|
||||
|
||||
fun test(a: Stream<String>) = a.collect(Collectors.toList()).first()
|
||||
Reference in New Issue
Block a user