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,51 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
// FILE: JavaClass.java
public class JavaClass {
public static class C extends B {
public OutPair<String, Integer> foo() {
return super.foo();
}
public In<Object> bar() {
return super.bar();
}
}
public static String test() {
A a = new C();
if (!a.foo().getX().equals("OK")) return "fail 1";
if (!a.foo().getY().equals(123)) return "fail 2";
if (!a.bar().make("123").equals("123")) return "fail 3";
return "OK";
}
}
// FILE: main.kt
class OutPair<out X, out Y>(val x: X, val y: Y)
class In<in Z> {
fun make(x: Z): String = x.toString()
}
@JvmSuppressWildcards(suppress = false)
interface A {
fun foo(): OutPair<CharSequence, Number>
fun bar(): In<String>
}
abstract class B : A {
override fun foo(): OutPair<String, Int> = OutPair("OK", 123)
override fun bar(): In<Any> = In()
}
fun box(): String {
return JavaClass.test();
}
@@ -0,0 +1,50 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
// FILE: JavaClass.java
public class JavaClass {
public static class C extends B {
public OutPair<String, Integer> foo() {
return super.foo();
}
public In<Object> bar() {
return super.bar();
}
}
public static String test() {
A a = new C();
if (!a.foo().getX().equals("OK")) return "fail 1";
if (!a.foo().getY().equals(123)) return "fail 2";
if (!a.bar().make("123").equals("123")) return "fail 3";
return "OK";
}
}
// FILE: main.kt
class OutPair<out X, out Y>(val x: X, val y: Y)
class In<in Z> {
fun make(x: Z): String = x.toString()
}
interface A {
fun foo(): OutPair<@JvmWildcard CharSequence, @JvmSuppressWildcards(false) Number>
fun bar(): In<@JvmWildcard String>
}
abstract class B : A {
override fun foo(): OutPair<String, Int> = OutPair("OK", 123)
override fun bar(): In<Any> = In()
}
fun box(): String {
return JavaClass.test();
}
@@ -0,0 +1,24 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// FILE: JavaClass.java
public class JavaClass {
public static String test() {
return MainKt.bar(MainKt.foo());
}
}
// FILE: main.kt
class Pair<out X, out Y>(val x: X, val y: Y)
class Inv<T>(val x: T)
fun foo(): Inv<Pair<CharSequence, CharSequence>> = Inv(Pair("O", "K"))
fun bar(inv: Inv<Pair<CharSequence, CharSequence>>) = inv.x.x.toString() + inv.x.y
fun box(): String {
return JavaClass.test();
}
@@ -0,0 +1,26 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
// FILE: J.java
import kotlin.Function;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
public class J {
public static String test(Function<String> x) {
if (x instanceof Function1) return "Fail 1";
if (x instanceof Function2) return "Fail 2";
if (!(x instanceof Function0)) return "Fail 3";
return ((Function0<String>) x).invoke();
}
}
// FILE: K.kt
fun box(): String {
return J.test({ "OK" })
}
@@ -0,0 +1,32 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// FILE: Test.java
public class Test {
public static String invokeFoo() {
try {
ExtensionKt.foo(null);
}
catch (IllegalArgumentException e) {
try {
ExtensionKt.getBar(null);
}
catch (IllegalArgumentException f) {
return "OK";
}
}
return "Fail: assertion must have been fired";
}
}
// FILE: extension.kt
fun Any.foo() { }
val Any.bar: String get() = ""
fun box(): String {
return Test.invokeFoo()
}
@@ -0,0 +1,10 @@
fun <K: Any, V: Any> foo(k: K, v: V) {
val map = HashMap<K, V>()
val old = map.put(k, v)
}
fun box(): String {
foo("", "")
return "OK"
}
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
data class A(var x: Int) : Cloneable {
public override fun clone(): A = A(x)
}
fun box(): String {
val a = A(42)
val b = a.clone()
if (b != a) return "Fail equals"
if (b === a) return "Fail identity"
return "OK"
}
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
data class A(var x: Int) : Cloneable {
public override fun clone(): A = super.clone() as A
}
fun box(): String {
val a = A(42)
val b = a.clone()
if (a != b) return "Fail equals"
if (a === b) return "Fail identity"
return "OK"
}
@@ -0,0 +1,19 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
data class A(var x: Int) : Cloneable {
public override fun clone(): A {
val result = super.clone() as A
result.x = 239
return result
}
}
fun box(): String {
val a = A(42)
val b = a.clone()
if (a == b) return "Fail: $a == $b"
if (a === b) return "Fail: $a === $b"
if (b.x != 239) return "Fail: b.x = ${b.x}"
return "OK"
}
@@ -0,0 +1,12 @@
// TARGET_BACKEND: JVM
fun box(): String {
val a = HashSet<String>()
a.add("live")
a.add("long")
a.add("prosper")
val b = a.clone()
if (a != b) return "Fail equals"
if (a === b) return "Fail identity"
return "OK"
}
@@ -0,0 +1,32 @@
// TARGET_BACKEND: JVM
open class A : Cloneable {
public override fun clone(): A = super.clone() as A
}
open class B(var s: String) : A() {
override fun clone(): B = super.clone() as B
}
open class C(s: String, var l: ArrayList<Any>): B(s) {
override fun clone(): C {
val result = super.clone() as C
result.l = l.clone() as ArrayList<Any>
return result
}
}
fun box(): String {
val l = ArrayList<Any>()
l.add(true)
val c = C("OK", l)
val d = c.clone()
if (c.s != d.s) return "Fail s: ${d.s}"
if (c.l != d.l) return "Fail l: ${d.l}"
if (c.l === d.l) return "Fail list identity"
if (c === d) return "Fail identity"
return "OK"
}
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
data class A(val s: String) : Cloneable {
fun externalClone(): A = clone() as A
}
fun box(): String {
val a = A("OK")
val b = a.externalClone()
if (a != b) return "Fail equals"
if (a === b) return "Fail identity"
return b.s
}