Make several tests running on JS backend.

This commit is contained in:
Ilya Gorbunov
2016-11-17 01:58:43 +03:00
parent 0899a0fdda
commit 62fe89b536
16 changed files with 48 additions and 196 deletions
+2 -5
View File
@@ -1,14 +1,11 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.util.Arrays
// WITH_RUNTIME
abstract class A {
abstract fun foo(): List<String>
}
interface B {
fun foo(): ArrayList<String> = ArrayList(Arrays.asList("B"))
fun foo(): ArrayList<String> = ArrayList(listOf("B"))
}
open class C : A(), B {
@@ -1,6 +1,4 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.util.Arrays
// WITH_RUNTIME
interface A {
fun foo(): Collection<String>
@@ -11,7 +9,7 @@ interface B : A {
}
class C : B {
override fun foo(): MutableList<String> = ArrayList(Arrays.asList("C"))
override fun foo(): MutableList<String> = ArrayList(listOf("C"))
}
fun box(): String {
@@ -1,22 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.util.ArrayList
import java.util.Arrays
import java.util.Collections
import java.util.Comparator
// WITH_RUNTIME
fun sort(list: MutableList<String>, comparator: (String, String) -> Int) {
Collections.sort(list, object : Comparator<String> {
override fun compare(p0: String, p1: String) = comparator(p0, p1)
})
list.sortWith(Comparator(comparator))
}
fun compare(s1: String, s2: String) = s1.compareTo(s2)
fun box(): String {
val l = ArrayList(Arrays.asList("d", "b", "c", "e", "a"))
val l = mutableListOf("d", "b", "c", "e", "a")
sort(l, ::compare)
if (l != Arrays.asList("a", "b", "c", "d", "e")) return "Fail: $l"
if (l != listOf("a", "b", "c", "d", "e")) return "Fail: $l"
return "OK"
}
@@ -1,10 +1,5 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
@@ -37,7 +32,7 @@ inline fun asFailsWithCCE(operation: String, block: () -> Unit) {
try {
block()
}
catch (e: java.lang.ClassCastException) {
catch (e: ClassCastException) {
return
}
catch (e: Throwable) {
@@ -1,10 +1,5 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
@@ -33,6 +28,8 @@ class MME : MutableMap.MutableEntry<String, String> {
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
fun assert(condition: Boolean, message: () -> String) { if (!condition) throw AssertionError(message())}
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
@@ -1,10 +1,5 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
@@ -46,7 +41,7 @@ inline fun <reified T> reifiedAsFailsWithCCE(x: Any, operation: String) {
try {
x as T
}
catch (e: java.lang.ClassCastException) {
catch (e: ClassCastException) {
return
}
catch (e: Throwable) {
@@ -1,10 +1,5 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
@@ -36,6 +31,8 @@ class MME : MutableMap.MutableEntry<String, String> {
inline fun <reified T> reifiedIs(x: Any): Boolean = x is T
inline fun <reified T> reifiedIsNot(x: Any): Boolean = x !is T
fun assert(condition: Boolean, message: () -> String) { if (!condition) throw AssertionError(message())}
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
@@ -1,10 +1,5 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
@@ -33,6 +28,9 @@ class MME : MutableMap.MutableEntry<String, String> {
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
fun assert(condition: Boolean, message: () -> String) { if (!condition) throw AssertionError(message())}
inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
try {
val x = cast()
@@ -1,9 +1,6 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.Arrays
fun foo(): List<String>? = Arrays.asList("abcde")
fun foo(): List<String>? = listOf("abcde")
fun box(): String {
for (i in 1..3) {
+2 -5
View File
@@ -1,7 +1,4 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.util.*
// WITH_RUNTIME
class A() {
infix fun <T> ArrayList<T>.add3(el: T) = add(el)
@@ -22,6 +19,6 @@ fun box() : String{
list add2 i
}
A().test(list)
System.out?.println(list)
println(list)
return "OK"
}
+1 -5
View File
@@ -1,7 +1,3 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.util.ArrayList
fun box() : String {
val array = ArrayList<String>()
@@ -14,7 +10,7 @@ fun box() : String {
var <T> ArrayList<T>.length : Int
get() = size
set(value: Int) = throw java.lang.Error()
set(value: Int) = throw Error()
var <T> ArrayList<T>.last : T
get() = get(size-1)!!
@@ -1,11 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.util.*
// WITH_RUNTIME
fun box(): String {
val list = ArrayList(Arrays.asList(3, 2, 4, 8, 1, 5))
val expected = ArrayList(Arrays.asList(8, 5, 4, 3, 2, 1))
Collections.sort(list, Comparator { a, b -> b - a })
val list = mutableListOf(3, 2, 4, 8, 1, 5)
val expected = listOf(8, 5, 4, 3, 2, 1)
list.sortWith(Comparator { a, b -> b - a })
return if (list == expected) "OK" else list.toString()
}
@@ -1,12 +1,9 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.util.*
// WITH_RUNTIME
fun box(): String {
val list = ArrayList(Arrays.asList(3, 2, 4, 8, 1, 5))
val expected = ArrayList(Arrays.asList(8, 5, 4, 3, 2, 1))
val list = mutableListOf(3, 2, 4, 8, 1, 5)
val expected = listOf(8, 5, 4, 3, 2, 1)
val comparatorFun: (Int, Int) -> Int = { a, b -> b - a }
Collections.sort(list, Comparator(comparatorFun))
list.sortWith(Comparator(comparatorFun))
return if (list == expected) "OK" else list.toString()
}
@@ -1,11 +1,5 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.ArrayList
import java.util.Arrays
fun box(): String {
val list = ArrayList<Pair<String,String>>()
list.add(Pair("Sample", "http://cyber.law.harvard.edu/rss/examples/rss2sample.xml"))
@@ -13,7 +7,7 @@ fun box(): String {
val keys = list.map { it.first }.toTypedArray<String>()
val keysToString = Arrays.toString(keys)
val keysToString = keys.contentToString()
if (keysToString != "[Sample, Scripting]") return keysToString
return "OK"
@@ -1,14 +1,9 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import java.util.Arrays
fun getCopyToArray(): Array<Int> = Arrays.asList(2, 3, 9).toTypedArray()
fun getCopyToArray(): Array<Int> = listOf(2, 3, 9).toTypedArray()
fun box(): String {
val str = Arrays.toString(getCopyToArray())
val str = getCopyToArray().contentToString()
if (str != "[2, 3, 9]") return str
return "OK"