Merge boxWithStdlib testData into box, delete BoxWithStdlib test
This commit is contained in:
committed by
Alexander Udalov
parent
22bfc9786a
commit
06a67e6602
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
open class A {
|
||||
@JvmField public val publicField = "1";
|
||||
@JvmField internal val internalField = "2";
|
||||
@JvmField protected val protectedField = "34";
|
||||
|
||||
fun test(): String {
|
||||
return {
|
||||
publicField + internalField + protectedField
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return if (A().test() == "1234") return "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@JvmField public val publicField = "1";
|
||||
@JvmField internal val internalField = "23";
|
||||
|
||||
fun test(): String {
|
||||
return {
|
||||
publicField + internalField
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return if (test() == "123") return "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertFalse
|
||||
|
||||
@JvmField public val field = "OK";
|
||||
|
||||
class A {
|
||||
@JvmField public val field = "OK";
|
||||
|
||||
companion object {
|
||||
@JvmField public val cfield = "OK";
|
||||
}
|
||||
}
|
||||
|
||||
object Object {
|
||||
@JvmField public val field = "OK";
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
var result = A().field
|
||||
|
||||
checkNoAccessors(A::class.java)
|
||||
checkNoAccessors(A.Companion::class.java)
|
||||
checkNoAccessors(Object::class.java)
|
||||
checkNoAccessors(Class.forName("CheckNoAccessorsKt"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
public fun checkNoAccessors(clazz: Class<*>) {
|
||||
clazz.declaredMethods.forEach {
|
||||
assertFalse(it.name.startsWith("get") || it.name.startsWith("set"),
|
||||
"Class ${clazz.name} has accessor '${it.name}'"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
package zzz
|
||||
import java.lang.reflect.Field
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A(val s1: String, val s2: String) {
|
||||
@JvmField public val publicField = s1;
|
||||
@JvmField internal val internalField = s2;
|
||||
|
||||
fun testAccessors() {
|
||||
checkAccessor(A::publicField, s1, this)
|
||||
checkAccessor(A::internalField, s2, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// TODO: uncomment when callable references to object members are supported
|
||||
class AWithCompanion {
|
||||
companion object {
|
||||
@JvmField public val publicField = "1";
|
||||
@JvmField internal val internalField = "2";
|
||||
|
||||
fun testAccessors() {
|
||||
checkAccessor(AWithCompanion.Companion::publicField, "1", AWithCompanion.Companion)
|
||||
checkAccessor(AWithCompanion.Companion::internalField, "2", AWithCompanion.Companion)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
fun box(): String {
|
||||
A("1", "2").testAccessors()
|
||||
// AWithCompanion.testAccessors()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
public fun <T, R> checkAccessor(prop: KProperty1<T, R>, value: R, receiver: T) {
|
||||
assertEquals(prop.get(receiver), value, "Property ${prop} has wrong value")
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
package zzz
|
||||
import java.lang.reflect.Field
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A(val s1: String, val s2: String) {
|
||||
@JvmField public var publicField = s1;
|
||||
@JvmField internal var internalField = s2;
|
||||
|
||||
fun testAccessors() {
|
||||
checkAccessor(A::class.members.firstOrNull { it.name == "publicField" } as KMutableProperty1<A, String>, s1, "3", this)
|
||||
checkAccessor(A::class.members.firstOrNull { it.name == "internalField" } as KMutableProperty1<A, String>, s2, "4", this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AWithCompanion {
|
||||
companion object {
|
||||
@JvmField public var publicField = "1";
|
||||
@JvmField internal var internalField = "2";
|
||||
|
||||
fun testAccessors() {
|
||||
checkAccessor(AWithCompanion.Companion::class.members.firstOrNull { it.name == "publicField" } as KMutableProperty1<AWithCompanion.Companion, String>, "1", "3", AWithCompanion.Companion)
|
||||
checkAccessor(AWithCompanion.Companion::class.members.firstOrNull { it.name == "internalField" } as KMutableProperty1<AWithCompanion.Companion, String>, "2", "4", AWithCompanion.Companion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A("1", "2").testAccessors()
|
||||
AWithCompanion.testAccessors()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
public fun <T, R> checkAccessor(prop: KMutableProperty1<T, R>, value: R, newValue: R, receiver: T) {
|
||||
assertEquals(prop.get(receiver), value, "Property ${prop} has wrong value")
|
||||
prop.set(receiver, newValue)
|
||||
assertEquals(prop.get(receiver), newValue, "Property ${prop} has wrong value")
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A {
|
||||
@JvmField public val field = "OK";
|
||||
|
||||
companion object {
|
||||
@JvmField public val cfield = "OK";
|
||||
}
|
||||
}
|
||||
|
||||
object Object {
|
||||
@JvmField public val field = "OK";
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
var result = A().field
|
||||
|
||||
if (result != "OK") return "fail 1: $result"
|
||||
if (A.cfield != "OK") return "fail 2: ${A.cfield}"
|
||||
if (Object.field != "OK") return "fail 3: ${Object.field}"
|
||||
|
||||
return "OK"
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
open class A {
|
||||
@JvmField public val publicField = "1";
|
||||
@JvmField internal val internalField = "2";
|
||||
@JvmField protected val protectedfield = "3";
|
||||
}
|
||||
|
||||
|
||||
class B : A() {
|
||||
fun test(): String {
|
||||
return super.publicField + super.internalField + super.protectedfield
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return if (B().test() == "123") return "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
open class A {
|
||||
@JvmField public val publicField = "1";
|
||||
@JvmField internal val internalField = "2";
|
||||
@JvmField protected val protectedfield = "3";
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
|
||||
}
|
||||
|
||||
open class C : B() {
|
||||
fun test(): String {
|
||||
return super.publicField + super.internalField + super.protectedfield
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return if (C().test() == "123") return "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
package zzz
|
||||
import java.lang.reflect.Field
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.reflect.KProperty0
|
||||
|
||||
@JvmField public val publicField = "1";
|
||||
@JvmField internal val internalField = "2";
|
||||
|
||||
fun testAccessors() {
|
||||
val kProperty: KProperty0<String> = ::publicField
|
||||
checkAccessor(kProperty, "1")
|
||||
checkAccessor(::internalField, "2")
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
testAccessors()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
public fun <T, R> checkAccessor(prop: KProperty0<T>, value: R) {
|
||||
assertEquals<Any?>(prop.get(), value, "Property ${prop} has wrong value")
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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")
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
|
||||
import java.lang.reflect.Field
|
||||
import kotlin.reflect.jvm.javaField
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.test.assertNotEquals
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
@JvmField public val publicField = "OK";
|
||||
@JvmField internal val internalField = "OK";
|
||||
|
||||
fun testVisibilities() {
|
||||
checkVisibility(::publicField.javaField!!, Modifier.PUBLIC)
|
||||
checkVisibility(::internalField.javaField!!, Modifier.PUBLIC)
|
||||
}
|
||||
|
||||
class A {
|
||||
@JvmField public val publicField = "OK";
|
||||
@JvmField internal val internalField = "OK";
|
||||
@JvmField protected val protectedfield = "OK";
|
||||
|
||||
fun testVisibilities() {
|
||||
checkVisibility(A::publicField.javaField!!, Modifier.PUBLIC)
|
||||
checkVisibility(A::internalField.javaField!!, Modifier.PUBLIC)
|
||||
checkVisibility(A::protectedfield.javaField!!, Modifier.PROTECTED)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AWithCompanion {
|
||||
companion object {
|
||||
@JvmField public val publicField = "OK";
|
||||
@JvmField internal val internalField = "OK";
|
||||
@JvmField protected val protectedfield = "OK";
|
||||
|
||||
operator fun get(name: String) = AWithCompanion.Companion::class.members.single { it.name == name } as KProperty<*>
|
||||
|
||||
fun testVisibilities() {
|
||||
checkVisibility(this["publicField"].javaField!!, Modifier.PUBLIC)
|
||||
checkVisibility(this["internalField"].javaField!!, Modifier.PUBLIC)
|
||||
checkVisibility(this["protectedfield"].javaField!!, Modifier.PROTECTED)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object Object {
|
||||
@JvmField public val publicField = "OK";
|
||||
@JvmField internal val internalField = "OK";
|
||||
|
||||
operator fun get(name: String) = Object::class.members.single { it.name == name } as KProperty<*>
|
||||
|
||||
fun testVisibilities() {
|
||||
checkVisibility(this["publicField"].javaField!!, Modifier.PUBLIC)
|
||||
checkVisibility(this["internalField"].javaField!!, Modifier.PUBLIC)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A().testVisibilities()
|
||||
AWithCompanion.testVisibilities()
|
||||
Object.testVisibilities()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
public fun checkVisibility(field: Field, visibility: Int) {
|
||||
assertNotEquals(field.modifiers and visibility, 0, "Field ${field} has wrong visibility")
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
package zzz
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A(val s1: String, val s2: String) {
|
||||
@JvmField public var publicField = s1;
|
||||
@JvmField internal var internalField = s2;
|
||||
|
||||
fun testAccessors() {
|
||||
val kMutableProperty: KMutableProperty1<A, String> = A::publicField
|
||||
checkAccessor(kMutableProperty, s1, "3", this)
|
||||
checkAccessor(A::internalField, s2, "4", this)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A("1", "2").testAccessors()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
public fun <T, R> checkAccessor(prop: KMutableProperty1<T, R>, value: R, newValue: R, receiver: T) {
|
||||
assertEquals(prop.get(receiver), value, "Property ${prop} has wrong value")
|
||||
prop.set(receiver, newValue)
|
||||
assertEquals(prop.get(receiver), newValue, "Property ${prop} has wrong value")
|
||||
}
|
||||
Reference in New Issue
Block a user