Inline test data structure changed

This commit is contained in:
Mikhael Bogdanov
2014-06-04 15:47:20 +04:00
committed by Michael Bogdanov
parent b37c0d3fff
commit 02c6bdeaa3
115 changed files with 765 additions and 519 deletions
@@ -0,0 +1,21 @@
import test.*
fun testClassObjectCall(): String {
return InlineAll.inline({"classobject"})
}
fun testInstanceCall(): String {
val inlineX = InlineAll()
return inlineX.inline({"instance"})
}
fun testPackageCall(): String {
return inline({"package"})
}
fun box(): String {
if (testClassObjectCall() != "classobject") return "test1: ${testClassObjectCall()}"
if (testInstanceCall() != "instance") return "test2: ${testInstanceCall()}"
if (testPackageCall() != "package") return "test3: ${testPackageCall()}"
return "OK"
}
@@ -0,0 +1,18 @@
package test
inline fun inline(s: () -> String): String {
return s()
}
class InlineAll {
inline fun inline(s: () -> String): String {
return s()
}
class object {
inline fun inline(s: () -> String): String {
return s()
}
}
}
@@ -0,0 +1,37 @@
fun test1(): Int {
val inlineX = Inline(9)
return inlineX.calcExt({(z: Int) -> z}, 25)
}
fun test2(): Int {
val inlineX = Inline(9)
return inlineX.calcExt2({Int.() -> this}, 25)
}
fun test3(): Int {
val inlineX = Inline(9)
return inlineX.doWork(InlineX(11))
}
fun test4(): Double {
val inlineX = Inline(9)
return inlineX.doWorkWithDouble(11.0)
}
fun test5(): Double {
val inlineX = Inline(9)
with(inlineX) {
11.0.calcDouble{(a: Int, b: Double) -> a + b}
}
return inlineX.doWorkWithDouble(11.0)
}
fun box(): String {
if (test1() != 25) return "test1: ${test1()}"
if (test2() != 25) return "test2: ${test2()}"
if (test3() != 20) return "test3: ${test3()}"
if (test4() != 20.0) return "test4: ${test4()}"
if (test5() != 20.0) return "test5: ${test5()}"
return "OK"
}
@@ -0,0 +1,29 @@
inline fun Inline.calcExt(s: (Int) -> Int, p: Int) : Int {
return s(p)
}
inline fun Inline.calcExt2(s: Int.() -> Int, p: Int) : Int {
return p.s()
}
class InlineX(val value : Int) {}
class Inline(val res: Int) {
inline fun InlineX.calcInt(s: (Int, Int) -> Int) : Int {
return s(res, this.value)
}
inline fun Double.calcDouble(s: (Int, Double) -> Double) : Double {
return s(res, this)
}
fun doWork(l : InlineX) : Int {
return l.calcInt({(a: Int, b: Int) -> a + b})
}
fun doWorkWithDouble(s : Double) : Double {
return s.calcDouble({(a: Int, b: Double) -> a + b})
}
}
@@ -0,0 +1,32 @@
fun test1(): Int {
val inlineX = Inline()
return inlineX.foo1Int({(z: Int) -> z}, 25)
}
fun test2(): Double {
val inlineX = Inline()
return inlineX.foo1Double(25.0, {(z: Double) -> z})
}
fun test3(): Double {
val inlineX = Inline()
return inlineX.foo2Param(15.0, {(z1: Int, z2: Double) -> z1 + z2}, 10)
}
fun test3WithCaptured(): Double {
val inlineX = Inline()
var c = 11.0;
return inlineX.foo2Param(15.0, {(z1: Int, z2: Double) -> z1 + z2 + c}, 10)
}
fun box(): String {
if (test1() != 25) return "test1: ${test1()}"
if (test2() != 25.0) return "test2: ${test2()}"
if (test3() != 25.0) return "test3: ${test3()}"
if (test3WithCaptured() != 36.0) return "test3WithCaptured: ${test3WithCaptured()}"
return "OK"
}
@@ -0,0 +1,15 @@
class Inline() {
inline fun foo1Int(s : (l: Int) -> Int, param: Int) : Int {
return s(param)
}
inline fun foo1Double(param: Double, s : (l: Double) -> Double) : Double {
return s(param)
}
inline fun foo2Param(param1: Double, s : (i: Int, l: Double) -> Double, param2: Int) : Double {
return s(param2, param1)
}
}
@@ -0,0 +1,9 @@
import test.*
val s = doWork({11})
fun box(): String {
if (s != 11) return "test1: ${s}"
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,23 @@
fun test1(): Double {
val inlineX = Inline()
return inlineX.foo1({(z: Int) -> z}, 25, {(z: Double) -> z}, 11.5)
}
fun test1WithCaptured(): Double {
val inlineX = Inline()
var d = 0.0;
return inlineX.foo1({(z: Int) -> d = 1.0; z}, 25, {(z: Double) -> z + d}, 11.5)
}
fun test2(): Double {
val inlineX = Inline()
return inlineX.foo2({(z: Int, p: Int) -> z + p}, 25, {(x: Double, y: Int, z: Int) -> z + x + y}, 11.5, 2)
}
fun box(): String {
if (test1() != 36.5) return "test1: ${test1()}"
if (test1WithCaptured() != 37.5) return "test1WithCaptured: ${test1WithCaptured()}"
if (test2() != 65.5) return "test2: ${test2()}"
return "OK"
}
@@ -0,0 +1,11 @@
class Inline() {
inline fun foo1(closure1 : (l: Int) -> Int, param1: Int, closure2 : (l: Double) -> Double, param2: Double) : Double {
return closure1(param1) + closure2(param2)
}
inline fun foo2(closure1 : (Int, Int) -> Int, param1: Int, closure2 : (Double, Int, Int) -> Double, param2: Double, param3: Int) : Double {
return closure1(param1, param3) + closure2(param2, param1, param3)
}
}
@@ -0,0 +1,7 @@
fun box(): String {
val result = runTest{minByTest<Int> { it }}
if (result != 1) return "test1: ${result}"
return "OK"
}
@@ -0,0 +1,10 @@
public inline fun <R> runTest(f: () -> R): R {
return f()
}
public inline fun <R> minByTest(f: (Int) -> R): R {
var minValue = f(1)
val v = f(1)
return v
}
@@ -0,0 +1,48 @@
fun test0Param(): Double {
val inlineX = InlineDouble(10.0)
return inlineX.foo({() -> 1.0})
}
fun test1Param(): Double {
val inlineX = InlineDouble(10.0)
return inlineX.foo11({(z: Double) -> z})
}
fun test1ParamCaptured(): Double {
val s = 100.0
val inlineX = InlineDouble(10.0)
return inlineX.foo11({(z: Double) -> s})
}
fun test1ParamMissed() : Double {
val inlineX = InlineDouble(10.0)
return inlineX.foo11({(z: Double) -> 111.0})
}
fun test1ParamFromCallContext() : Double {
val inlineX = InlineDouble(1000.0)
return inlineX.fooRes({(z: Double) -> z})
}
fun test2Params() : Double {
val inlineX = InlineDouble(1000.0)
return inlineX.fooRes2({(y: Double, z: Double) -> 2.0 * y + 3.0 * z})
}
fun test2ParamsWithCaptured() : Double {
val inlineX = InlineDouble(1000.0)
val s = 9.0
var t = 1.0
return inlineX.fooRes2({(y: Double, z: Double) -> 2.0 * s + t})
}
fun box(): String {
if (test0Param() != 1.0) return "test0Param"
if (test1Param() != 11.0) return "test1Param()"
if (test1ParamCaptured() != 100.0) return "testtest1ParamCaptured()"
if (test1ParamMissed() != 111.0) return "test1ParamMissed()"
if (test1ParamFromCallContext() != 1000.0) return "test1ParamFromCallContext()"
if (test2Params() != 35.0) return "test2Params()"
if (test2ParamsWithCaptured() != 19.0) return "test2ParamsWithCaptured()"
return "OK"
}
@@ -0,0 +1,23 @@
class InlineDouble(val res : Double) {
inline fun foo(s : () -> Double) : Double {
val f = "fooStart"
val z = s()
return z
}
inline fun foo11(s : (l: Double) -> Double) : Double {
return s(11.0)
}
inline fun fooRes(s : (l: Double) -> Double) : Double {
val z = s(res)
return z
}
inline fun fooRes2(s : (l: Double, t: Double) -> Double) : Double {
val f = "fooRes2Start"
val z = s(1.0, 11.0)
return z
}
}
@@ -0,0 +1,12 @@
import test.*
fun test1(): String {
return MyEnum.K.doSmth("O")
}
fun box(): String {
val result = test1()
if (result != "OK") return "fail1: ${result}"
return "OK"
}
@@ -0,0 +1,10 @@
package test
enum class MyEnum {
K;
//TODO: KT-4693
[inline] fun <T> doSmth(a: T) : String {
return a.toString() + K.name()
}
}
@@ -0,0 +1,12 @@
import test.*
fun test1(s: Long): String {
return doSmth(s)
}
fun box(): String {
val result = test1(11.toLong())
if (result != "11") return "fail1: ${result}"
return "OK"
}
@@ -0,0 +1,5 @@
package test
inline fun <T> doSmth(a: T) : String {
return a.toString()
}
@@ -0,0 +1,48 @@
fun test0Param(): Int {
val inlineX = Inline(10)
return inlineX.foo({() -> 1})
}
fun test1Param(): Int {
val inlineX = Inline(10)
return inlineX.foo11({(z: Int) -> z})
}
fun test1ParamCaptured(): Int {
val s = 100
val inlineX = Inline(10)
return inlineX.foo11({(z: Int) -> s})
}
fun test1ParamMissed() : Int {
val inlineX = Inline(10)
return inlineX.foo11({(z: Int) -> 111})
}
fun test1ParamFromCallContext() : Int {
val inlineX = Inline(1000)
return inlineX.fooRes({(z: Int) -> z})
}
fun test2Params() : Int {
val inlineX = Inline(1000)
return inlineX.fooRes2({(y: Int, z: Int) -> 2 * y + 3 * z})
}
fun test2ParamsWithCaptured() : Int {
val inlineX = Inline(1000)
val s = 9
var t = 1
return inlineX.fooRes2({(y: Int, z: Int) -> 2 * s + t})
}
fun box(): String {
if (test0Param() != 1) return "test0Param: ${test0Param()}"
if (test1Param() != 11) return "test1Param: ${test1Param()}"
if (test1ParamCaptured() != 100) return "test1ParamCaptured: ${test1ParamCaptured()}"
if (test1ParamMissed() != 111) return "test1ParamMissed: ${test1ParamMissed()}"
if (test1ParamFromCallContext() != 1000) return "test1ParamFromCallContext: ${test1ParamFromCallContext()}"
if (test2Params() != 35) return "test2Params: ${test2Params()}"
if (test2ParamsWithCaptured() != 19) return "test2ParamsWithCaptured: ${test2ParamsWithCaptured()}"
return "OK"
}
@@ -0,0 +1,24 @@
class Inline(val res : Int) {
inline fun foo(s : () -> Int) : Int {
val f = "fooStart"
val z = s()
return z
}
inline fun foo11(s : (l: Int) -> Int) : Int {
return s(11)
}
inline fun fooRes(s : (l: Int) -> Int) : Int {
val z = s(res)
return z
}
inline fun fooRes2(s : (l: Int, t: Int) -> Int) : Int {
val f = "fooRes2Start"
val z = s(1, 11)
return z
}
}
@@ -0,0 +1,23 @@
import test.*
class Z {}
fun test1() : Int {
val input = Z()
return input.use<Z, Int>{
100
}
}
fun test2() : Int {
val x = 1000
return use2() + x
}
fun box(): String {
if (test1() != 100) return "test1: ${test1()}"
if (test2() != 1100) return "test1: ${test2()}"
return "OK"
}
@@ -0,0 +1,14 @@
package test
public class Data()
public inline fun <T, R> T.use(block: (T)-> R) : R {
return block(this)
}
public inline fun use2() : Int {
val s = 100
return s
}
@@ -0,0 +1,49 @@
fun test0Param(): String {
val inlineX = InlineString("10")
return inlineX.foo({() -> "1"})
}
fun test1Param(): String {
val inlineX = InlineString("10")
return inlineX.foo11({(z: String) -> z})
}
fun test1ParamCaptured(): String {
val s = "100"
val inlineX = InlineString("10")
return inlineX.foo11({(z: String) -> s})
}
fun test1ParamMissed() : String {
val inlineX = InlineString("10")
return inlineX.foo11({(z: String) -> "111"})
}
fun test1ParamFromCallContext() : String {
val inlineX = InlineString("1000")
return inlineX.fooRes({(z: String) -> z})
}
fun test2Params() : String {
val inlineX = InlineString("1000")
return inlineX.fooRes2({(y: String, z: String) -> y + "0" + z})
}
fun test2ParamsWithCaptured() : String {
val inlineX = InlineString("1000")
val s = "9"
var t = "1"
return inlineX.fooRes2({(y: String, z: String) -> s + t})
}
fun box(): String {
if (test0Param() != "1") return "test0Param: ${test0Param()}"
if (test1Param() != "11") return "test1Param: ${test1Param()}"
if (test1ParamCaptured() != "100") return "test1ParamCaptured: ${test1ParamCaptured()}"
if (test1ParamMissed() != "111") return "test1ParamMissed: ${test1ParamMissed()}"
if (test1ParamFromCallContext() != "1000") return "test1ParamFromCallContext: ${test1ParamFromCallContext()}"
if (test2Params() != "1011") return "test2Params: ${test2Params()}"
if (test2ParamsWithCaptured() != "91") return "test2ParamsWithCaptured: ${test2ParamsWithCaptured()}"
return "OK"
}
@@ -0,0 +1,24 @@
class InlineString(val res : String) {
inline fun foo(s : () -> String) : String {
val f = "fooStart"
val z = s()
return z
}
inline fun foo11(s : (l: String) -> String) : String {
return s("11")
}
inline fun fooRes(s : (l: String) -> String) : String {
val z = s(res)
return z
}
inline fun fooRes2(s : (l: String, t: String) -> String) : String {
val f = "fooRes2Start"
val z = s("1", "11")
return z
}
}
@@ -0,0 +1,12 @@
import test.*
fun test1(): String {
return doSmth("O", "K")
}
fun box(): String {
val result = test1()
if (result != "OK") return "fail1: ${result}"
return "OK"
}
@@ -0,0 +1,5 @@
package test
inline fun doSmth(vararg a: String) : String {
return a.foldRight("", {(a, b) -> a + b})
}