JS: create new common directory for all generated tests, migrate several tests there

This commit is contained in:
Alexey Andreev
2016-08-26 16:44:48 +03:00
parent 34a57f863b
commit 2bf0199959
321 changed files with 2123 additions and 2001 deletions
@@ -0,0 +1,12 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
abstract class Base {
val result = "OK"
}
class Derived : Base()
fun box(): String {
return (Base::result).get(Derived())
}
@@ -0,0 +1,27 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
import kotlin.reflect.KProperty
object NumberDecrypter {
operator fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
"four" -> 4
"two" -> 2
else -> throw Exception()
}
}
val four: Int by NumberDecrypter
class A {
val two: Int by NumberDecrypter
}
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"
}
@@ -0,0 +1,27 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
import kotlin.reflect.KProperty
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
}
}
var result: String by Delegate
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()
}
@@ -0,0 +1,41 @@
package foo
import kotlin.reflect.KMutableProperty1
open class A(var msg:String) {
}
class B:A("FromB") {
}
var global:String = ""
var A.ext:String
get() = ":A.ext ${this.msg}:"
set(value) { global = ":A.ext ${value}" }
var B.ext:String
get() = ":B.ext ${this.msg}:"
set(value) { global = ":B.ext ${value}" }
fun box(): String {
val a = A("Test")
var refAExt = A::ext
var refBExt: KMutableProperty1<B, String> = B::ext
assertEquals("ext", refAExt.name)
assertEquals("ext", refBExt.name)
assertEquals(":A.ext Test:", refAExt.get(a))
assertEquals(":B.ext FromB:", refBExt.get(B()))
refAExt.set(a, "newA")
assertEquals(":A.ext newA", global)
global = ""
refBExt.set(B(), "newB")
assertEquals(":B.ext newB", global)
return "OK"
}
@@ -0,0 +1,16 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
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())
}
@@ -0,0 +1,31 @@
package foo
open class A(var msg:String) {
open var prop:String = "initA"
}
class B:A("FromB") {
override var prop:String = "initB"
}
fun box(): String {
var refAProp = A::prop
var refBProp = B::prop
assertEquals("prop", refAProp.name)
assertEquals("prop", refBProp.name)
val a = A("Test")
assertEquals("initA", refAProp.get(a))
refAProp.set(a, "newPropA")
assertEquals("newPropA", a.prop)
val a1 = B()
assertEquals("initB", refAProp.get(a1))
refAProp.set(a1, "newPropB")
assertEquals("newPropB", a1.prop)
return "OK"
}
@@ -0,0 +1,12 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
open class Base {
open val foo = "Base"
}
class Derived : Base() {
override val foo = "OK"
}
fun box() = (Base::foo).get(Derived())
@@ -0,0 +1,15 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
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")
}
@@ -0,0 +1,12 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
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"
}
@@ -0,0 +1,21 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
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"
}
@@ -0,0 +1,19 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
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"
}
@@ -0,0 +1,15 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
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"
}
@@ -0,0 +1,13 @@
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
package foo
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"
}
@@ -0,0 +1,20 @@
package foo
var x = 1
val y = 2
fun box(): String {
var refX = ::x
assertEquals(1, refX.get())
assertEquals("x", refX.name)
refX.set(100)
assertEquals(100, x)
var refY = ::y
assertEquals(2, refY.get())
assertEquals("y", refY.name)
return "OK"
}