[JS IR] Add reflection tests
This commit is contained in:
committed by
Space Team
parent
c13cc38758
commit
85b2daf41d
+18
@@ -10208,12 +10208,24 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassCompanion.kt")
|
||||||
|
public void testKClassCompanion() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassIsInstance.kt")
|
@TestMetadata("kClassIsInstance.kt")
|
||||||
public void testKClassIsInstance() throws Exception {
|
public void testKClassIsInstance() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassLambda.kt")
|
||||||
|
public void testKClassLambda() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassOnReifiedType.kt")
|
@TestMetadata("kClassOnReifiedType.kt")
|
||||||
public void testKClassOnReifiedType() throws Exception {
|
public void testKClassOnReifiedType() throws Exception {
|
||||||
@@ -10244,6 +10256,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassSuspendFunction.kt")
|
||||||
|
public void testKClassSuspendFunction() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassSuspendFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassToAndFromJsClass.kt")
|
@TestMetadata("kClassToAndFromJsClass.kt")
|
||||||
public void testKClassToAndFromJsClass() throws Exception {
|
public void testKClassToAndFromJsClass() throws Exception {
|
||||||
|
|||||||
+18
@@ -10314,12 +10314,24 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassCompanion.kt")
|
||||||
|
public void testKClassCompanion() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassIsInstance.kt")
|
@TestMetadata("kClassIsInstance.kt")
|
||||||
public void testKClassIsInstance() throws Exception {
|
public void testKClassIsInstance() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassLambda.kt")
|
||||||
|
public void testKClassLambda() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassOnReifiedType.kt")
|
@TestMetadata("kClassOnReifiedType.kt")
|
||||||
public void testKClassOnReifiedType() throws Exception {
|
public void testKClassOnReifiedType() throws Exception {
|
||||||
@@ -10350,6 +10362,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassSuspendFunction.kt")
|
||||||
|
public void testKClassSuspendFunction() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassSuspendFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassToAndFromJsClass.kt")
|
@TestMetadata("kClassToAndFromJsClass.kt")
|
||||||
public void testKClassToAndFromJsClass() throws Exception {
|
public void testKClassToAndFromJsClass() throws Exception {
|
||||||
|
|||||||
+18
@@ -10314,12 +10314,24 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassCompanion.kt")
|
||||||
|
public void testKClassCompanion() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassIsInstance.kt")
|
@TestMetadata("kClassIsInstance.kt")
|
||||||
public void testKClassIsInstance() throws Exception {
|
public void testKClassIsInstance() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassLambda.kt")
|
||||||
|
public void testKClassLambda() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassOnReifiedType.kt")
|
@TestMetadata("kClassOnReifiedType.kt")
|
||||||
public void testKClassOnReifiedType() throws Exception {
|
public void testKClassOnReifiedType() throws Exception {
|
||||||
@@ -10350,6 +10362,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassSuspendFunction.kt")
|
||||||
|
public void testKClassSuspendFunction() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassSuspendFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassToAndFromJsClass.kt")
|
@TestMetadata("kClassToAndFromJsClass.kt")
|
||||||
public void testKClassToAndFromJsClass() throws Exception {
|
public void testKClassToAndFromJsClass() throws Exception {
|
||||||
|
|||||||
+18
@@ -10208,12 +10208,24 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
runTest("js/js.translator/testData/box/reflection/kClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassCompanion.kt")
|
||||||
|
public void testKClassCompanion() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassIsInstance.kt")
|
@TestMetadata("kClassIsInstance.kt")
|
||||||
public void testKClassIsInstance() throws Exception {
|
public void testKClassIsInstance() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassIsInstance.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassLambda.kt")
|
||||||
|
public void testKClassLambda() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassOnReifiedType.kt")
|
@TestMetadata("kClassOnReifiedType.kt")
|
||||||
public void testKClassOnReifiedType() throws Exception {
|
public void testKClassOnReifiedType() throws Exception {
|
||||||
@@ -10244,6 +10256,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kClassSuspendFunction.kt")
|
||||||
|
public void testKClassSuspendFunction() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/reflection/kClassSuspendFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kClassToAndFromJsClass.kt")
|
@TestMetadata("kClassToAndFromJsClass.kt")
|
||||||
public void testKClassToAndFromJsClass() throws Exception {
|
public void testKClassToAndFromJsClass() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
class A {
|
||||||
|
companion object {
|
||||||
|
fun getSimpleName() = this::class.simpleName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B {
|
||||||
|
companion object MyCompanion {
|
||||||
|
fun getSimpleName() = this::class.simpleName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSimpleName(x: Any) = x::class.simpleName
|
||||||
|
inline fun <reified T> getSimpleNameReified(x: T) = T::class.simpleName
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
assertEquals("Companion", A.getSimpleName())
|
||||||
|
assertEquals("MyCompanion", B.getSimpleName())
|
||||||
|
|
||||||
|
assertEquals("Companion", A.Companion.getSimpleName())
|
||||||
|
assertEquals("MyCompanion", B.MyCompanion.getSimpleName())
|
||||||
|
|
||||||
|
assertEquals("Companion", getSimpleName(A.Companion))
|
||||||
|
assertEquals("MyCompanion", getSimpleName(B.MyCompanion))
|
||||||
|
|
||||||
|
assertEquals("Companion", getSimpleNameReified(A.Companion))
|
||||||
|
assertEquals("MyCompanion", getSimpleNameReified(B.MyCompanion))
|
||||||
|
|
||||||
|
assertEquals("Companion", A.Companion::class.simpleName)
|
||||||
|
assertEquals("MyCompanion", B.MyCompanion::class.simpleName)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
import kotlin.coroutines.startCoroutine
|
||||||
|
|
||||||
|
class CoroutineStub {
|
||||||
|
companion object {
|
||||||
|
fun evaluate(c: suspend () -> Unit) {
|
||||||
|
c.startCoroutine(object : Continuation<Unit> {
|
||||||
|
override val context = EmptyCoroutineContext
|
||||||
|
override fun resumeWith(result: Result<Unit>) {
|
||||||
|
result.getOrThrow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testLabmdaParam(x: () -> Unit) {
|
||||||
|
assertEquals(x::class.simpleName, "Function0")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSuspendLambaParam(x: suspend () -> Unit) {
|
||||||
|
assertEquals(x::class.simpleName, "Function1")
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T> testLabmdaParamGeneric(x: T) {
|
||||||
|
assertEquals(T::class.simpleName, "Function0")
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T> testSuspendLambaParamGeneric(x: T) {
|
||||||
|
assertEquals(T::class.simpleName, "SuspendFunction0")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testLabmdaParam({})
|
||||||
|
testSuspendLambaParam(suspend {})
|
||||||
|
testLabmdaParamGeneric({})
|
||||||
|
testSuspendLambaParamGeneric(suspend {})
|
||||||
|
|
||||||
|
val sx = suspend {
|
||||||
|
val sy = suspend {
|
||||||
|
val sz = suspend {
|
||||||
|
val a = {
|
||||||
|
val b = {
|
||||||
|
val c = {
|
||||||
|
CoroutineStub.evaluate {
|
||||||
|
val x = suspend {
|
||||||
|
val y = suspend {
|
||||||
|
val z = suspend { }
|
||||||
|
assertEquals(z::class.simpleName, "Function1")
|
||||||
|
|
||||||
|
assertEquals((suspend { })::class.simpleName, "Function1")
|
||||||
|
assertEquals(({ })::class.simpleName, "Function0")
|
||||||
|
}
|
||||||
|
y()
|
||||||
|
assertEquals(y::class.simpleName, "Function1")
|
||||||
|
}
|
||||||
|
x()
|
||||||
|
assertEquals(x::class.simpleName, "Function1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c()
|
||||||
|
assertEquals(c::class.simpleName, "Function0")
|
||||||
|
}
|
||||||
|
b()
|
||||||
|
assertEquals(b::class.simpleName, "Function0")
|
||||||
|
}
|
||||||
|
a()
|
||||||
|
assertEquals(a::class.simpleName, "Function0")
|
||||||
|
}
|
||||||
|
sz()
|
||||||
|
assertEquals(sz::class.simpleName, "Function1")
|
||||||
|
}
|
||||||
|
sy()
|
||||||
|
assertEquals(sy::class.simpleName, "Function1")
|
||||||
|
}
|
||||||
|
assertEquals(sx::class.simpleName, "Function1")
|
||||||
|
CoroutineStub.evaluate(sx)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
suspend fun testB(x: Int) {}
|
||||||
|
|
||||||
|
suspend fun testA() {
|
||||||
|
testB(123)
|
||||||
|
testB(456)
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
suspend fun testC() {
|
||||||
|
testA()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSimpleName0(x: suspend () -> Unit) = x::class.simpleName
|
||||||
|
fun getSimpleName1(x: suspend (x: Int) -> Unit) = x::class.simpleName
|
||||||
|
inline fun <reified T> getSimpleNameReified(x: T) = T::class.simpleName
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
assertEquals("Function1", getSimpleName0(::testA))
|
||||||
|
assertEquals("Function2", getSimpleName1(::testB))
|
||||||
|
assertEquals("Function1", getSimpleName0(A()::testC))
|
||||||
|
|
||||||
|
assertEquals("KSuspendFunction0", getSimpleNameReified(::testA))
|
||||||
|
assertEquals("KSuspendFunction1", getSimpleNameReified(::testB))
|
||||||
|
assertEquals("KSuspendFunction0", getSimpleNameReified(A()::testC))
|
||||||
|
|
||||||
|
assertEquals("Function1", (::testA)::class.simpleName)
|
||||||
|
assertEquals("Function2", (::testB)::class.simpleName)
|
||||||
|
assertEquals("Function1", (A()::testC)::class.simpleName)
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user