Move some tests from boxWithStdlib/ to box/

Move those tests which do not require neither stdlib nor reflect
This commit is contained in:
Alexander Udalov
2016-03-05 18:39:20 +03:00
committed by Alexander Udalov
parent 54a615fcd3
commit 20e36438e2
217 changed files with 1561 additions and 1397 deletions
@@ -1,9 +0,0 @@
abstract class A {
abstract fun foo(): String
}
class B : A() {
override fun foo() = "OK"
}
fun box(): String = (A::foo)(B())
@@ -1,5 +0,0 @@
fun box(): String {
if ((Boolean::not)(true) != false) return "Fail 1"
if ((Boolean::not)(false) != true) return "Fail 2"
return "OK"
}
@@ -1,11 +0,0 @@
class A {
fun foo(k: Int) = k
fun result() = (A::foo)(this, 111)
}
fun box(): String {
val result = A().result()
if (result != 111) return "Fail $result"
return "OK"
}
@@ -1,12 +0,0 @@
class A {
fun o() = 111
fun k(k: Int) = k
}
fun A.foo() = (A::o)(this) + (A::k)(this, 222)
fun box(): String {
val result = A().foo()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,8 +0,0 @@
class A {
fun foo() = "OK"
}
fun box(): String {
val x = A::foo
return x(A())
}
@@ -1,8 +0,0 @@
class A {
fun foo(result: String) = result
}
fun box(): String {
val x = A::foo
return x(A(), "OK")
}
@@ -1,14 +0,0 @@
class A {
var result = "Fail"
fun foo() {
result = "OK"
}
}
fun box(): String {
val a = A()
val x = A::foo
x(a)
return a.result
}
@@ -1,14 +0,0 @@
class A {
var result = "Fail"
fun foo(newResult: String) {
result = newResult
}
}
fun box(): String {
val a = A()
val x = A::foo
x(a, "OK")
return a.result
}
@@ -1,5 +0,0 @@
class A {
var result = "OK"
}
fun box() = (::A)().result
@@ -1,3 +0,0 @@
class A(val result: String)
fun box() = (::A)("OK").result
@@ -1,9 +0,0 @@
enum class E {
ENTRY
}
fun box(): String {
val f = E::valueOf
val result = f("ENTRY")
return if (result == E.ENTRY) "OK" else "Fail $result"
}
@@ -1,3 +0,0 @@
class A
fun box() = if ((A::equals)(A(), A())) "Fail" else "OK"
@@ -1,7 +0,0 @@
class A {
fun result() = (A::foo)(this, "OK")
}
fun A.foo(x: String) = x
fun box() = A().result()
@@ -1,7 +0,0 @@
class A
fun A.foo() = (A::bar)(this, "OK")
fun A.bar(x: String) = x
fun box() = A().foo()
@@ -1,8 +0,0 @@
class A
fun A.foo() = "OK"
fun box(): String {
val x = A::foo
return x(A())
}
@@ -1,8 +0,0 @@
class A
fun A.foo(result: String) = result
fun box(): String {
val x = A::foo
return x(A(), "OK")
}
@@ -1,14 +0,0 @@
class A {
var result = "Fail"
}
fun A.foo() {
result = "OK"
}
fun box(): String {
val a = A()
val x = A::foo
x(a)
return a.result
}
@@ -1,14 +0,0 @@
class A {
var result = "Fail"
}
fun A.foo(newResult: String) {
result = newResult
}
fun box(): String {
val a = A()
val x = A::foo
x(a, "OK")
return a.result
}
@@ -1,5 +0,0 @@
class A<T>(val t: T) {
fun foo(): T = t
}
fun box() = (A<String>::foo)(A("OK"))
@@ -1,14 +0,0 @@
class A {
inner class Inner {
val o = 111
val k = 222
}
fun result() = (A::Inner)(this).o + (A::Inner)(this).k
}
fun box(): String {
val result = A().result()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,14 +0,0 @@
class A {
inner class Inner {
val o = 111
val k = 222
}
}
fun A.foo() = (A::Inner)(this).o + (A::Inner)(this).k
fun box(): String {
val result = A().foo()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,12 +0,0 @@
class A {
inner class Inner {
val o = 111
val k = 222
}
}
fun box(): String {
val result = (A::Inner)((::A)()).o + (A::Inner)(A()).k
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,9 +0,0 @@
class A {
inner class Inner(val result: Int)
}
fun box(): String {
val result = (A::Inner)((::A)(), 111).result + (A::Inner)(A(), 222).result
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,13 +0,0 @@
// KT-5123
import java.util.Collections
import java.util.ArrayList
fun box(): String {
val numbers = ArrayList<Int>()
numbers.add(1)
numbers.add(2)
numbers.add(3)
(Collections::rotate)(numbers, 1)
return if ("$numbers" == "[3, 1, 2]") "OK" else "Fail $numbers"
}
@@ -1,12 +0,0 @@
class Outer {
val result = "OK"
inner class Inner {
fun foo() = result
}
}
fun box(): String {
val f = Outer.Inner::foo
return f(Outer().Inner())
}
@@ -1,8 +0,0 @@
fun box(): String {
class Local {
fun foo() = "OK"
}
val ref = Local::foo
return ref(Local())
}
@@ -1,9 +0,0 @@
fun box(): String {
var result = "Fail"
fun changeToOK() { result = "OK" }
val ok = ::changeToOK
ok()
return result
}
@@ -1,7 +0,0 @@
fun box(): String {
class A {
val result = "OK"
}
return (::A)().result
}
@@ -1,10 +0,0 @@
fun box(): String {
class A {
var result: String = "Fail";
init {
result = "OK"
}
}
return (::A)().result
}
@@ -1,11 +0,0 @@
interface Named {
val name: String
}
enum class E : Named {
OK
}
fun box(): String {
return E.OK.name
}
@@ -1,6 +0,0 @@
class A
fun box(): String {
fun A.foo() = "OK"
return (A::foo)(A())
}
@@ -1,5 +0,0 @@
fun box(): String {
class A
fun A.foo() = "OK"
return (A::foo)((::A)())
}
@@ -1,4 +0,0 @@
fun box(): String {
fun Int.is42With(that: Int) = this + 2 * that == 42
return if ((Int::is42With)(16, 13)) "OK" else "Fail"
}
@@ -1,11 +0,0 @@
class A
fun box(): String {
var result = "Fail"
fun A.ext() { result = "OK" }
val f = A::ext
f(A())
return result
}
@@ -1,8 +0,0 @@
fun box(): String {
class Id<T> {
fun invoke(t: T) = t
}
val ref = Id<String>::invoke
return ref(Id<String>(), "OK")
}
@@ -1,11 +0,0 @@
fun box(): String {
val result = "OK"
class Local {
fun foo() = result
}
val member = Local::foo
val instance = Local()
return member(instance)
}
@@ -1,10 +0,0 @@
fun box(): String {
fun foo(): String {
fun bar() = "OK"
val ref = ::bar
return ref()
}
val ref = ::foo
return ref()
}
@@ -1,7 +0,0 @@
fun foo(until: Int): String {
fun bar(x: Int): String =
if (x == until) "OK" else bar(x + 1)
return (::bar)(0)
}
fun box() = foo(10)
@@ -1,4 +0,0 @@
fun box(): String {
fun foo() = "OK"
return (::foo)()
}
@@ -1,7 +0,0 @@
fun box(): String {
val result = "OK"
fun foo() = result
return (::foo)()
}
@@ -1,4 +0,0 @@
fun box(): String {
fun foo(s: String) = s
return (::foo)("OK")
}
@@ -1,15 +0,0 @@
var state = 23
fun box(): String {
fun incrementState(inc: Int) {
state += inc
}
val inc = ::incrementState
inc(12)
inc(-5)
inc(27)
inc(-15)
return if (state == 42) "OK" else "Fail $state"
}
@@ -1,14 +0,0 @@
class A {
class Nested {
val o = 111
val k = 222
}
fun result() = (::Nested)().o + (A::Nested)().k
}
fun box(): String {
val result = A().result()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,7 +0,0 @@
class A {
class Nested {
val result = "OK"
}
}
fun box() = (A::Nested)().result
@@ -1,5 +0,0 @@
class A {
class Nested(val result: String)
}
fun box() = (A::Nested)("OK").result
@@ -1,13 +0,0 @@
private fun <T> upcast(value: T): T = value
fun box(): String {
upcast<(Int)->ByteArray>(::ByteArray)(10)
upcast<(Int)->IntArray>(::IntArray)(10)
upcast<(Int)->ShortArray>(::ShortArray)(10)
upcast<(Int)->LongArray>(::LongArray)(10)
upcast<(Int)->DoubleArray>(::DoubleArray)(10)
upcast<(Int)->FloatArray>(::FloatArray)(10)
upcast<(Int)->BooleanArray>(::BooleanArray)(10)
return "OK"
}
@@ -1,22 +0,0 @@
import kotlin.test.assertEquals
fun foo(): String = "foo1"
fun foo(i: Int): String = "foo2"
val f1: () -> String = ::foo
val f2: (Int) -> String = ::foo
fun foo1() {}
fun foo2(i: Int) {}
fun bar(f: () -> Unit): String = "bar1"
fun bar(f: (Int) -> Unit): String = "bar2"
fun box(): String {
assertEquals("foo1", f1())
assertEquals("foo2", f2(0))
assertEquals("bar1", bar(::foo1))
assertEquals("bar2", bar(::foo2))
return "OK"
}
@@ -1,19 +0,0 @@
import kotlin.reflect.*
import kotlin.test.assertEquals
class A {
val x = 1
fun x(): String = "OK"
}
val f1: KProperty1<A, Int> = A::x
val f2: (A) -> String = A::x
fun box(): String {
val a = A()
assertEquals(1, f1.get(a))
assertEquals("OK", f2(a))
return "OK"
}
@@ -1,7 +0,0 @@
class A {
private fun foo() = "OK"
fun bar() = (A::foo)(this)
}
fun box() = A().bar()
@@ -1,19 +0,0 @@
import java.util.ArrayList
import java.util.Arrays
import java.util.Collections
import java.util.Comparator
fun sort(list: MutableList<String>, comparator: (String, String) -> Int) {
Collections.sort(list, object : Comparator<String> {
override fun compare(p0: String, p1: String) = comparator(p0, p1)
})
}
fun compare(s1: String, s2: String) = s1.compareTo(s2)
fun box(): String {
val l = ArrayList(Arrays.asList("d", "b", "c", "e", "a"))
sort(l, ::compare)
if (l != Arrays.asList("a", "b", "c", "d", "e")) return "Fail: $l"
return "OK"
}
@@ -1,11 +0,0 @@
fun foo(o: Int, k: Int) = o + k
class A {
fun bar() = (::foo)(111, 222)
}
fun box(): String {
val result = A().bar()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,11 +0,0 @@
fun foo(o: Int, k: Int) = o + k
class A
fun A.bar() = (::foo)(111, 222)
fun box(): String {
val result = A().bar()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -1,6 +0,0 @@
fun foo() = "OK"
fun box(): String {
val x = ::foo
return x()
}
@@ -1,6 +0,0 @@
fun foo(x: String) = x
fun box(): String {
val x = ::foo
return x("OK")
}
@@ -1,11 +0,0 @@
var result = "Fail"
fun foo() {
result = "OK"
}
fun box(): String {
val x = ::foo
x()
return result
}
@@ -1,11 +0,0 @@
var result = "Fail"
fun foo(newResult: String) {
result = newResult
}
fun box(): String {
val x = ::foo
x("OK")
return result
}
@@ -1,11 +0,0 @@
interface T {
fun foo() = "OK"
}
class B : T {
inner class C {
fun bar() = (T::foo)(this@B)
}
}
fun box() = B().C().bar()
@@ -1,9 +0,0 @@
interface A {
fun foo(): String
}
class B : A {
override fun foo() = "OK"
}
fun box() = (A::foo)(B())
@@ -1,9 +0,0 @@
abstract class Base {
val result = "OK"
}
class Derived : Base()
fun box(): String {
return (Base::result).get(Derived())
}
@@ -1,24 +0,0 @@
import kotlin.reflect.KProperty
val four: Int by NumberDecrypter
class A {
val two: Int by NumberDecrypter
}
object NumberDecrypter {
operator fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
"four" -> 4
"two" -> 2
else -> throw AssertionError()
}
}
fun box(): String {
val x = ::four.get()
if (x != 4) return "Fail x: $x"
val a = A()
val y = A::two.get(a)
if (y != 2) return "Fail y: $y"
return "OK"
}
@@ -1,24 +0,0 @@
import kotlin.reflect.KProperty
var result: String by Delegate
object Delegate {
var value = "lol"
operator fun getValue(instance: Any?, data: KProperty<*>): String {
return value
}
operator fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
value = newValue
}
}
fun box(): String {
val f = ::result
if (f.get() != "lol") return "Fail 1: {$f.get()}"
Delegate.value = "rofl"
if (f.get() != "rofl") return "Fail 2: {$f.get()}"
f.set("OK")
return f.get()
}
@@ -1,11 +0,0 @@
enum class E {
I
}
fun box(): String {
val i = (E::name).get(E.I)
if (i != "I") return "Fail $i"
val n = (E::ordinal).get(E.I)
if (n != 0) return "Fail $n"
return "OK"
}
@@ -1,6 +0,0 @@
val Array<String>.firstElement: String get() = get(0)
fun box(): String {
val p = Array<String>::firstElement
return p.get(arrayOf("OK", "Fail"))
}
@@ -1,21 +0,0 @@
//For KT-6020
import kotlin.reflect.KProperty1
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty
class Value<T>(var value: T = null as T, var text: String? = null)
val <T> Value<T>.additionalText by DVal(Value<T>::text) //works
val <T> Value<T>.additionalValue by DVal(Value<T>::value) //not work
class DVal<T, R, P: KProperty1<T, R>>(val kmember: P) {
operator fun getValue(t: T, p: KProperty<*>): R {
return kmember.get(t)
}
}
fun box(): String {
val p = Value("O", "K")
return p.additionalValue + p.additionalText
}
@@ -1,31 +0,0 @@
var state = ""
var topLevel: Int
get() {
state += "1"
return 42
}
set(value) {
throw AssertionError("Nooo")
}
class A {
val member: String
get() {
state += "2"
return "42"
}
}
val A.ext: Any
get() {
state += "3"
return this
}
fun box(): String {
(::topLevel)()
(A::member)(A())
(A::ext)(A())
return if (state == "123") "OK" else "Fail $state"
}
@@ -1,14 +0,0 @@
// Name of the getter should be 'getaBcde' according to JavaBean conventions
var aBcde: Int = 239
fun box(): String {
val x = (::aBcde).get()
if (x != 239) return "Fail x: $x"
(::aBcde).set(42)
val y = (::aBcde).get()
if (y != 42) return "Fail y: $y"
return "OK"
}
@@ -1,13 +0,0 @@
import kotlin.reflect.KProperty1
class A {
companion object {
val ref: KProperty1<A, String> = A::foo
}
val foo: String = "OK"
}
fun box(): String {
return A.ref.get(A())
}
@@ -1,22 +0,0 @@
class Test {
private var iv = 1
public fun exec() {
val t = object : Thread() {
override fun run() {
Test::iv.get(this@Test)
Test::iv.set(this@Test, 2)
}
}
t.start()
t.join(1000)
}
fun result() = if (iv == 2) "OK" else "Fail $iv"
}
fun box(): String {
val t = Test()
t.exec()
return t.result()
}
@@ -1,9 +0,0 @@
fun box(): String {
class Local {
var result = "Fail"
}
val l = Local()
(Local::result).set(l, "OK")
return (Local::result).get(l)
}
@@ -1,9 +0,0 @@
open class Base {
open val foo = "Base"
}
class Derived : Base() {
override val foo = "OK"
}
fun box() = (Base::foo).get(Derived())
@@ -1,23 +0,0 @@
import kotlin.reflect.jvm.*
var state: String = "value"
@JvmName("getter")
get
@JvmName("setter")
set
fun box(): String {
val p = ::state
if (p.name != "state") return "Fail name: ${p.name}"
if (p.get() != "value") return "Fail get: ${p.get()}"
p.set("OK")
val getterName = p.javaGetter!!.getName()
if (getterName != "getter") return "Fail getter name: $getterName"
val setterName = p.javaSetter!!.getName()
if (setterName != "setter") return "Fail setter name: $setterName"
return p.get()
}
@@ -1,12 +0,0 @@
import kotlin.reflect.jvm.accessible
class Result {
public val value: String = "OK"
}
fun box(): String {
val p = Result::value
p.accessible = false
// setAccessible(false) should have no effect on the accessibility of a public reflection object
return p.get(Result())
}
@@ -1,12 +0,0 @@
val String.id: String
get() = this
fun box(): String {
val pr = String::id
if (pr.get("123") != "123") return "Fail value: ${pr.get("123")}"
if (pr.name != "id") return "Fail name: ${pr.name}"
return pr.get("OK")
}
@@ -1,9 +0,0 @@
class A(val x: Int)
fun box(): String {
val p = A::x
if (p.get(A(42)) != 42) return "Fail 1"
if (p.get(A(-1)) != -1) return "Fail 2"
if (p.name != "x") return "Fail 3"
return "OK"
}
@@ -1,18 +0,0 @@
var storage = 0
var Int.foo: Int
get() {
return this + storage
}
set(value) {
storage = this + value
}
fun box(): String {
val pr = Int::foo
if (pr.get(42) != 42) return "Fail 1: ${pr.get(42)}"
pr.set(200, 39)
if (pr.get(-239) != 0) return "Fail 2: ${pr.get(-239)}"
if (storage != 239) return "Fail 3: $storage"
return "OK"
}
@@ -1,16 +0,0 @@
data class Box(var value: String)
fun box(): String {
val o = Box("lorem")
val prop = Box::value
if (prop.get(o) != "lorem") return "Fail 1: ${prop.get(o)}"
prop.set(o, "ipsum")
if (prop.get(o) != "ipsum") return "Fail 2: ${prop.get(o)}"
if (o.value != "ipsum") return "Fail 3: ${o.value}"
o.value = "dolor"
if (prop.get(o) != "dolor") return "Fail 4: ${prop.get(o)}"
if ("$o" != "Box(value=dolor)") return "Fail 5: $o"
return "OK"
}
@@ -1,12 +0,0 @@
data class Box(val value: String)
var pr = Box("first")
fun box(): String {
val property = ::pr
if (property.get() != Box("first")) return "Fail value: ${property.get()}"
if (property.name != "pr") return "Fail name: ${property.name}"
property.set(Box("second"))
if (property.get().value != "second") return "Fail value 2: ${property.get()}"
return "OK"
}
@@ -1,10 +0,0 @@
data class Box(val value: String)
val foo = Box("lol")
fun box(): String {
val property = ::foo
if (property.get() != Box("lol")) return "Fail value: ${property.get()}"
if (property.name != "foo") return "Fail name: ${property.name}"
return "OK"
}