Inline test data structure changed
This commit is contained in:
committed by
Michael Bogdanov
parent
b37c0d3fff
commit
02c6bdeaa3
@@ -0,0 +1,60 @@
|
||||
import test.*
|
||||
|
||||
fun test1(param: String): String {
|
||||
var result = "fail"
|
||||
inlineFun("1") { c ->
|
||||
{
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun test2(param: String): String {
|
||||
var result = "fail"
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
{
|
||||
result = param + a
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun test3(param: String): String {
|
||||
var result = "fail"
|
||||
inlineFun("2") { d ->
|
||||
inlineFun("1") { c ->
|
||||
{
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (test1("start") != "start12") return "fail1: ${test1("start")}"
|
||||
if (test2("start") != "start2") return "fail2: ${test2("start")}"
|
||||
if (test3("start") != "start12") return "fail3: ${test3("start")}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
inline fun <T> inlineFun(arg: T, f: (T) -> Unit) {
|
||||
f(arg)
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import test.*
|
||||
|
||||
inline fun test1(param: () -> String): String {
|
||||
var result = "fail"
|
||||
inlineFun("1") { c ->
|
||||
{
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
{
|
||||
result = param() + c + a
|
||||
}()
|
||||
}()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
inline fun test2(param: () -> String): String {
|
||||
var result = "fail"
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
{
|
||||
result = param() + a
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
inline fun test3(param: () -> String): String {
|
||||
var result = "fail"
|
||||
inlineFun("2") { d ->
|
||||
inlineFun("1") { c ->
|
||||
{
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
{
|
||||
result = param() + c + a
|
||||
}()
|
||||
}()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (test1({"start"}) != "start12") return "fail1: ${test1({"start"})}"
|
||||
if (test2({"start"}) != "start2") return "fail2: ${test2({"start"})}"
|
||||
if (test3({"start"}) != "start12") return "fail3: ${test3({"start"})}"
|
||||
|
||||
var captured1 = "sta";
|
||||
val captured2 = "rt";
|
||||
if (test1({captured1 + captured2}) != "start12") return "fail4: ${test1({captured1 + captured2})}"
|
||||
if (test2({captured1 + captured2}) != "start2") return "fail5: ${test2({captured1 + captured2})}"
|
||||
if (test3({captured1 + captured2}) != "start12") return "fail6: ${test3({captured1 + captured2})}"
|
||||
|
||||
return {
|
||||
if (test1 { captured1 + captured2 } != "start12") "fail7: ${test1 { captured1 + captured2 }}"
|
||||
else if (test2 { captured1 + captured2 } != "start2") "fail8: ${test2 { captured1 + captured2 }}"
|
||||
else if (test3 { captured1 + captured2 } != "start12") "fail9: ${test3 { captured1 + captured2 }}"
|
||||
else "OK"
|
||||
} ()
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
inline fun <T> inlineFun(arg: T, f: (T) -> Unit) {
|
||||
f(arg)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun test1(): Int {
|
||||
val inlineX = Inline()
|
||||
var p = {(l : Int) -> l};
|
||||
return inlineX.calc(p, 25)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != 25) return "test1: ${test1()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Inline {
|
||||
|
||||
inline fun calc(s: (Int) -> Int, p: Int) : Int {
|
||||
return s(p)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user