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:
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@JvmName("bar")
|
||||
fun foo() = "foo"
|
||||
|
||||
fun box(): String {
|
||||
val f = (::foo)()
|
||||
if (f != "foo") return "Fail: $f"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun <T> List<T>.foo() = "foo"
|
||||
|
||||
@JvmName("fooInt")
|
||||
fun List<Int>.foo() = "fooInt"
|
||||
|
||||
fun box(): String {
|
||||
val strings = listOf("", "").foo()
|
||||
if (strings != "foo") return "Fail: $strings"
|
||||
|
||||
val ints = listOf(1, 2).foo()
|
||||
if (ints != "fooInt") return "Fail: $ints"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
// See:
|
||||
// http://kotlinlang.org/docs/reference/java-interop.html#handling-signature-clashes-with-platformname
|
||||
// https://youtrack.jetbrains.com/issue/KT-5524
|
||||
|
||||
val strs = listOf("abc", "def")
|
||||
val ints = listOf(1, 2, 3)
|
||||
|
||||
class C {
|
||||
// Instance methods
|
||||
|
||||
@JvmName("instMethodStr")
|
||||
fun instMethod(list: List<String>): String = "instMethodStr"
|
||||
|
||||
@JvmName("instMethodInt")
|
||||
fun instMethod(list: List<Int>): String = "instMethodInt"
|
||||
|
||||
// Properties
|
||||
|
||||
var rwProperty: Int
|
||||
@JvmName("get_rwProperty")
|
||||
get() = 123
|
||||
@JvmName("set_rwProperty")
|
||||
set(v) {}
|
||||
|
||||
var rwValue = 111
|
||||
|
||||
fun getRwProperty(): Int = rwValue
|
||||
|
||||
fun setRwProperty(v: Int) {
|
||||
rwValue = v
|
||||
}
|
||||
|
||||
// Extension methods
|
||||
|
||||
class Inner
|
||||
|
||||
@JvmName("extMethodWithGenericParamStr")
|
||||
fun Inner.extMethodWithGenericParam(list: List<String>): String = "extMethodWithGenericParamStr"
|
||||
|
||||
@JvmName("extMethodWithGenericParamInt")
|
||||
fun Inner.extMethodWithGenericParam(list: List<Int>): String = "extMethodWithGenericParamInt"
|
||||
|
||||
// This is already covered by extMethodWithGenericParam(), but might be relevant for a platform
|
||||
// with extension method code generation strategy different from Java 6.
|
||||
|
||||
@JvmName("extMethodWithGenericReceiverStr")
|
||||
fun List<String>.extMethodWithGenericReceiver(): String = "extMethodWithGenericReceiverStr"
|
||||
|
||||
@JvmName("extMethodWithGenericReceiverInt")
|
||||
fun List<Int>.extMethodWithGenericReceiver(): String = "extMethodWithGenericReceiverInt"
|
||||
|
||||
// Extension method vs instance method
|
||||
|
||||
@JvmName("ambigMethod1")
|
||||
fun ambigMethod(str: String): String = "ambigMethod1"
|
||||
|
||||
@JvmName("ambigMethod2")
|
||||
fun String.ambigMethod(): String = "ambigMethod2"
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
|
||||
// Instance methods:
|
||||
// method signatures with erased types SHOULD NOT clash
|
||||
|
||||
val test1 = c.instMethod(strs)
|
||||
if (test1 != "instMethodStr") return "Fail: c.instMethod(strs)==$test1"
|
||||
|
||||
val test2 = c.instMethod(ints)
|
||||
if (test2 != "instMethodInt") return "Fail: c.instMethod(ints)==$test2"
|
||||
|
||||
// Properties:
|
||||
// property accessors SHOULD NOT clash with class methods
|
||||
|
||||
val test3 = c.rwProperty
|
||||
if (test3 != 123) return "Fail: c.rwProperty==$test3"
|
||||
|
||||
val test3a = c.getRwProperty()
|
||||
if (test3a != 111) return "Fail: c.getRwProperty()==$test3a"
|
||||
|
||||
c.setRwProperty(444)
|
||||
val test3b = c.rwProperty
|
||||
if (test3b != 123) return "Fail: c.rwProperty==$test3b after c.setRwProperty(1234)"
|
||||
val test3c = c.getRwProperty()
|
||||
if (test3c != 444) return "Fail: c.getRwProperty()==$test3c after c.setRwProperty(1234)"
|
||||
|
||||
// Extension methods:
|
||||
// method signatures with erased types SHOULD NOT clash
|
||||
|
||||
val test4 = with(c) { C.Inner().extMethodWithGenericParam(strs) }
|
||||
if (test4 != "extMethodWithGenericParamStr") return "Fail: with(c) { C.Inner().extMethodWithGenericParam(strs) }==$test4"
|
||||
|
||||
val test5 = with(c) { C.Inner().extMethodWithGenericParam(ints) }
|
||||
if (test5 != "extMethodWithGenericParamInt") return "Fail: with(c) { C.Inner().extMethodWithGenericParam(ints) }==$test5"
|
||||
|
||||
val test6 = with(c) { strs.extMethodWithGenericReceiver() }
|
||||
if (test6 != "extMethodWithGenericReceiverStr") return "Fail: with(c) { strs.extMethodWithGenericReceiver() }==$test6"
|
||||
|
||||
val test7 = with(c) { ints.extMethodWithGenericReceiver() }
|
||||
if (test7 != "extMethodWithGenericReceiverInt") return "Fail: with(c) { ints.extMethodWithGenericReceiver() }==$test7"
|
||||
|
||||
// Extension method SHOULD NOT clash with instance method with the same Java signature.
|
||||
|
||||
val str = "abc"
|
||||
|
||||
val test8 = with(c) { ambigMethod(str) }
|
||||
if (test8 != "ambigMethod1") return "Fail: with(c) { ambigMethod(str) }==$test8"
|
||||
|
||||
val test9 = with(c) { str.ambigMethod() }
|
||||
if (test9 != "ambigMethod2") return "Fail: with(c) { str.ambigMethod() }==$test9"
|
||||
|
||||
// Everything is fine.
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// FILE: FakePlatformName.java
|
||||
|
||||
import kotlin.jvm.JvmName;
|
||||
|
||||
public class FakePlatformName {
|
||||
@JvmName(name = "fake")
|
||||
public String foo() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
public String fake() {
|
||||
return "fake";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: FakePlatformName.kt
|
||||
|
||||
fun box(): String {
|
||||
val test1 = FakePlatformName().foo()
|
||||
if (test1 != "foo") return "Failed: FakePlatformName().foo()==$test1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
// FILE: Baz.java
|
||||
|
||||
public class Baz {
|
||||
public static String baz() {
|
||||
return Foo.foo() + Bar.bar();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: bar.kt
|
||||
|
||||
@file:JvmName("Bar")
|
||||
public fun bar(): String = "K"
|
||||
|
||||
// FILE: foo.kt
|
||||
|
||||
@file:JvmName("Foo")
|
||||
public fun foo(): String = "O"
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String = Baz.baz()
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
// FILE: StringHolder.java
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface StringHolder {
|
||||
public String value();
|
||||
}
|
||||
|
||||
// FILE: fileFacade.kt
|
||||
|
||||
@file:StringHolder("OK")
|
||||
|
||||
fun box(): String =
|
||||
Class.forName("FileFacadeKt").getAnnotation(StringHolder::class.java)?.value ?: "null"
|
||||
@@ -0,0 +1,20 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
// FILE: Bar.java
|
||||
|
||||
public class Bar {
|
||||
public static String bar() {
|
||||
return Foo.foo();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: foo.kt
|
||||
|
||||
@file:JvmName("Foo")
|
||||
public fun foo(): String = "OK"
|
||||
|
||||
// FILE: simple.kt
|
||||
|
||||
fun box(): String = Bar.bar()
|
||||
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@JvmName("bar")
|
||||
fun foo() = "foo"
|
||||
|
||||
fun box(): String {
|
||||
val f = foo()
|
||||
if (f != "foo") return "Fail: $f"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("Test")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String = qux()
|
||||
fun qux(): String = "OK"
|
||||
|
||||
fun box(): String = foo()
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("Test")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String {
|
||||
class Local(val x: String)
|
||||
return Local("OK").x
|
||||
}
|
||||
|
||||
fun box(): String = foo()
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("Test")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String {
|
||||
open class LocalGeneric<T>(val x: T)
|
||||
class Derived(x: String) : LocalGeneric<String>(x)
|
||||
fun <T> LocalGeneric<T>.extFun() = this
|
||||
fun <T> localFun(x: LocalGeneric<T>) = x
|
||||
class Local3 {
|
||||
fun <T> method(x: LocalGeneric<T>) = x.x
|
||||
}
|
||||
return Local3().method(localFun(Derived("OK")).extFun())
|
||||
}
|
||||
|
||||
fun box(): String = foo()
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class TestIt {
|
||||
@get:JvmName("getIsFries")
|
||||
@set:JvmName("setIsFries")
|
||||
var isFries: Boolean = true
|
||||
|
||||
@get:JvmName("getIsUpdateable")
|
||||
@set:JvmName("setIsUpdateable")
|
||||
var isUpdateable: Boolean by Delegate
|
||||
}
|
||||
|
||||
object Delegate {
|
||||
operator fun getValue(thiz: Any?, metadata: Any?) = true
|
||||
operator fun setValue(thiz: Any?, metadata: Any?, value: Boolean) {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(
|
||||
listOf("getIsFries", "getIsUpdateable", "setIsFries", "setIsUpdateable"),
|
||||
TestIt::class.java.declaredMethods.map { it.name }.sorted()
|
||||
)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
var v: Int = 1
|
||||
@JvmName("vget")
|
||||
get
|
||||
@JvmName("vset")
|
||||
set
|
||||
|
||||
fun box(): String {
|
||||
v += 1
|
||||
if (v != 2) return "Fail: $v"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("Util")
|
||||
package test
|
||||
|
||||
fun foo(): String = bar()
|
||||
fun bar(): String = qux()
|
||||
fun qux(): String = "OK"
|
||||
|
||||
fun box(): String = foo()
|
||||
Reference in New Issue
Block a user