Inline test data structure changed
This commit is contained in:
committed by
Michael Bogdanov
parent
b37c0d3fff
commit
02c6bdeaa3
@@ -0,0 +1,11 @@
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
val result = doWork({11})
|
||||
if (result != 11) return "test1: ${result}"
|
||||
|
||||
val result2 = doWork({12; result+1})
|
||||
if (result2 != 12) return "test2: ${result2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package test
|
||||
|
||||
inline fun <R> doWork(job: ()-> R) : R {
|
||||
return notInline({job()})
|
||||
}
|
||||
|
||||
fun <R> notInline(job: ()-> R) : R {
|
||||
return job()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
val result = doWork({11})
|
||||
if (result != 11) return "test1: ${result}"
|
||||
|
||||
val result2 = doWork({12; result+1})
|
||||
if (result2 != 12) return "test2: ${result2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
inline fun <R> doWork(job: ()-> R) : R {
|
||||
val k = 10;
|
||||
return notInline({k; job()})
|
||||
}
|
||||
|
||||
fun <R> notInline(job: ()-> R) : R {
|
||||
return job()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
fun test1() : Int {
|
||||
val inlineX = My(111)
|
||||
|
||||
return inlineX.perform<My, Int>{
|
||||
|
||||
val outX = My(1111111)
|
||||
outX.perform<My, Int>(
|
||||
{inlineX.value}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun My.execute(): Int {
|
||||
return perform { this.value }
|
||||
}
|
||||
|
||||
fun test2(): Int {
|
||||
val inlineX = My(11)
|
||||
|
||||
return inlineX.execute()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != 111) return "test1: ${test1()}"
|
||||
if (test2() != 11) return "test2: ${test2()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class My(val value: Int)
|
||||
|
||||
inline fun <T, R> T.perform(job: (T)-> R) : R {
|
||||
return job(this)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import test.*
|
||||
|
||||
fun test1(s: Long): String {
|
||||
var result = "OK"
|
||||
result = mfun(s) { a ->
|
||||
result + doSmth(s) + doSmth(a)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = test1(11.toLong())
|
||||
if (result != "OK1111") return "fail1: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
inline fun <T, R> mfun(arg: T, f: (T) -> R) : R {
|
||||
return f(arg)
|
||||
}
|
||||
|
||||
inline fun <T> doSmth(a: T): String {
|
||||
return a.toString()
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
fun testAll(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
return inlineX.inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVal(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
val c1 = 21
|
||||
val c2 = 22.0
|
||||
val c3 = 23.0
|
||||
val c4 = "24"
|
||||
val c5 = 25.toLong()
|
||||
val c6 = 'H'
|
||||
val c7 = 26.toByte()
|
||||
val c8 = 27.toShort()
|
||||
val c9 = 28.toFloat()
|
||||
|
||||
return inlineX.inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVar(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
var c1 = 21
|
||||
var c2 = 22.0
|
||||
var c3 = 23.0
|
||||
var c4 = "24"
|
||||
var c5 = 25.toLong()
|
||||
var c6 = 'H'
|
||||
var c7 = 26.toByte()
|
||||
var c8 = 27.toShort()
|
||||
val c9 = 28.toFloat()
|
||||
|
||||
return inlineX.inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedValAndVar(): String {
|
||||
val inlineX = InlineAll()
|
||||
|
||||
var c1 = 21
|
||||
var c2 = 22.0
|
||||
val c3 = 23.0
|
||||
val c4 = "24"
|
||||
var c5 = 25.toLong()
|
||||
val c6 = 'H'
|
||||
var c7 = 26.toByte()
|
||||
var c8 = 27.toShort()
|
||||
val c9 = 28.toFloat()
|
||||
|
||||
return inlineX.inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (testAll() != "112.013.01415") return "testAll: ${testAll()}"
|
||||
if (testAllWithCapturedVal() != "112.013.014152122.023.02425H262728.0") return "testAllWithCapturedVal: ${testAllWithCapturedVal()}"
|
||||
if (testAllWithCapturedVar() != "112.013.014152122.023.02425H262728.0") return "testAllWithCapturedVar: ${testAllWithCapturedVar()}"
|
||||
if (testAllWithCapturedValAndVar() != "112.013.014152122.023.02425H262728.0") return "testAllWithCapturedVal: ${testAllWithCapturedValAndVar()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class InlineAll {
|
||||
|
||||
inline fun inline(s: (Int, Double, Double, String, Long) -> String,
|
||||
a1: Int, a2: Double, a3: Double, a4: String, a5: Long): String {
|
||||
return s(a1, a2, a3, a4, a5)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
fun testAll(): String {
|
||||
return inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVal(): String {
|
||||
val c1 = 21
|
||||
val c2 = 22.0
|
||||
val c3 = 23.0
|
||||
val c4 = "24"
|
||||
val c5 = 25.toLong()
|
||||
val c6 = 'H'
|
||||
val c7 = 26.toByte()
|
||||
val c8 = 27.toShort()
|
||||
val c9 = 28.toFloat()
|
||||
|
||||
return inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedVar(): String {
|
||||
var c1 = 21
|
||||
var c2 = 22.0
|
||||
var c3 = 23.0
|
||||
var c4 = "24"
|
||||
var c5 = 25.toLong()
|
||||
var c6 = 'H'
|
||||
var c7 = 26.toByte()
|
||||
var c8 = 27.toShort()
|
||||
val c9 = 28.toFloat()
|
||||
|
||||
return inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
fun testAllWithCapturedValAndVar(): String {
|
||||
var c1 = 21
|
||||
var c2 = 22.0
|
||||
val c3 = 23.0
|
||||
val c4 = "24"
|
||||
var c5 = 25.toLong()
|
||||
val c6 = 'H'
|
||||
var c7 = 26.toByte()
|
||||
var c8 = 27.toShort()
|
||||
val c9 = 28.toFloat()
|
||||
|
||||
return inline({(a1: Int, a2: Double, a3: Double, a4: String, a5: Long) ->
|
||||
"" + a1 + a2 + a3 + a4 + a5 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9},
|
||||
1, 12.0, 13.0, "14", 15)
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (testAll() != "112.013.01415") return "testAll: ${testAll()}"
|
||||
if (testAllWithCapturedVal() != "112.013.014152122.023.02425H262728.0") return "testAllWithCapturedVal: ${testAllWithCapturedVal()}"
|
||||
if (testAllWithCapturedVar() != "112.013.014152122.023.02425H262728.0") return "testAllWithCapturedVar: ${testAllWithCapturedVar()}"
|
||||
if (testAllWithCapturedValAndVar() != "112.013.014152122.023.02425H262728.0") return "testAllWithCapturedVal: ${testAllWithCapturedValAndVar()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
inline fun inline(s: (Int, Double, Double, String, Long) -> String,
|
||||
a1: Int, a2: Double, a3: Double, a4: String, a5: Long): String {
|
||||
return s(a1, a2, a3, a4, a5)
|
||||
}
|
||||
Reference in New Issue
Block a user