Files
kotlin/compiler/testData/codegen/box/jvmField/topLevelFieldReflection.kt
Ilya Matveev a5e4e0284e Mute some box tests for native backend
This patch mutes the following test categories:
   * Tests with java dependencies (System class,
     java stdlib, jvm-oriented annotations etc).
   * Coroutines tests.
   * Reflection tests.
   * Tests with an inheritance from the standard
     collections.
2017-03-10 19:59:37 +03:00

33 lines
1.0 KiB
Kotlin
Vendored

// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// WITH_REFLECT
package test
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.jvm.kotlinProperty
import kotlin.test.assertEquals
public var publicField = "1"
internal var internalField = "2"
fun testAccessors() {
val packageClass = Class.forName("test.TopLevelFieldReflectionKt")
packageClass.getDeclaredField("publicField").kotlinProperty
checkAccessor(packageClass.getDeclaredField("publicField").kotlinProperty as KMutableProperty0<String>, "1", "3")
checkAccessor(packageClass.getDeclaredField("internalField").kotlinProperty as KMutableProperty0<String>, "2", "4")
}
fun box(): String {
testAccessors()
return "OK"
}
public fun < R> checkAccessor(prop: KMutableProperty0<R>, value: R, newValue: R) {
assertEquals(prop.get(), value, "Property ${prop} has wrong value")
prop.set(newValue)
assertEquals(prop.get(), newValue, "Property ${prop} has wrong value")
}