backend/tests: Add blackbox tests from Kotlin JVM

Added tests from testData/codegen/box directory. There are blackbox tests
in other directories and they are to be added.
This commit is contained in:
Ilya Matveev
2017-01-12 19:43:20 +07:00
parent d5988297b1
commit 1b553ebfaf
2643 changed files with 66666 additions and 0 deletions
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun box(): String {
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()
}
@@ -0,0 +1,16 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.io.*
fun box(): String {
val ACCEPT_NAME = "test"
val WRONG_NAME = "wrong"
val filter = FileFilter { file -> ACCEPT_NAME == file?.getName() }
if (!filter.accept(File(ACCEPT_NAME))) return "Wrong answer for $ACCEPT_NAME"
if (filter.accept(File(WRONG_NAME))) return "Wrong answer for $WRONG_NAME"
return "OK"
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun box(): String {
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 }
list.sortWith(Comparator(comparatorFun))
return if (list == expected) "OK" else list.toString()
}
@@ -0,0 +1,17 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
import java.io.*
fun box(): String {
val ACCEPT_NAME = "test"
val WRONG_NAME = "wrong"
val f : (File?) -> Boolean = { file -> ACCEPT_NAME == file?.getName() }
val filter = FileFilter(f)
if (!filter.accept(File(ACCEPT_NAME))) return "Wrong answer for $ACCEPT_NAME"
if (filter.accept(File(WRONG_NAME))) return "Wrong answer for $WRONG_NAME"
return "OK"
}
@@ -0,0 +1,9 @@
// TARGET_BACKEND: JVM
fun box(): String {
var result = "FAIL"
val f = { result = "OK" }
val r = Runnable(f)
r.run()
return result
}
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM
var result = "FAIL"
fun getFun(): () -> Unit {
return { result = "OK" }
}
fun box(): String {
val r = Runnable(getFun())
r.run()
return result
}
@@ -0,0 +1,9 @@
// TARGET_BACKEND: JVM
var result = "FAIL"
fun box(): String {
val r = Runnable { result = "OK" }
r.run()
return result
}
@@ -0,0 +1,10 @@
// TARGET_BACKEND: JVM
fun box(): String {
val o = "O"
var result = ""
val r = Runnable { result = o + "K" } //capturing local vals and local var
r.run()
return result
}
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM
class Box(val s: String) {
fun extract(): String {
var result = ""
Runnable { result = s }.run() // capturing this and local var
return result
}
}
fun box(): String {
return Box("OK").extract()
}
@@ -0,0 +1,26 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
// FILE: 1/wrapped.kt
fun getWrapped1(): Runnable {
val f = { }
return Runnable(f)
}
// FILE: 2/wrapped2.kt
fun getWrapped2(): Runnable {
val f = { }
return Runnable(f)
}
// FILE: box.kt
fun box(): String {
val class1 = getWrapped1().javaClass
val class2 = getWrapped2().javaClass
return if (class1 != class2) "OK" else "Same class: $class1"
}
@@ -0,0 +1,10 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
fun box(): String {
val f = { }
val class1 = (Runnable(f) as Object).getClass()
val class2 = (Runnable(f) as Object).getClass()
return if (class1 == class2) "OK" else "$class1 $class2"
}
@@ -0,0 +1,14 @@
// TARGET_BACKEND: JVM
var global = ""
fun Runnable(f: () -> Unit) = object : Runnable {
public override fun run() {
global = "OK"
}
}
fun box(): String {
Runnable { global = "FAIL" } .run()
return global
}