tests: Update external tests (1.1.2-dev-393)

This commit is contained in:
Ilya Matveev
2017-03-13 12:38:08 +03:00
committed by ilmat192
parent ac56fccb15
commit bc074e6d39
3178 changed files with 22396 additions and 696 deletions
@@ -0,0 +1,14 @@
// WITH_RUNTIME
fun box(): String {
val list = ArrayList<Pair<String,String>>()
list.add(Pair("Sample", "http://cyber.law.harvard.edu/rss/examples/rss2sample.xml"))
list.add(Pair("Scripting", "http://static.scripting.com/rss.xml"))
val keys = list.map { it.first }.toTypedArray<String>()
val keysToString = keys.contentToString()
if (keysToString != "[Sample, Scripting]") return keysToString
return "OK"
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun getCopyToArray(): Array<Int> = listOf(2, 3, 9).toTypedArray()
fun box(): String {
val str = getCopyToArray().contentToString()
if (str != "[2, 3, 9]") return str
return "OK"
}
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
class MyCollection<T>(val delegate: Collection<T>): Collection<T> by delegate
fun box(): String {
val collection = MyCollection(listOf(2, 3, 9)) as java.util.Collection<*>
val array1 = collection.toArray()
val array2 = collection.toArray(arrayOfNulls<Int>(3) as Array<Int>)
if (!array1.isArrayOf<Any>()) return (array1 as Object).getClass().toString()
if (!array2.isArrayOf<Int>()) return (array2 as Object).getClass().toString()
val s1 = array1.contentToString()
val s2 = array2.contentToString()
if (s1 != "[2, 3, 9]") return "s1 = $s1"
if (s2 != "[2, 3, 9]") return "s2 = $s2"
return "OK"
}
@@ -0,0 +1,40 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
import java.util.Arrays
class MyCollection<T>(val delegate: Collection<T>): Collection<T> by delegate {
public fun toArray(): Array<Any?> {
val a = arrayOfNulls<Any?>(3)
a[0] = 0
a[1] = 1
a[2] = 2
return a
}
public fun <E> toArray(array: Array<E>): Array<E> {
val asIntArray = array as Array<Int>
asIntArray[0] = 0
asIntArray[1] = 1
asIntArray[2] = 2
return array
}
}
fun box(): String {
val collection = MyCollection(Arrays.asList(2, 3, 9)) as java.util.Collection<*>
val array1 = collection.toArray()
val array2 = collection.toArray(arrayOfNulls<Int>(3) as Array<Int>)
if (!array1.isArrayOf<Any>()) return (array1 as Object).getClass().toString()
if (!array2.isArrayOf<Int>()) return (array2 as Object).getClass().toString()
val s1 = Arrays.toString(array1)
val s2 = Arrays.toString(array2)
if (s1 != "[0, 1, 2]") return "s1 = $s1"
if (s2 != "[0, 1, 2]") return "s2 = $s2"
return "OK"
}
@@ -0,0 +1,50 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: SingletonCollection.kt
package test
open class SingletonCollection<T>(val value: T) : AbstractCollection<T>() {
override val size = 1
override fun iterator(): Iterator<T> = listOf(value).iterator()
protected override final fun toArray(): Array<Any?> =
arrayOf<Any?>(value)
protected override final fun <E> toArray(a: Array<E>): Array<E> {
a[0] = value as E
return a
}
}
// FILE: DerivedSingletonCollection.kt
package test2
import test.*
class DerivedSingletonCollection<T>(value: T) : SingletonCollection<T>(value)
// FILE: box.kt
import test.*
import test2.*
fun box(): String {
val sc = SingletonCollection(42)
val test1 = (sc as java.util.Collection<Int>).toArray()
if (test1[0] != 42) return "Failed #1"
val test2 = arrayOf<Any?>(0)
(sc as java.util.Collection<Int>).toArray(test2)
if (test2[0] != 42) return "Failed #2"
val dsc = DerivedSingletonCollection(42)
val test3 = (dsc as java.util.Collection<Int>).toArray()
if (test3[0] != 42) return "Failed #3"
val test4 = arrayOf<Any?>(0)
(dsc as java.util.Collection<Int>).toArray(test4)
if (test4[0] != 42) return "Failed #4"
return "OK"
}
@@ -0,0 +1,68 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: SingletonCollection.kt
package test
open class SingletonCollection<T>(val value: T) : AbstractCollection<T>() {
override val size = 1
override fun iterator(): Iterator<T> = listOf(value).iterator()
protected override fun toArray(): Array<Any?> =
arrayOf<Any?>(value)
protected override fun <E> toArray(a: Array<E>): Array<E> {
a[0] = value as E
return a
}
}
// FILE: JavaSingletonCollection.java
import test.*;
public class JavaSingletonCollection<T> extends SingletonCollection<T> {
public JavaSingletonCollection(T value) {
super(value);
}
}
// FILE: JavaSingletonCollection2.java
import test.*;
public class JavaSingletonCollection2<T> extends SingletonCollection<T> {
public JavaSingletonCollection2(T value) {
super(value);
}
public Object[] toArray() {
return super.toArray();
}
public <E> E[] toArray(E[] arr) {
return super.toArray(arr);
}
}
// FILE: box.kt
import test.*
fun box(): String {
val jsc = JavaSingletonCollection(42) as java.util.Collection<Int>
val test3 = jsc.toArray()
if (test3[0] != 42) return "Failed #3"
val test4 = arrayOf<Any?>(0)
jsc.toArray(test4)
if (test4[0] != 42) return "Failed #4"
val jsc2 = JavaSingletonCollection2(42) as java.util.Collection<Int>
val test5 = jsc2.toArray()
if (test5[0] != 42) return "Failed #5"
val test6 = arrayOf<Any?>(0)
jsc2.toArray(test6)
if (test6[0] != 42) return "Failed #6"
return "OK"
}
@@ -0,0 +1,15 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// missing isArrayOf on JS
// WITH_RUNTIME
fun box(): String {
val array = listOf(2, 3, 9).toTypedArray()
if (!array.isArrayOf<Int>()) return "fail: is not Array<Int>"
val str = array.contentToString()
if (str != "[2, 3, 9]") return str
return "OK"
}