[K/N][Tests] Adjust moved codegen tests to new infra
^KT-61259
This commit is contained in:
committed by
Space Team
parent
71a834b778
commit
73032213f0
@@ -3,16 +3,24 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.lazy
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
val lazyValue: String by lazy {
|
||||
println("computed!")
|
||||
sb.appendLine("computed!")
|
||||
"Hello"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(lazyValue)
|
||||
println(lazyValue)
|
||||
fun box(): String {
|
||||
sb.appendLine(lazyValue)
|
||||
sb.appendLine(lazyValue)
|
||||
|
||||
assertEquals("""
|
||||
computed!
|
||||
Hello
|
||||
Hello
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
computed!
|
||||
Hello
|
||||
Hello
|
||||
@@ -3,16 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.local
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun foo(): Int {
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
sb.appendLine(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
@@ -22,6 +21,13 @@ fun foo(): Int {
|
||||
return x
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(foo())
|
||||
fun box(): String {
|
||||
sb.appendLine(foo())
|
||||
|
||||
assertEquals("""
|
||||
x
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
x
|
||||
42
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.map
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class User(val map: Map<String, Any?>) {
|
||||
@@ -12,11 +10,13 @@ class User(val map: Map<String, Any?>) {
|
||||
val age: Int by map
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val user = User(mapOf(
|
||||
"name" to "John Doe",
|
||||
"age" to 25
|
||||
))
|
||||
println(user.name) // Prints "John Doe"
|
||||
println(user.age) // Prints 25
|
||||
assertEquals("John Doe", user.name)
|
||||
assertEquals(25, user.age)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
John Doe
|
||||
25
|
||||
@@ -3,21 +3,28 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.observable
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class User {
|
||||
var name: String by Delegates.observable("<no name>") {
|
||||
prop, old, new ->
|
||||
println("$old -> $new")
|
||||
sb.appendLine("$old -> $new")
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val user = User()
|
||||
user.name = "first"
|
||||
user.name = "second"
|
||||
|
||||
assertEquals("""
|
||||
<no name> -> first
|
||||
first -> second
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
<no name> -> first
|
||||
first -> second
|
||||
@@ -3,21 +3,28 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.packageLevel
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
sb.appendLine(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
val x: Int by Delegate()
|
||||
|
||||
@Test fun runTest() {
|
||||
println(x)
|
||||
fun box(): String {
|
||||
sb.appendLine(x)
|
||||
|
||||
assertEquals("""
|
||||
x
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
x
|
||||
42
|
||||
@@ -3,15 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.simpleVal
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
sb.appendLine(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,13 @@ class C {
|
||||
val x: Int by Delegate()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(C().x)
|
||||
fun box(): String {
|
||||
sb.appendLine(C().x)
|
||||
|
||||
assertEquals("""
|
||||
x
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
x
|
||||
42
|
||||
@@ -3,22 +3,22 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.simpleVar
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class Delegate {
|
||||
var f: Int = 42
|
||||
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println("get ${p.name}")
|
||||
sb.appendLine("get ${p.name}")
|
||||
return f
|
||||
}
|
||||
|
||||
operator fun setValue(receiver: Any?, p: KProperty<*>, value: Int) {
|
||||
println("set ${p.name}")
|
||||
sb.appendLine("set ${p.name}")
|
||||
f = value
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,19 @@ class C {
|
||||
var x: Int by Delegate()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
println(c.x)
|
||||
sb.appendLine(c.x)
|
||||
c.x = 117
|
||||
println(c.x)
|
||||
sb.appendLine(c.x)
|
||||
|
||||
assertEquals("""
|
||||
get x
|
||||
42
|
||||
set x
|
||||
get x
|
||||
117
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
get x
|
||||
42
|
||||
set x
|
||||
get x
|
||||
117
|
||||
Reference in New Issue
Block a user