Inline test data structure changed
This commit is contained in:
committed by
Michael Bogdanov
parent
b37c0d3fff
commit
02c6bdeaa3
@@ -0,0 +1,19 @@
|
||||
import test.*
|
||||
|
||||
fun test1(s: Long): String {
|
||||
return doSmth(s)
|
||||
}
|
||||
|
||||
fun test2(s: Int): String {
|
||||
return doSmth2(s)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = test1(11.toLong())
|
||||
if (result != "11") return "fail1: ${result}"
|
||||
|
||||
result = test2(11)
|
||||
if (result != "11") return "fail2: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
inline fun <T> doSmth(a: T) : String {
|
||||
return {a.toString()}()
|
||||
}
|
||||
|
||||
inline fun <T> doSmth2(a: T) : String {
|
||||
return {{a.toString()}()}()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import test.*
|
||||
import java.util.*
|
||||
|
||||
fun test1(prefix: String): String {
|
||||
var result = "fail"
|
||||
mfun {
|
||||
concat("start") {
|
||||
if (it.startsWith(prefix)) {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1("start") != "OK") return "fail1"
|
||||
if (test1("nostart") != "fail") return "fail2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
inline fun <R> mfun(f: () -> R) {
|
||||
f()
|
||||
}
|
||||
|
||||
fun concat(suffix: String, l: (s: String) -> Unit) {
|
||||
l(suffix)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import test.*
|
||||
|
||||
fun test1(param: String): String {
|
||||
var result = "fail1"
|
||||
noInlineFun(param) { a ->
|
||||
concat("start") {
|
||||
result = doSmth(a).toString()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun test11(param: String): String {
|
||||
var result = "fail1"
|
||||
noInlineFun("stub") { a ->
|
||||
concat("start") {
|
||||
result = doSmth(param).toString()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
inline fun test2(param: () -> String): String {
|
||||
var result = "fail1"
|
||||
noInlineFun("stub") { a ->
|
||||
concat(param()) {
|
||||
result = doSmth(param()).toString()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
inline fun test22(param: () -> String): String {
|
||||
var result = "fail1"
|
||||
{{result = param()}()}()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (test1("start") != "start") return "fail1: ${test1("start")}"
|
||||
if (test1("nostart") != "nostart") return "fail2: ${test1("nostart")}"
|
||||
if (test11("start") != "start") return "fail3: ${test11("start")}"
|
||||
|
||||
if (test2({"start"}) != "start") return "fail4: ${test2({"start"})}"
|
||||
if (test22({"start"}) != "start") return "fail5: ${test22({"start"})}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package test
|
||||
|
||||
fun concat(suffix: String, l: (s: String) -> Unit) {
|
||||
l(suffix)
|
||||
}
|
||||
|
||||
fun <T> noInlineFun(arg: T, f: (T) -> Unit) {
|
||||
f(arg)
|
||||
}
|
||||
|
||||
inline fun doSmth(a: String): String {
|
||||
return a.toString()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import test.*
|
||||
|
||||
fun sameName(s: Long): Long {
|
||||
return call {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
fun sameName(s: Int): Int {
|
||||
return call {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = sameName(1.toLong())
|
||||
if (result != 1.toLong()) return "fail1: ${result}"
|
||||
|
||||
val result2 = sameName(2)
|
||||
if (result2 != 2) return "fail2: ${result2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
inline fun <R> call(f: () -> R) : R {
|
||||
return {f()} ()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import test.*
|
||||
|
||||
fun testSameCaptured() : String {
|
||||
var result = 0;
|
||||
result = doWork({result+=1; result}, {result += 11; result})
|
||||
return if (result == 12) "OK" else "fail ${result}"
|
||||
}
|
||||
|
||||
inline fun testSameCaptured(lambdaWithResultCaptured: () -> Unit) : String {
|
||||
var result = 1;
|
||||
result = doWork({result+=11; lambdaWithResultCaptured(); result})
|
||||
return if (result == 12) "OK" else "fail ${result}"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (testSameCaptured() != "OK") return "test1 : ${testSameCaptured()}"
|
||||
|
||||
var result = 0;
|
||||
if (testSameCaptured{result += 1111} != "OK") return "test2 : ${testSameCaptured{result = 1111}}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package test
|
||||
|
||||
inline fun <R> doWork(job: ()-> R) : R {
|
||||
val k = 10;
|
||||
return notInline({k; job()})
|
||||
}
|
||||
|
||||
inline fun <R> doWork(job: ()-> R, job2: () -> R) : R {
|
||||
val k = 10;
|
||||
return notInline({k; job(); job2()})
|
||||
}
|
||||
|
||||
fun <R> notInline(job: ()-> R) : R {
|
||||
return job()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user