Add some new tests on functions and extension functions
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
val f = fun (s: String): String = s
|
||||
val g = f as String.() -> String
|
||||
if ("OK".g() != "OK") return "Fail 1"
|
||||
|
||||
val h = fun String.(): String = this
|
||||
val i = h as (String) -> String
|
||||
if (i("OK") != "OK") return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import kotlin.reflect.KMemberFunction;
|
||||
|
||||
public class J {
|
||||
public static String go() {
|
||||
KMemberFunction<K, String> fun = K.Companion.getRef();
|
||||
Object result = ((Function2) fun).invoke(new K(), "KO");
|
||||
return (String) result;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class K {
|
||||
fun reverse(s: String): String {
|
||||
return s.reverse()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getRef() = K::reverse
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return J.go()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fun box(): String =
|
||||
if (listOf("abc", "de", "f").map(String::length) == listOf(3, 2, 1)) "OK" else "Fail"
|
||||
Reference in New Issue
Block a user